我正在嘗試將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'給了我同樣的錯誤。 –