"build": "webpack --config build/webpack.config.js",
"start": "webpack-dev-server --open"
使用npm run build不报错,但是用npm run start报错,不知道为什么
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" })
]
}
}
] //cssloader解析css,styleloader创建style标签
},
//图片文件
{
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"
})
]
};
图片的file-loader改为file试试