[英]How do I get decorators working with babel & webpack?
I have the following setup: 我有以下设置:
{
"babel-core": "~5.8.25",
"babel-eslint": "^4.1.3",
"babel-loader": "~5.3.2",
"babel-polyfill": "^6.2.0",
"eslint": "^1.7.3",
"eslint-config-airbnb": "^0.1.0",
"eslint-loader": "~1.1.0",
"eslint-plugin-angular": "~0.12.0",
// ...
}
webpack: 的WebPack:
module: {
preLoaders: [{ test: /\.js$/, exclude: /node_modules/, loader: 'eslint-loader'}],
loaders: [
{
test: /\.js$/,
exclude: /node_modules/,
loaders: ['ng-annotate', 'babel-loader?plugins[]=transform-decorators-legacy'],
}
]
}
But I get the following error: 但是我收到以下错误:
TypeError: The plugin "transform-decorators-legacy" didn't export a Plugin instance
Does anyone know what I'm doing wrong here? 有谁知道我在这里做错了什么?
UPDATE UPDATE
I've since upgraded to Babel 6 and now have the following set up: 我已经升级到Babel 6,现在有以下设置:
{
"babel-core": "^6.0.0",
"babel-eslint": "^4.1.3",
"babel-loader": "^6.0.0",
"babel-plugin-transform-decorators-legacy": "^1.3.4",
"babel-polyfill": "^6.2.0",
"babel-preset-es2015": "^6.0.0",
"babel-preset-stage-0": "^6.5.0",
"eslint": "^1.10.0",
"eslint-config-airbnb": "^4.0.0",
"eslint-loader": "^1.2.0",
"eslint-plugin-angular": "^0.15.0",
// ...
}
and: 和:
module: {
preLoaders: [{ test: /\.js$/, exclude: /node_modules/, loader: 'eslint-loader'}],
loaders: [
{
test: /\.js$/,
exclude: /node_modules/,
loaders: ['ng-annotate', 'babel?presets[]=es2015&presets[]=stage-0&plugins[]=transform-decorators-legacy'],
}
]
},
But get Parsing error: Unexpected token ILLEGAL
referring to the decorator. 但得到
Parsing error: Unexpected token ILLEGAL
引用装饰器。
After some searching and this SO answer , I was able to get it working without using a .babelrc
file. 经过一些搜索和这个SO答案后 ,我能够在不使用
.babelrc
文件的情况下使其工作。
transform-decorators-legacy
transform-decorators-legacy
npm install --save-dev babel-plugin-transform-decorators-legacy
webpack.config.js
webpack.config.js
包含该插件 loaders: [
{
test: /\.jsx?$/,
exclude: /node_modules/,
loader: 'babel',
query: {
plugins: ['transform-decorators-legacy'],
presets: ['es2015', 'stage-0', 'react']
}
}
]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.