Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
FlynnLeeGit opened this issue Sep 30, 2017 · 3 comments
Open

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

FlynnLeeGit opened this issue Sep 30, 2017 · 3 comments

Comments

@FlynnLeeGit
Copy link

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>
@gwuhaolin
Copy link
Owner

应该是:

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

详情请阅读 配置 Output

@FlynnLeeGit
Copy link
Author

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

@gwuhaolin
Copy link
Owner

这个暂时还不支持

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants