web-webpack-plugin icon indicating copy to clipboard operation
web-webpack-plugin copied to clipboard

output中的filename设置为[name].js?[hash]时替换无效

Open FlynnLeeGit opened this issue 8 years ago • 3 comments

webpack.config

const path = require("path"),
    resolve = p => path.resolve(__dirname, p);
const { WebPlugin, AutoWebPlugin } = require("web-webpack-plugin");
const config = {
    entry: {
        A: resolve("src/pages/A.js"),
        B: resolve("src/pages/B.js")
    },
    output: {
        path: resolve("dist"),
        filename: "[name].js?[chunkhash]",
        publicPath:'v2/dist/'
    },
    module: {
        loaders: [
            {
                test: /\.css$/,
                use: ["style-loader", "css-loader"]
            }
        ]
    },
    resolve: {},
    plugins: [
        new WebPlugin({
            template:'./template.html',
            filename: "index.html",
            requires: ["A", "B"]
        })
    ]
};
module.exports = config;

template

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="B"></script>
    <link rel="stylesheet" href="./reset.min.css?_inline">
    <script src="./test.js"></script>
</head>
<body>
    <!-- SCRIPT -->
</body>
</html>

结果


<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    
    <style rel="stylesheet">*{
    margin: 0;
    padding: 0;
    color: green;
}</style>
    <script src="v2/dist/test.js"></script>
</head>
<body>
    <!-- SCRIPT -->

</body>
</html>

FlynnLeeGit avatar Sep 30 '17 01:09 FlynnLeeGit

应该是:

filename: "[name]_[chunkhash].js

详情请阅读 配置 Output

gwuhaolin avatar Sep 30 '17 02:09 gwuhaolin

这个我知道 ,但是需求的是要在js文件后使用query形式的hash而不是修改文件名称

FlynnLeeGit avatar Sep 30 '17 04:09 FlynnLeeGit

这个暂时还不支持

gwuhaolin avatar Sep 30 '17 04:09 gwuhaolin