我正在尝试使用i18n-webpack插件与babel-加载器。
我的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代码时,一切都很好。
发布于 2015-09-29 18:06:34
我想通了。把“巴贝尔-装载机”改为“巴贝尔”。下面是完整代码
var path = require("path"),
I18nPlugin = require("i18n-webpack-plugin"),
webpack = require("webpack"),
babel = require("babel-loader"),
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: "./dist/static/scripts",
filename: language + ".[name].output.js"
},
module: {
loaders: [
{
test: /\.js?$/,
exclude: /(node_modules|bower_components)/,
loader: 'babel'
}
]
},
plugins: [
new I18nPlugin(
languages[language]
),
new webpack.optimize.UglifyJsPlugin({minimize: true})
]
};
});发布于 2015-12-28 12:34:41
数组使用“加载器”,字符串使用“加载器”。
loader: 'babel?someparam!ts'与
loaders: ['babel?someparam', 'ts']https://stackoverflow.com/questions/32833381
复制相似问题