kand
kand

Reputation: 2338

Browserify with already browserified files

Using browserify, I'm attempting to require an already browserified module, but the bundle is not able to resolve the module that has already been browserified.

For example, I have a file bundle-1.js that has been bundled with the command:

browserify -r ./bundle-1:bundle.one > build/bundle.one.js

I have another file, bundle-2.js that has require('bundle.two'), which is bundled with the command:

browserify -r ./bundle-2:bundle.two -x ./build/bundle.one.js > build/bundle.two.js

Attempting to run that last command, produces an error stating Cannot find module 'bundle.one'.

How can I expose the modules from bundle-1 for bundle-2 to use from the module name bundle.one?

I've created a repo for this example here: https://github.com/kand/browserify-bundling-tests

Upvotes: 2

Views: 569

Answers (1)

tomastrajan
tomastrajan

Reputation: 1726

This is caused because browserified bundle is already wrapped by browserify and does not look like node.js module (commonjs, containing require() and exports) statements. It should be possible to specify previous bundle as a global library exporting some object in browserify configuration.

Solution is similar to importing any other global library as described here.

Upvotes: 1

Related Questions