Multiple browser packages using external modules

I want to link some common code as CommonJS modules, and then use these common modules from another package and / or directly from the global one.

entry1-common.js -- a.js -- b.js entry2-app.js -- x.js inside i would like to to access entry1-common a.js here var moduleA = require('./a.js'); <script> // i would also like to access modules from outside var moduleA = require('./a.js'); var moduleX = require('./x.js'); </script> 

I am using gulp. Some browser options that I seem to need, but not quite me there:

 browserify(bundleConfigs: [{ entries: './entry1-common.js', dest: dest, outputName: 'common.js', hasExports: true, // this gives me require() function on the outside require: ['jquery'] }]) 

Do I need to bind through and duplexer? I saw examples of this in the documentation browser.

I can create two separate packages in my gulp task, but I don't know how to access modules from one to the other.

+5
source share
1 answer

Reading about Webpack, I see where they solve so many issues, including the one above. You can systematically exteriorize everything as shown in the webpack documentation. The snapshot below:

  externals: [ { a: false, // a is not external b: true, // b is external (require("b")) "./c": "c", // "./c" is external (require("c")) "./d": "var d" // "./d" is external (d) }, // Every non-relative module is external // abc -> require("abc") /^[az\-0-9]+$/, function(context, request, callback) { // Every module prefixed with "global-" becomes external // "global-abc" -> abc if(/^global-/.test(request)) return callback(null, "var " + request.substr(7)); callback(); }, "./e" // "./e" is external (require("./e")) ] 
+1
source

All Articles