我最近重构了我的应用程序以使用 webpack v2。运行 webpack -p 后,我注意到我的构建大小实际上增加了 ~32kb。我认为它没有实现摇树。因此,在我的 .babelrc 文件中,我更改了以下代码:
"presets": [
"react",
"es2015",
"stage-0",
]
到==>
"presets": [
["es2015", { "modules": false }],
"react",
"stage-0",
]
但现在我收到以下错误:
> webpack -p
C:\Users\jasan\Downloads\app\webpack.config.babel.js:1
(function (exports, require, module, __filename, __dirname) { import webpack fro
m 'webpack';
^^^^^^
SyntaxError: Unexpected token import
at Object.exports.runInThisContext (vm.js:76:16)
at Module._compile (module.js:542:28)
at loader (C:\Users\jasan\Downloads\app\node_modules\babel-register\lib\n
ode.js:144:5)
at Object.require.extensions.(anonymous function) [as .js] (C:\Users\jasan\D
ownloads\app\node_modules\babel-register\lib\node.js:154:7)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at requireConfig (C:\Users\jasan\Downloads\app\node_modules\webpack\bin\c
onvert-argv.js:96:18)