Sign in to follow this  
State Valentin

Requiring a npm package inside Client-side ?

Recommended Posts

Ok so my index.js from server-side looks like this:

 

// Loading official packages of the server

const glob = require('glob');  
const config = require('./config.js');

glob ('./packages/semp/Assets/**/*.js', function(err,files) {  
  for (file of files) {
    require(file.replace('./packages/semp/','./'));
    if(config.env == 'dev') { 
      console.log(file); 
    }
  }
});

 

I want to do the same to the client-side packages. But how can i do that if i can't load an npm package with Vanilla JS ? Any fix to that ? 

Share this post


Link to post
Share on other sites

Wrong area to post this, but the client-side JS supports the require function to load in other files.

For using packages from NPM you just have to include them in your client_packages directory so they get sent to each client. I suggest something like Webpack to handle bundling for you.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.