javascript - Simple solution to share modules loaded via NPM across multiple Browserify or Webpack bundles -


The solution simple to share a code by dragging my hair here, through NPM It is necessary to think of multiple browsers or webpack bundles, is there a thing like "bridge"?

This time is not due to being compiled (I have been aware of caution) but in my desire to remove specific lbs from all vendors vendor.js therefore my app In addition to keeping js organized and crashing the browser with a massive source map, I think the way cleaners need to see the compiled JS. And so:

  // vendor.js is required ('response'); ('Lodash') is required; ('Other- NPM Module') is required; ('Another- NPM module') is required; It is very important that NOPM can be loaded in code against the BOVERS, or some 'vendor' to import through the relative path and identify through Shim. 'Is saved in the directory. I want to keep every library reference drawn through NPM except for each actual reference source.  

In app.js I place all of my source code, and through the externals array, exemplifies the vendor libraries listed above from the collection Is:

  // app.js var response = required ('response'); Var _ = is required ('trash'); Var component = React.createClass () // ...  

and then in index.html , I need both files

  // index.html & lt; Script src = 'vendor.js' & gt; & Lt; / Script & gt; & Lt; Script src = 'app.js' & gt; & Lt; / Script & gt;  

How can I create this by using browserproof or webpack so that I can see " app.js " in the module loaded through NPM? I know about creating an external bundle and then referring to the direct file (in, say, node_modules ) through the nickname, but I'm hoping to find a solution that is more automated and less Like "Require.js"

Actually, I am thinking that if it is possible to pull both, then app.js can be seen in the vendor.js dependency . It sounds like a simple, straightforward action, but I can not find an answer anywhere on this broad, comprehensive web

Thank you!

With webpack, you use multiple entry points and taken from

:


To split your app into 2 files, app.js and vendor.js , you'll see the vendor. Js may require vendor files, then pass this name to the general check plugins below.

  module.exports = {entry}: {app: "./app.js", vendor: ["jquery", "underscore", ...],}, output: {filename : "Bundle.js"}, Plugins: [New WebPack.Pits. Commonsch plugin (/ * chunkname = * / "vendor", / * filename = * / "vendor. Bundle JS")]};  

This app will remove all the modules in the vendor section from Chuck. bundle.js will no longer be an app code, without any dependencies of it, these are in vendor.bundle.js .

In your HTML page load vendor.bundle.js before bundle.js .

  & lt; Script src = "vendor.bundle.js" & gt; & Lt; / Script & gt; & Lt; Script src = "bundle.js" & gt; & Lt; / Script & gt;  


Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -