我正在尝试删除webpack验证器,因为它可能会抛出一个错误,并且不允许我使用解决对象(这是最初的问题:Resolving relative paths in React with Webpack not working)。但是,删除相关代码后,我将得到一个语法错误。
context: __dirname,
^
SyntaxError: Unexpected token :但是,只需删除这一行就可以将相同的错误移到下一行,如果我删除该行,它就会再次向下移动。但它始终是一个“意外的标记:”错误。这似乎很容易解决,但我找不到错误。
以下是webpack的背景:
const {resolve} = require('path');
const webpack = require('webpack');
const {getIfUtils, removeEmpty} = require('webpack-config-utils');
module.exports = env => {
const {ifProd, ifNotProd} = getIfUtils(env)
entry: './index.js',
context: __dirname,
output: {
path: resolve(__dirname, './build'),
filename: 'bundle.js',
publicPath: '/build/',
pathinfo: ifNotProd(),
},
devtool: ifProd('source-map', 'eval'),
devServer: {
port: 8080,
historyApiFallback: true
},
module: {
loaders: [
{test: /\.js$/, exclude: /node_modules/, loader: 'babel-loader'},
{test: /\.css$/, loader: 'style-loader!css-loader'},
{test: /(\.eot|\.woff2|\.woff|\.ttf|\.svg)/, loader: 'file-loader'},
],
},
resolve: {
alias: {
shared: path.resolve(__dirname, 'app')
}
//modulesDirectories: ['app']
},
plugins: removeEmpty([
ifProd(new webpack.optimize.DedupePlugin()),
ifProd(new webpack.LoaderOptionsPlugin({
minimize: true,
debug: false,
quiet: true,
})),
ifProd(new webpack.DefinePlugin({
'process.env': {
NODE_ENV: '"production"',
},
})),
ifProd(new webpack.optimize.UglifyJsPlugin({
sourceMap: true,
compress: {
screw_ie8: true, // eslint-disable-line
warnings: false,
},
})),
])
};发布于 2017-03-10 09:40:20
您正在导出一个函数,但是您将它作为一个对象来处理,从而导致语法错误。
试试这个:
module.exports = env => {
const {ifProd, ifNotProd} = getIfUtils(env);
return {
entry: './index.js',
...
}
};https://stackoverflow.com/questions/42714329
复制相似问题