I am developing multiple plugins to a system that loads these plugins as AMD modules (with requirejs). Plugins are written as ES6 modules and packed with webpack (output.libraryTarget = 'amd'). Everything works as expected so far.
But plugins share quite a lot of common code that is bundled into every entry. I tried to use CommonsChunkPlugin
webpack plugin but initial chunk contains code that is not AMD module. However other entry points relaying on common chuck are still generated correctly. Also documentation says that it is not good idea to have multiple initial chunks (with JSONp runtime) on one page - there is possibility that another plugin author would use same approach.
Is there a way to optimize this use case in AMD compatible manner?
It seems to me as a bug in CommonsChunkPlugin
that the initial entry is not AMD (but still its code is not safe to be loaded in plugin env)... Is there a configuration I am missing?
When you set target: 'node' in webpack config, webpack will not bundle the built-ins module of Node. js. path is a built-in module of Node. js, it doesn't come from the node_modules directory.
Webpack supports the following module types natively: ECMAScript modules. CommonJS modules.
Webpack allows you to define externals - modules that should not be bundled. When bundling with Webpack for the backend - you usually don't want to bundle its node_modules dependencies. This library creates an externals function that ignores node_modules when bundling in Webpack.
There are four basic concepts in webpack: entry , output , modules and plug-ins . These configurations are added in webpack.
I'm not quite sure that understand you correctly. But if you want to build your bundle as AMD module, than you must config it as a library:
...
output: {
...
library: true,
libraryTarget: 'umd'
},
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With