最近我Webpack 4
为我的react
应用程序实现了设置。
我的webpack.config.js
看起来像这样
const HtmlWebPackPlugin = require('html-webpack-plugin');
const htmlWebpackPlugin = new HtmlWebPackPlugin({
template: './src/index.js',
filename: './index.html',
});
module.exports = {
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
},
},
{
test: /\.css$/,
use: [
{
loader: 'style-loader',
},
{
loader: 'css-loader',
options: {
modules: true,
importLoaders: 1,
localIdentName: '[name]_[local]_[hash:base64]',
sourceMap: true,
minimize: true,
},
},
],
},
],
},
plugins: [htmlWebpackPlugin],
};
这是我的package.json
脚本
"scripts": {
"dev": "webpack-dev-server --mode development --open",
"prod": "webpack --mode production"
}
这里的问题是当我使用...
(spread operator) 时,它会抛出一个error
我相信这是与babel
未正确转译有关的东西。任何建议,将不胜感激。谢谢。
它抛出一个error
类似于下面的东西。
ERROR in ./src/index.js
Module build failed: SyntaxError: D:/cp/src/index.js: Unexpected token (31:6)
29 | return {
30 | headers: {
> 31 | ...headers,
| ^
32 | authorization: token ? `Bearer ${token}` : null,
33 | },
34 | };