有没有大佬知道 vue-cli 创建的项目里 public 文件夹下的 index.html文件是干什么用的?
看了半天官网,就说会被 webpack 处理的模板,别的也不说。搞不懂
有没有大佬知道 vue-cli 创建的项目里 public 文件夹下的 index.html文件是干什么用的?
看了半天官网,就说会被 webpack 处理的模板,别的也不说。搞不懂
pubilc/index.html
是一个模板文件,作用是生成项目的入口文件,webpack
打包的js,css也会自动注入到该页面中。我们浏览器访问项目的时候就会默认打开生成好的index.html
。
在webpack
配置中是这样的:
// generate dist index.html with correct asset hash for caching.
// you can customize output by editing /index.html
// see https://github.com/ampedandwired/html-webpack-plugin
new HtmlWebpackPlugin({
filename: config.build.index,
template: 'index.html',
inject: true,
minify: {
removeComments: true,
collapseWhitespace: true,
removeAttributeQuotes: true
// more options:
// https://github.com/kangax/html-minifier#options-quick-reference
},
// necessary to consistently work with multiple chunks via CommonsChunkPlugin
chunksSortMode: 'dependency'
}),
通过html-webpack-plugin
插件读取模板(index.html
),进行模板绑定之后再输出到outut
目录的index.html
10 回答11.2k 阅读
5 回答4.9k 阅读✓ 已解决
4 回答3.1k 阅读✓ 已解决
2 回答2.8k 阅读✓ 已解决
2 回答4.8k 阅读✓ 已解决
4 回答4.4k 阅读✓ 已解决
4 回答1.9k 阅读✓ 已解决
index.html是一个总的入口文件,vue是单页面应用,挂在id为app的div下然后动态渲染路由模板