Javascript webpack拆分块:如何将依赖项合并到命名块中?
假设您有以下项目: package.jsonJavascript webpack拆分块:如何将依赖项合并到命名块中?,javascript,webpack,Javascript,Webpack,假设您有以下项目: package.json { "name": "webpack-test-repo", "main": "index.js", "dependencies": { "define-properties": "^1.1.3" }, "devDependencies": { "webpack": "^4.20.2", "webpack-cli": "^3.1.2" } } index.js // dynamically load
{
"name": "webpack-test-repo",
"main": "index.js",
"dependencies": {
"define-properties": "^1.1.3"
},
"devDependencies": {
"webpack": "^4.20.2",
"webpack-cli": "^3.1.2"
}
}
index.js
// dynamically load the 'define-properties' module.
import('define-properties');
module.exports = {
mode: 'production',
entry: './index.js',
output: {
chunkFilename: '[name].js',
},
optimization: {
splitChunks: {
minSize: 0, // <- just to demonstrate the situation with small packages
cacheGroups: {
defineProperties: {
test: /node_modules\/define-properties\//,
name: 'define-properties',
},
},
},
},
};
webpack.config.js
// dynamically load the 'define-properties' module.
import('define-properties');
module.exports = {
mode: 'production',
entry: './index.js',
output: {
chunkFilename: '[name].js',
},
optimization: {
splitChunks: {
minSize: 0, // <- just to demonstrate the situation with small packages
cacheGroups: {
defineProperties: {
test: /node_modules\/define-properties\//,
name: 'define-properties',
},
},
},
},
};
这里我们得到三个输出文件:main.js
用于index.js
的内容,define properties.js
用于define properties
模块,2.js
用于对象键
模块
问题:
我希望对象键
的区块合并到定义属性
中,因为它仅由定义属性
使用
换句话说,我只想通过指定父模块,将定义属性
及其依赖项打包到一个命名块中
虽然test:/node\u modules\/(?:define properties | object key)\/
适用于本例,但我不想列出define properties
的所有(可能很多)依赖项
我如何配置webpack来实现它