所以这是我的webpack配置文件:
var path = require("path");
var webpack = require('webpack');
var BundleTracker = require('webpack-bundle-tracker');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
var autoprefixer = require('autoprefixer');
module.exports = {
context: __dirname,
devtool: 'inline-source-map',
entry: [
'webpack-dev-server/client?http://localhost:3000',
'webpack/hot/only-dev-server',
'./static/js/index',
],
output: {
path: path.resolve('./static/bundles/'),
filename: "[name]-[hash].js",
publicPath: 'http://localhost:3000/static/bundles/',
},
resolve: {
modulesDirectories: ['../node_modules', 'bower_components'],
extensions: ['', '.scss', '.css', '.js', '.jsx', '.json']
},
module: {
loaders: [
{ test: /(\.js|\.jsx)$/,
exclude: /node_modules/,
loaders: ['react-hot',
'babel?presets[]=es2015&presets[]=stage-0&presets[]=react,plugins[]=transform-object-assign'],
}, {
test: /(\.scss | \.css)$/,
loaders: ExtractTextPlugin.extract('style',
'css?sourceMap&modules&importLoaders=1&localIdentName=[name]__[local]___[hash:base64:5]!postcss!sass')
}
],
},
postcss: [autoprefixer],
sassLoader: {
data: '@import "theme/_config.scss";',
includePaths: [path.resolve(__dirname, './static')]
},
plugins: [
new ExtractTextPlugin('react-toolbox.css', { allChunks: true }),
new webpack.optimize.OccurrenceOrderPlugin(),
new webpack.HotModuleReplacementPlugin(),
new webpack.NoErrorsPlugin(), // don't reload if errors are present
new BundleTracker({filename: './webpack-stats.json'}),
],
}
以下是我收到的错误消息:
ERROR in ./static/js/reducers/account.js
Module build failed: SyntaxError: /Users/Evita/Dev/ev_PrecisDigitalTools/react_boiler/static/js/reducers/account.js: Unexpected token (9:14)
7 | case 'GET':
8 | return {
> 9 | Object.assign({}, state, {
| ^
10 | accountId: action.value
11 | })
12 | }
at Parser.pp.raise (/Users/Evita/Dev/ev_PrecisDigitalTools/node_modules/babylon/lib/parser/location.js:22:13)
at Parser.pp.unexpected (/Users/Evita/Dev/ev_PrecisDigitalTools/node_modules/babylon/lib/parser/util.js:89:8)
at Parser.pp.expect (/Users/Evita/Dev/ev_PrecisDigitalTools/node_modules/babylon/lib/parser/util.js:83:33)
at Parser.pp.parseObj (/Users/Evita/Dev/ev_PrecisDigitalTools/node_modules/babylon/lib/parser/expression.js:739:12)
at Parser.pp.parseExprAtom (/Users/Evita/Dev/ev_PrecisDigitalTools/node_modules/babylon/lib/parser/expression.js:491:19)
at Parser.parseExprAtom (/Users/Evita/Dev/ev_PrecisDigitalTools/node_modules/babylon/lib/plugins/jsx/index.js:18:22)
at Parser.pp.parseExprSubscripts (/Users/Evita/Dev/ev_PrecisDigitalTools/node_modules/babylon/lib/parser/expression.js:277:19)
at Parser.pp.parseMaybeUnary (/Users/Evita/Dev/ev_PrecisDigitalTools/node_modules/babylon/lib/parser/expression.js:257:19)
at Parser.pp.parseExprOps (/Users/Evita/Dev/ev_PrecisDigitalTools/node_modules/babylon/lib/parser/expression.js:188:19)
at Parser.pp.parseMaybeConditional (/Users/Evita/Dev/ev_PrecisDigitalTools/node_modules/babylon/lib/parser/expression.js:165:19)
@ ./static/js/reducers/index.js 15:15-35
ERROR in ../~/react-toolbox/lib/input/theme.scss
Module parse failed: /Users/Evita/Dev/ev_PrecisDigitalTools/node_modules/react-toolbox/lib/input/theme.scss Unexpected character '@' (1:0)
You may need an appropriate loader to handle this file type.
SyntaxError: Unexpected character '@' (1:0)
at Parser.pp$4.raise (/Users/Evita/Dev/ev_PrecisDigitalTools/node_modules/acorn/dist/acorn.js:2221:15)
at Parser.pp$7.getTokenFromCode (/Users/Evita/Dev/ev_PrecisDigitalTools/node_modules/acorn/dist/acorn.js:2756:10)
at Parser.pp$7.readToken (/Users/Evita/Dev/ev_PrecisDigitalTools/node_modules/acorn/dist/acorn.js:2477:17)
at Parser.pp$7.nextToken (/Users/Evita/Dev/ev_PrecisDigitalTools/node_modules/acorn/dist/acorn.js:2468:15)
at Parser.parse (/Users/Evita/Dev/ev_PrecisDigitalTools/node_modules/acorn/dist/acorn.js:515:10)
at Object.parse (/Users/Evita/Dev/ev_PrecisDigitalTools/node_modules/acorn/dist/acorn.js:3098:39)
at Parser.parse (/Users/Evita/Dev/ev_PrecisDigitalTools/node_modules/webpack/lib/Parser.js:902:15)
at DependenciesBlock.<anonymous> (/Users/Evita/Dev/ev_PrecisDigitalTools/node_modules/webpack/lib/NormalModule.js:104:16)
at DependenciesBlock.onModuleBuild (/Users/Evita/Dev/ev_PrecisDigitalTools/node_modules/webpack-core/lib/NormalModuleMixin.js:310:10)
at nextLoader (/Users/Evita/Dev/ev_PrecisDigitalTools/node_modules/webpack-core/lib/NormalModuleMixin.js:275:25)
@ ../~/react-toolbox/lib/input/index.js 18:13-36
现在,我知道Object.assign不是开箱即用的,所以你可以看到我尝试添加插件'babel-transform-object-assign'(如下所述:{{ 3}}),我试过从core-js(https://github.com/react-toolbox/react-toolbox/issues/45)和babel-core,以及'运行时'选项等方面要求它。简单 - 不用了。 Postcss显然引起了问题,但我已经降级了。
我还没有真正开始尝试修复sass加载程序问题,认为在我解决了Object.assign问题之后我会从那开始,虽然我已经在过去的5个小时内一直在使用它而且我真的无处可去。所以我添加了两个错误消息,希望有人能指出我正确的方向。
我怀疑我把旧语法与新语法混淆了,但我真的无法想出这个...帮助??
答案 0 :(得分:0)
你不能这样做:
return {
Object.assign({}, state, {
accountId: action.value
})
}
我认为这是对的:
return Object.assign({}, state, {
accountId: action.value
})