我正在尝试将i18n-webpack-plugin和babel-loader一起使用。Webpack i18n插件不能与babel es6一起使用
我的WebPack配置:
var path = require("path"),
I18nPlugin = require("i18n-webpack-plugin"),
webpack = require("webpack"),
languages = {
"en": null,
"es": require("./src/locale/es.po.json")
};
module.exports = Object.keys(languages).map(function(language) {
return {
name: language,
entry: {
home: "./src/static/scripts/script.js",
alt: "./src/static/scripts/alt.js"
},
output: {
path: path.join(__dirname, "dist/static/scripts"),
filename: language + ".[name].output.js"
},
modules: {
loaders: [
{
test: /\.js$/,
exclude: /node_modules/,
loader: ["babel-loader"]
},
]
},
plugins: [
new I18nPlugin(
languages[language]
),
new webpack.optimize.UglifyJsPlugin({minimize: true})
]
};
});
我收到的错误:
ERROR in ./src/static/scripts/script.js
Module parse failed: /Users/anthonydandrea/react/gulp-react-flask/src/static/scripts/script.js Line 1: Unexpected token
You may need an appropriate loader to handle this file type.
| import React from 'react';
不确定是什么原因造成的问题。似乎从未使用过babel,并且不会让我在第一行上执行ES6导入。注意:当我注释掉ES6代码时,一切正常。
你尝过'preLoaders'而是采用通天塔?该插件可能会在Babel之前添加它的加载器来运行。 – loganfsmyth
将'loaders'改为'preLoaders'给了我同样的错误。 –