module.exports = { entry: './index.js', output: { filename: 'index.min.js', path: './' }, module: { loaders: [ { test: /\.js$/, loader: 'babel', exclude: /node_modules/, query: { presets: ['es2015'], plugins: ['transform-runtime'] }, cacheDirectory: true } ] } }
const pi = 3.14159265; let s = "Hello"; for (let codePoint of s) { console.log(codePoint); }
当我删除"排除"的行时,编译的文件变得大约两倍并且抛出错误:" $ extend不是函数"。
我想知道为什么exclude选项会对编译过程产生影响。我只编译./index.js
答案 0 :(得分:0)
导致此行为的transform-runtime
插件 - 如果您将其删除,则尺寸相同。
为了找到问题的根源,我创建了两个配置,一个配置排除了node_modules
,另一个配置就像你的配置一样。另外我让webpack生成源映射(web pack' s -d 参数/ devtool:" source-map" config)并查看包含的文件不出现在排除版本(简单差异)中。这些是
webpack:///../~/babel-runtime/core-js/object/create.js
webpack:///../~/babel-runtime/core-js/object/define-properties.js
webpack:///../~/babel-runtime/core-js/object/define-property.js
webpack:///../~/babel-runtime/core-js/object/get-own-property-descriptor.js
webpack:///../~/babel-runtime/core-js/object/get-own-property-names.js
webpack:///../~/babel-runtime/core-js/object/get-own-property-symbols.js
webpack:///../~/babel-runtime/core-js/object/get-prototype-of.js
webpack:///../~/babel-runtime/core-js/object/is-extensible.js
webpack:///../~/babel-runtime/core-js/object/keys.js
webpack:///../~/babel-runtime/core-js/object/prevent-extensions.js
webpack:///../~/babel-runtime/core-js/symbol.js
webpack:///../~/babel-runtime/core-js/symbol/iterator.js
webpack:///../~/babel-runtime/helpers/typeof.js
webpack:///../~/core-js/library/fn/object/create.js
webpack:///../~/core-js/library/fn/object/define-properties.js
webpack:///../~/core-js/library/fn/object/define-property.js
webpack:///../~/core-js/library/fn/object/get-own-property-descriptor.js
webpack:///../~/core-js/library/fn/object/get-own-property-names.js
webpack:///../~/core-js/library/fn/object/get-own-property-symbols.js
webpack:///../~/core-js/library/fn/object/get-prototype-of.js
webpack:///../~/core-js/library/fn/object/is-extensible.js
webpack:///../~/core-js/library/fn/object/keys.js
webpack:///../~/core-js/library/fn/object/prevent-extensions.js
webpack:///../~/core-js/library/fn/symbol/index.js
webpack:///../~/core-js/library/fn/symbol/iterator.js
webpack:///../~/core-js/library/modules/_enum-keys.js
webpack:///../~/core-js/library/modules/_is-array.js
webpack:///../~/core-js/library/modules/_keyof.js
webpack:///../~/core-js/library/modules/_meta.js
webpack:///../~/core-js/library/modules/_object-gopd.js
webpack:///../~/core-js/library/modules/_object-gopn-ext.js
webpack:///../~/core-js/library/modules/_object-gopn.js
webpack:///../~/core-js/library/modules/_object-gops.js
webpack:///../~/core-js/library/modules/_object-pie.js
webpack:///../~/core-js/library/modules/_object-sap.js
webpack:///../~/core-js/library/modules/_wks-define.js
webpack:///../~/core-js/library/modules/_wks-ext.js
webpack:///../~/core-js/library/modules/es6.object.create.js
webpack:///../~/core-js/library/modules/es6.object.define-properties.js
webpack:///../~/core-js/library/modules/es6.object.define-property.js
webpack:///../~/core-js/library/modules/es6.object.get-own-property-descriptor.js
webpack:///../~/core-js/library/modules/es6.object.get-own-property-names.js
webpack:///../~/core-js/library/modules/es6.object.get-prototype-of.js
webpack:///../~/core-js/library/modules/es6.object.is-extensible.js
webpack:///../~/core-js/library/modules/es6.object.keys.js
webpack:///../~/core-js/library/modules/es6.object.prevent-extensions.js
webpack:///../~/core-js/library/modules/es6.symbol.js
webpack:///../~/core-js/library/modules/es7.symbol.async-iterator.js
webpack:///../~/core-js/library/modules/es7.symbol.observable.js
transform-runtime
插件处理这些文件,因此当您不排除node_modules
时,它们会包含在您的版本中。