美文网首页
vue build 后生成的html文件没有注入资源,仅以记住w

vue build 后生成的html文件没有注入资源,仅以记住w

作者: Mr_Liu攻城狮 | 来源:发表于2021-03-13 10:53 被阅读0次

众所周知build后的html文件会注入编译后的资源

npm run build


//生成后的html文件下面会有
<!DOCTYPE html>
<html lang=en>
    <head>
        <meta charset=UTF-8>
        <meta name=viewport content="width=device-width,initial-scale=1">
        <meta http-equiv=X-UA-Compatible content="ie=edge">
        <title>导购管理平台</title>
        <script>
            document.write('<script src="./config/index.js?t=' + new Date().getTime() + '"><\/script>');
        </script>
        <script src="https://map.qq.com/api/gljs?v=1.exp&key=OB4BZ-D4W3U-B7VVO-4PJWW-6TKDJ-WPB77"></script>
        <link href=./static/css/app.css rel=stylesheet>
    </head>
    <body>
        <div id=app></div>
        <script type=text/javascript src=./static/js/manifest.js></script>
        <script type=text/javascript src=./static/js/vendor.js></script>
        <script type=text/javascript src=./static/js/app.js></script>
    </body>
    <script src=https://rescdn.qqmail.com/node/ww/wwopenmng/js/sso/wwLogin-1.0.0.js></script>
</html>

而我这次啥都没有

<!DOCTYPE html>
<html lang=en>
    <head>
        <meta charset=UTF-8>
        <meta name=viewport content="width=device-width,initial-scale=1">
        <meta http-equiv=X-UA-Compatible content="ie=edge">
        <title>导购管理平台</title>
        <script>
            document.write('<script src="./config/index.js?t=' + new Date().getTime() + '"><\/script>');
        </script>
        <script src="https://map.qq.com/api/gljs?v=1.exp&key=OB4BZ-D4W3U-B7VVO-4PJWW-6TKDJ-WPB77"></script>
        <link href=./static/css/app.css rel=stylesheet>
    </head>
    <body>
        <div id=app></div>
        
    </body>
    <script src=https://rescdn.qqmail.com/node/ww/wwopenmng/js/sso/wwLogin-1.0.0.js></script>
</html>

看之前的项目,查文档,纠结了半天,最后终于查到原因,还是自己没有细看文档,上代码

/build/webpack.prod.conf.js

new HtmlWebpackPlugin({
    filename: process.env.NODE_ENV === 'testing'
    ? 'index.html'
    : config.build.index,
    template: 'index.html',
    inject: fasle,
    minify: {
    removeComments: true,
    collapseWhitespace: false,
    removeAttributeQuotes: false
    // more options:
    // https://github.com/kangax/html-minifier#options-quick-reference
    },
    // necessary to consistently work with multiple chunks via CommonsChunkPlugin
    chunksSortMode: 'dependency'
}),


template: 'index.html',     // 模板文件
inject: true,    // 注入资源引用
minify: {}    // 压缩
removeComments: [true/false]    // 删除注释
removeAttrbuteQuotes: [true/false]    // 删除属性引号
collapseWhitespace: [true/false]    // 折叠空白

原因就是inject: 我写成了false。修改为true,完美解决。

相关文章

网友评论

      本文标题:vue build 后生成的html文件没有注入资源,仅以记住w

      本文链接:https://www.haomeiwen.com/subject/wqcxcltx.html