webpack输出 - 一个资产比整体更大?

时间:2017-06-20 13:23:43

标签: javascript reactjs webpack

怎么可能:

如果需要了解更多信息,请在评论中告诉我。

Version: webpack 2.4.1
Time: 2344ms
   Asset     Size  Chunks             Chunk Names
index.js  49.6 kB       0  [emitted]  index
   [0] (webpack)/buildin/global.js 509 bytes {0} [built]
   [2] ./index.js 68 bytes {0} [built]
   [3] ./src/facebook-login.jsx 6.76 kB {0} [built]
   [4] ./src/helpers/helpers.js 1.46 kB {0} [built]
   [5] ./src/spinner.jsx 2.84 kB {0} [built]
   [6] ./src/style/styles.js 688 bytes {0} [built]
   [9] ./~/css-loader!./~/sass-loader/lib/loader.js?{"includePaths":["absolute/path/a","absolute/path/b"]}!./src/style/spinner.scss 236 bytes {0} [built]
   //  <----lodash.merge is 58.2kb ---->
  [15] ./~/lodash.merge/index.js 58.2 kB {0} [built]
  [16] ./~/prop-types/factoryWithThrowingShims.js 1.59 kB {0} [built]
  [17] ./~/prop-types/index.js 1.08 kB {0} [built]
  [18] ./~/prop-types/lib/ReactPropTypesSecret.js 436 bytes {0} [built]
  [19] ./~/style-loader/addStyles.js 8.51 kB {0} [built]
  [21] ./src/style/spinner.scss 1.08 kB {0} [built]
  [22] ./src/style/icon.png 1.59 kB {0} [built]
  [24] multi ./index.js 28 bytes {0} [built]
    + 10 hidden modules

1 个答案:

答案 0 :(得分:1)

我认为该网站不正确:

$ npm i lodash.merge
...

+ lodash.merge@4.6.0
added 1 package in 0.458s

$ ls -al node_modules/lodash.merge
total 72
drwxrwxr-x 6 robert staff   204 Jun 20 16:00 .
drwxrwxr-x 3 robert staff   102 Jun 20 16:00 ..
-rw-r--r-- 1 robert staff  1951 Aug 13  2016 LICENSE
-rw-r--r-- 1 robert staff   446 Aug 13  2016 README.md
-rw-r--r-- 1 robert staff 58183 Aug 13  2016 index.js
-rw-r--r-- 1 robert staff  1804 Jun 20 16:00 package.json

因此index.js的大小几乎与Webpack所说的一样。

您的捆绑包较小的原因可能是因为您正在创建缩小捆绑包。这大大减少了index.js的大小:

$ uglifyjs < node_modules/lodash.merge/index.js | wc -c
   21635