【发布时间】:2020-03-21 19:09:26
【问题描述】:
我是 webpack 的新手,所以我正在尝试将它与我的 react express 应用程序一起使用。例如,我创建了一个捆绑包并将其上传到主机,但它只打开主页,当我尝试使用链接访问其他页面时,我得到“无法获取 /about”。和 webpack-dev-server 的行为相同。有我必须使用的插件吗?
webpack.config.js
const path = require("path");
const HtmlWebPackPlugin = require("html-webpack-plugin");
const htmlPlugin = new HtmlWebPackPlugin({
template: "./client/public/index.html",
filename: "./index.html",
favicon: "./client/public/favicon.ico"
})
module.exports = {
entry: "./client/src/index.js",
output: {
path: path.resolve(__dirname, "dist"),
filename: "[name].js",
publicPath: "/"
},
devtool: "inline-source-map",
plugins: [
htmlPlugin
],
module: {
rules: [
{
test: /\.(png|svg|jpg|gif|webp|ico)$/,
loader: "file-loader"
},
{
test: /\.s?css$/,
use: ['style-loader', "css-loader", "sass-loader"]
},
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
loader: "babel-loader",
query: {
presets: ['@babel/env', '@babel/react'],
plugins: ["@babel/plugin-proposal-class-properties"]
}
}
]
}
}
【问题讨论】: