Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/458.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript webpack拆分块:如何将依赖项合并到命名块中?_Javascript_Webpack - Fatal编程技术网

Javascript webpack拆分块:如何将依赖项合并到命名块中?

Javascript 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

假设您有以下项目:

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 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来实现它