众所周知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,完美解决。
网友评论