Vue-Cli:为什么在构建之后 index.html 没有用引号生成? [英] Vue-Cli: why after the build the index.html is not generated with quotes?
问题描述
运行 npm 构建后,会生成不带引号的 ./dist/index.html
文件.该项目没有 webpack.config.js 或 vue.config.js.构建是从使用 vue create
制作的示例项目生成的.我该如何解决这个问题?
After running the npm build, the ./dist/index.html
file is generated without the quotes. The project does not have a webpack.config.js or a vue.config.js. The build is generated from the example project made with vue create
. How do I solve this?
<!DOCTYPE html><html lang=en><head><meta charset=utf-8><meta http-equiv=X-UA-Compatible content="IE=edge"><meta name=viewport content="width=device-width,initial-scale=1"><link rel=icon href=/favicon.ico><title>html-project</title><link href=/app.css rel=preload as=style><link href=/app.js rel=preload as=script><link href=/chunk-vendors.js rel=preload as=script><link href=/app.css rel=stylesheet></head><body><noscript><strong>We're sorry but html-project doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript><div id=app></div><script src=/chunk-vendors.js></script><script src=/app.js></script></body></html>
推荐答案
那里不需要属性引号(那仍然是 有效的 HTML),因此它们在生产版本中被删除以减少 HTML 文件的输出大小.
Attribute quotes aren't necessary there (that's still valid HTML), so they're removed in production builds to reduce the output size of the HTML file.
如果你更喜欢保留引号,你可以配置 HTML minifier 选项(即,特别是removeAttributeQuotes
)如下:
If you prefer to keep the quotes, you could configure the HTML minifier options (i.e., specifically removeAttributeQuotes
) as follows:
// vue.config.js
module.exports = {
chainWebpack: config => {
config.plugin('html').tap((args) => {
args[0].minify = {
...args[0].minify,
removeAttributeQuotes: false
}
return args
})
}
}
这篇关于Vue-Cli:为什么在构建之后 index.html 没有用引号生成?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!