[英]How can I configure Webpack output to include some options only for a particular bundle
I have a Webpack 4 that build multiple bundles, I want to attach the output options libraryTarget
& library
for a single bundle only. 我有一个构建多个bundle的Webpack 4,我想只为一个bundle附加输出选项
libraryTarget
和library
。
so it would look like this by default: 所以它默认看起来像这样:
output: {
path: path.resolve(__dirname, 'dist/js'),
filename: '[name].[chunkhash].js',
},
except for a single bundle, I need the following: 除了一个捆绑,我需要以下内容:
output: {
path: path.resolve(__dirname, 'dist/js'),
filename: '[name].[chunkhash].js',
libraryTarget: 'var',
library: '[name]'
},
is this possible? 这可能吗? I'm not seeing an example in the document
我没有在文档中看到一个例子
You can't do what you're asking, but you can instead use your existing configuration as a "common" configuration and extend it in another using webpack-merge
: 你无法做你想要的,但你可以使用现有配置作为“常见”配置,并使用
webpack-merge
在另一个配置中扩展它:
// e.g. webpack.config.your-lib.js
module.exports = merge(require('./webpack.config.common.js'), {
// ...entry changes...
output: {
libraryTarget: 'var',
library: '[name]',
}
})
Don't forget to make amendments to the entry
in the above so the new config is building only the intended library bundles. 不要忘记修改上面的
entry
,以便新配置只构建预期的库包。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.