0

js file that is using a npm node module greetings and I use my app.js in the browser with browserify:

enter image description here

My index.html looks like this:

enter image description here

I know that the source code of the file app.js is now embedded in the file bundle.js.

I have now the Requirement that my production code contains the app.js and a additional libary containing the node modules like this:

enter image description here

This means that the client gets the app.js file and the bundle.js file and that I now can use the node modules from my app.js like this:

enter image description here

Basically I just want a bundle.js that is used as libary for my app.js and contains the node modules in a way that I can include them in browser side JavaScript.

I also tired to use the client side file and module loader. require.js to load node_modules but according to this thread it does not work.

Community
  • 1
  • 1
Viktor Carlson
  • 989
  • 1
  • 13
  • 36

1 Answers1

1

You need to use browserify's -r & -x options: https://github.com/substack/node-browserify#multiple-bundles

To compile your code, run:

browserify app.js -r ./greetings -o dist/bundle.js
browserify app.js -x ./greetings -o dist/app.js

dist/bundle.js will contain the greetings module, dist/app.js will contain your code.

RyanZim
  • 6,609
  • 1
  • 27
  • 43