é¤äºå¯¼åºå个é ç½®å¤ï¼è¿æä¸äºè½æ»¡è¶³æ´å¤éæ±ç使ç¨æ¹å¼ã
ä½ å¯è½ä¼éå°éè¦åºåå¼åç¯å¢åç产ç¯å¢çæ åµãæå¾å¤ç§æ¹å¼å¯ä»¥åå°è¿ä¸ç¹ãå ¶ä¸ä¸ç§éæ©æ¯ç± webpack é 置导åºä¸ä¸ªå½æ°èé对象ï¼è¿ä¸ªå½æ°å å«ä¸¤ä¸ªåæ°ï¼
output-path
å mode
çã-module.exports = {
+module.exports = function(env, argv) {
+ return {
+ mode: env.production ? 'production' : 'development',
+ devtool: env.production ? 'source-map' : 'eval',
plugins: [
new TerserPlugin({
terserOptions: {
+ compress: argv.mode === 'production' // only if `--mode production` was passed
}
})
]
+ };
};
å½éè¦å¼æ¥å è½½é ç½®åéæ¶ï¼webpack å°æ§è¡å½æ°å¹¶å¯¼åºä¸ä¸ªé ç½®æ件ï¼åæ¶è¿åä¸ä¸ª Promiseã
module.exports = () => {
return new Promise((resolve, reject) => {
setTimeout(() => {
resolve({
entry: './app.js',
/* ... */
});
}, 5000);
});
};
é¤äºå¯¼åºå个é 置对象/å½æ°ï¼ä½ å¯è½ä¹ä¼éè¦å¯¼åºå¤ç§é ç½®ï¼webpack 3.1.0 èµ·æ¯æï¼ãå½è¿è¡ webpack æ¶ï¼ææé 置项é½ä¼æ建ãæ¯å¦ï¼å¯¹äºå¤ targetsï¼å¦ AMD å CommonJSï¼æ建 library æ¶ä¼é常æç¨ã
module.exports = [
{
output: {
filename: './dist-amd.js',
libraryTarget: 'amd',
},
name: 'amd',
entry: './app.js',
mode: 'production',
},
{
output: {
filename: './dist-commonjs.js',
libraryTarget: 'commonjs',
},
name: 'commonjs',
entry: './app.js',
mode: 'production',
},
];
以é²ä½ çæ个é
ç½®ä¾èµäºå¦ä¸ä¸ªé
ç½®çè¾åºï¼ä½ å¯ä»¥ä½¿ç¨ä¸ä¸ª dependencies
å表æå®ä¸ä¸ªä¾èµå表ã
webpack.config.js
module.exports = [
{
name: 'client',
target: 'web',
// â¦
},
{
name: 'server',
target: 'node',
dependencies: ['client'],
},
];
å¦æä½ å¯¼åºäºå¤ä¸ªé
ç½®ï¼ä½ å¯ä»¥å¨é
ç½®ä¸ä½¿ç¨ parallelism
é项æ¥æå®ç¼è¯çæ大并åæ°ã
number
webpack.config.js
module.exports = [
{
//config-1
},
{
//config-2
},
];
module.exports.parallelism = 1;