眾所周知build后的html文件會(huì)注入編譯后的資源
npm run build
//生成后的html文件下面會(huì)有
<!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>導(dǎo)購(gòu)管理平臺(tái)</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>
而我這次啥都沒(méi)有
<!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>導(dǎo)購(gòu)管理平臺(tái)</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>
看之前的項(xiàng)目差导,查文檔,糾結(jié)了半天甸赃,最后終于查到原因柿汛,還是自己沒(méi)有細(xì)看文檔,上代碼
/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] // 刪除屬性引號(hào)
collapseWhitespace: [true/false] // 折疊空白
原因就是inject: 我寫成了false埠对。修改為true,完美解決裁替。