我一直在努力让webpack2运行babel-loader。基本上我的当前配置babel什么都不做,结果传递给uglify,由于我的代码中仍然存在es2015功能而导致uglify失败。
如果我查看输出文件,babel什么都没做,所以我尝试通过CLI运行它
babel --preset es2015 catseye.bundle.js > catseye2.bundle.js
这工作正常,第二个文件包含bableified代码。
所以我的webpack配置就出现了问题,但是我无法发现我的错误。
我的版本应该是最新的:
"babel-core": "^6.23.1",
"babel-loader": "^6.3.2",
"babel-preset-es2015": "^6.22.0",
"ts-loader": "^2.0.1",
"webpack": "^2.2.1",
这是我的webpack配置文件:
const path = require("path");
const webpack = require("webpack");
module.exports = {
entry: ["babel-polyfill", "gl-matrix", path.join(__dirname, "src/catseye.ts")],
output: {
path: __dirname,
filename: "catseye.bundle.js"
},
resolve: {
extensions: [".js", ".ts"]
},
module: {
rules: [
{
test: /\.tsx?$/,
exclude: /node_modules/,
use: [
{
loader:"babel-loader",
options:{
presets:[
["es2015", {modules:false}]
]
},
},
{
loader: 'ts-loader'
}
]
}
]
},
plugins: [
new webpack.optimize.UglifyJsPlugin({
compress: {
dead_code: true,
warnings: false
}
})
]
};