因此在我的index.html中,我有这一行包含webpack捆绑包
<script src="/dist/bundle.js"></script>
我的webpack配置如下:
const path = require("path");
const webpack = require("webpack");
module.exports = {
entry: "./src/main.js",
mode: "development",
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /(node_modules|bower_components)/,
loader: "babel-loader",
options: { presets: ["@babel/env"] }
},
{
test: /\.css$/,
use: ["style-loader", "css-loader"]
}
]
},
resolve: { extensions: ["*", ".js", ".jsx"] },
output: {
path: path.resolve(__dirname, "dist/"),
publicPath: "/dist/",
filename: "bundle.js"
},
devServer: {
contentBase: path.join(__dirname, "public/"),
port: 3000,
publicPath: "http://localhost:3000/dist/",
hotOnly: true
},
plugins: [new webpack.HotModuleReplacementPlugin()]
};
我如何修改它,以便在运行webpack --mode production
时将查询字符串(?v = some_nr)添加到包中。我可以将index.html复制到dist / index.html或其他某个位置,如果需要的话,以后我会自动将其移动到webroot。