列出用于构建webpack块的所有传递依赖项

时间:2017-08-30 10:27:48

标签: webpack webpack-style-loader webpack-file-loader webpack-3

我已经在我的github帐户上创建了a demonstration of the problem I'm having

我有一个带有两个入口点的webpack配置 - " feature-one"和"功能二"。 "特征酮"包括一个CSS文件,它本身包含一个徽标:logo.svg

当webpack运行此代码时,logo.svg文件将包含在dist/文件夹中。

在" emit" webpack的阶段,可以检查每个入口点的块。

Chunk类具有files属性,该属性应列出所有文件 参与了大块。检查后,我们可以看到feature-one.jsfeature-one.css被引用, 但logo.svg不是。

相比之下,Module类具有fileDependencies属性,该属性列出了所涉及的所有文件路径,此列表 包含logo.svg文件的(完全限定路径)。可以通过Chunk modules属性访问块中涉及的模块。

以下是示例的webpack输出:

> yarn webpack
$ "<<checkout-dir>>/node_modules/.bin/webpack"
chunk info {
    "chunk id#0": {
        "modules": {
            "2": {
                "filepaths": [
                    "<<checkout-dir>>/src/feature-two.js"
                ]
            },
            "3": {
                "filepaths": [
                    "<<checkout-dir>>/src/feature-two.css",
                    "<<checkout-dir>>/node_modules/css-loader/lib/css-base.js",
                    "<<checkout-dir>>/src/feature-two.css"
                ]
            }
        },
        "files": [
            "feature-two.js",
            "feature-two.css"
        ]
    },
    "chunk id#1": {
        "modules": {
            "0": {
                "filepaths": [
                    "<<checkout-dir>>/src/feature-one.js"
                ]
            },
            "1": {
                "filepaths": [
                    "<<checkout-dir>>/src/feature-one.css",
                    "<<checkout-dir>>/node_modules/css-loader/lib/css-base.js",
                    "<<checkout-dir>>/src/feature-one.css",
                    "<<checkout-dir>>/src/logo.svg"
                ]
            }
        },
        "files": [
            "feature-one.js",
            "feature-one.css"
        ]
    }
}
Hash: 9d8603d6b25981dfd88f
Version: webpack 3.5.5
Time: 403ms
                               Asset       Size  Chunks             Chunk Names
2baa77d6015e6de6adf1ffa247530568.svg  679 bytes          [emitted]  
                      feature-two.js    3.01 kB       0  [emitted]  feature-two
                      feature-one.js    3.23 kB       1  [emitted]  feature-one
                     feature-one.css  136 bytes       1  [emitted]  feature-one
                     feature-two.css   50 bytes       0  [emitted]  feature-two
   [0] ./src/feature-one.js 142 bytes {1} [built]
   [1] ./src/feature-one.css 128 bytes {1} [built]
   [2] ./src/feature-two.js 28 bytes {0} [built]
   [3] ./src/feature-two.css 92 bytes {0} [built]
   [4] ./node_modules/css-loader?{"modules":true}!./src/feature-one.css 391 bytes [built]
   [6] ./src/logo.svg 82 bytes [built]
   [9] ./node_modules/css-loader?{"modules":true}!./src/feature-two.css 270 bytes [built]
    + 3 hidden modules
Child extract-text-webpack-plugin node_modules/extract-text-webpack-plugin/dist node_modules/css-loader/index.js??ref--0-2!src/feature-two.css:
       [0] ./node_modules/css-loader?{"modules":true}!./src/feature-two.css 270 bytes {0} [built]
        + 1 hidden module
Child extract-text-webpack-plugin node_modules/extract-text-webpack-plugin/dist node_modules/css-loader/index.js??ref--0-2!src/feature-one.css:
     1 asset
       [0] ./node_modules/css-loader?{"modules":true}!./src/feature-one.css 391 bytes {0} [built]
       [2] ./src/logo.svg 82 bytes {0} [built]
        + 1 hidden module
Done in 1.10s.

我的期望是块#1的files数组(即feature-one)将包含logo.svg,但它没有。

我不确定发现该功能的最合理或最受支持的方式 - 一个依赖图包含logo.svg文件,但是 最终,这是我的目标 - 获取给定入口点或块的所有直接+传递资产依赖关系的列表。

0 个答案:

没有答案