"build": "webpack--config build/webpack.config.js",
"start": "webpack-dev-server-- open"
use npm run build not to report an error, but use npm run start to report an error. I don"t know why
configuration of webpack.config.js
const path = require("path");
const rm = require("rimraf");
const HtmlWebpackPlugin = require("html-webpack-plugin");
//
rm("../dist/static", err => {
if (err) throw err;
});
module.exports = {
context: path.resolve(__dirname, "../"),
entry: "./src/index.js", //
output: {
filename: "[name].js",
path: path.resolve(__dirname, "../dist")
},
devtool: "inline-source-map",
devServer: {
contentBase: path.resolve(__dirname, "../dist")
},
module: {
rules: [
{
test: /\.css$/,
use: [
"style-loader",
{ loader: "css-loader", options: { importLoaders: 1 } },
{
loader: "postcss-loader",
options: {
plugins: loader => [
require("autoprefixer")({ browsers: "last 2 versions" })
]
}
}
] //cssloadercss,styleloaderstyle
},
//
{
test: /\.(png|jpg|gif)$/,
use: [
{
loader: "file-loader", //url
options: {
name: "[name][hash].[ext]"
}
}
]
},
//
{
test: /\.(woff|woff2|eot|ttf|otf)$/,
use: ["file-loader"]
}
]
},
plugins: [
new HtmlWebpackPlugin({
template: "index.html"
})
]
};