似乎没有什么能让webpack识别传播运算符。 我也试过为babel-core和object-rest-spread添加7.0.0-beta。
当我运行时,我收到消息,我需要一个合适的加载器来处理文件类型。在传播运营商的地方有一个意外的令牌。 (见img)
这是我的.babelrc:
{
"plugins": [
"syntax-dynamic-import",
"transform-async-to-generator",
"transform-es2015-destructuring",
"transform-es2015-parameters",
"transform-object-rest-spread",
["react-intl", {
"messagesDir": "./translations/messages/"
}]],
"presets": ["es2015", "react", "stage-0"]
}
这是我的webpack.config.js:
require('babel-polyfill');
const webpack = require('webpack');
const path = require('path');
module.exports = {
entry: [
'./src/index'
],
module: {
loaders: [
{test: /\.jsx$/, loader: 'babel-loader', /*...*/},
{ test: /\.js$/, loader: 'babel-loader', exclude: /node_modules/},
{ test: /\.scss$/, loader: 'style-loader!css-loader!sass-loader' },
{ test: /\.(svg|png|wav)$/, loader: 'file-loader'},
{ test: /\.css$/, loader: 'style-loader!css-loader'},
{ test: /\.(eot|woff|woff2|ttf)$/, loader: 'url-loader?limit=100000'},
],
},
resolve: {
extensions: ['.js', '.jsx', '.scss']
},
output: {
path: path.join(__dirname, '/dist'),
publicPath: '/',
filename: 'bundle.js'
},
这是我的package.json:
"devDependencies": {
"babel": "^6.23.0",
"babel-cli": "^6.26.0",
"babel-core": "^6.26.0",
"babel-eslint": "^8.2.2",
"babel-loader": "^7.1.0",
"babel-plugin-react-intl": "^2.2.0",
"babel-plugin-syntax-dynamic-import": "^6.18.0",
"babel-plugin-transform-async-to-generator": "^6.24.1",
"babel-plugin-transform-object-rest-spread": "^6.26.0",
"babel-preset-es2015": "^6.24.1",
"babel-preset-react": "^6.24.1",
"es6-object-assign": "1.1.0",
发生错误的文件:
const initialState = {
sprites: {},
stage: {}
};
const reducer = function (state, action) {
if (typeof state === 'undefined') state = initialState;
switch (action.type) {
case UPDATE_TARGET_LIST:
return Object.assign({}, state, {
sprites: action.targets
.filter(target => !target.isStage)
.reduce(
(targets, target, listId) => Object.assign(
targets,
//error message spread operator not handled
{[target.id]: {order: listId, ***...target***}}
),
{}
),
stage: action.targets
.filter(target => target.isStage)[0] || {}
});
case UPDATE_EDITING_TARGET:
return Object.assign({}, state, {editingTarget: action.target});
default:
return state;
}
};