javascript - webpack: commonchunksplugin with webworker and multiple chunks -
i work on legacy application that, now, have split in specific way: simplified case : have 4 modules:
//modulea.js export const modulea = ['modulea']; //moduleb.js import {modulea} './modulea'; export const moduleb = ['moduleb'].concat(modulea); //modulec.js import {modulea} './modulea'; import {moduleb} './moduleb'; export const modulec = ['modulec'].concat(modulea).concat(moduleb); //webworkermodule.js import {moduleb} './moduleb'; import {modulea} './modulea'; console.log("webworker module", modulea, moduleb);
what need have output of 5 files:
manifest.js
contain common runtime of webpackmodulea.js
contains code of moduleamoduleb.js
contains code of modulebmodulec.js
contains code of modulecwebworkermodule.js
contains code of module , module b , webpack runtime
i tried multiple configuration, cannot obtain want.
const path = require('path'); const webpack = require('webpack'); const config = { entry:{ modulea:'./src/modulea.js', moduleb:'./src/moduleb.js', modulec:'./src/modulec.js', webworkermodule:'./src/webworkermodule.js', }, output: { path: path.resolve(__dirname, 'dist'), filename: '[name].js' }, resolve: { extensions: ['.js'] }, plugins: [ new webpack.optimize.commonschunkplugin({ name: 'webworkermodule', chunks: ['webworkermodule'], minchunks: infinity }), new webpack.optimize.commonschunkplugin({ name: ['modulea', 'moduleb', 'manifest'], chunks: ['modulea', 'moduleb', 'modulec'], minchunks: infinity }) ] }; module.exports = config;
the above configuration example produce correct webworkermodule.js, modulea , moduleb duplicated in every other files.
has insight ?
i found solution:
const path = require('path'); const webpack = require('webpack'); const configww = { entry:{ webworkermodule:'./src/webworkermodule.js', }, output: { path: path.resolve(__dirname, 'dist'), filename: '[name].js' }, resolve: { extensions: ['.js'] }, }; const configothers = { entry: { modulea:'./src/modulea.js', moduleb:'./src/moduleb.js', modulec:'./src/modulec.js', }, output: { path: path.resolve(__dirname, 'dist'), filename: '[name].js' }, resolve: { extensions: ['.js'] }, plugins: [ new webpack.optimize.commonschunkplugin({ names: ['moduleb', 'modulea', 'manifest'], minchunks: infinity }) ] }; module.exports = [configww, configothers];
the main point of solution didn't know possible have multiple independent configuration.
Comments
Post a Comment