vue.config.js中的pages配置
时间: 2023-02-12 21:25:42 浏览: 1784
vue.config.js 文件是 Vue CLI 的配置文件,其中的 pages 配置项用来配置多页面应用。
pages 配置项是一个对象,其中的 key 是页面的路径,value 是页面的入口文件。例如:
```
module.exports = {
pages: {
index: {
entry: 'src/index/main.js',
template: 'public/index.html',
filename: 'index.html',
},
about: {
entry: 'src/about/main.js',
template: 'public/about.html',
filename: 'about.html',
},
},
};
```
这样配置后,Vue CLI 会自动生成两个页面,分别是 /index 和 /about,其中 index 页面的入口文件是 src/index/main.js,模板文件是 public/index.html,生成的文件名是 index.html。
相关问题
vue.config.js里的pages
在 `vue.config.js` 中,`pages` 选项用于配置多页面应用程序。它允许您为应用程序定义多个入口点,每个入口点可以有自己的模板,标题,脚本和样式等。下面是一个 `pages` 选项的示例:
```javascript
module.exports = {
pages: {
index: {
entry: 'src/main.js',
template: 'public/index.html',
filename: 'index.html',
title: 'Index Page',
chunks: ['chunk-vendors', 'chunk-common', 'index']
},
about: {
entry: 'src/about.js',
template: 'public/about.html', filename: 'about.html',
title: 'About Page',
chunks: ['chunk-vendors', 'chunk-common', 'about']
}
}
}
```
上面的示例中,我们定义了两个页面:`index` 和 `about`。每个页面都有自己的入口点、模板、文件名、标题和代码块等。在这个例子中,我们使用了 `chunk-vendors` 和 `chunk-common` 代码块,这些代码块是由 `vue-cli` 自动生成的。
vue.config.js中的pages配置怎么设置页面打包后的位置
`vue.config.js`中的`pages`配置可以用来设置多页应用程序的入口和输出路径。每个页面都会生成一个对应的HTML文件和JavaScript文件,以及其他可能的静态资源文件。
要设置页面打包后的位置,可以在`pages`配置中为每个页面指定其输出路径。例如:
```js
module.exports = {
pages: {
index: {
entry: 'src/main.js',
template: 'public/index.html',
filename: 'index.html',
outputPath: 'dist/',
},
about: {
entry: 'src/about.js',
template: 'public/about.html',
filename: 'about.html',
outputPath: 'dist/about',
},
},
};
```
在上面的例子中,`index.html`文件将被输出到`dist/`目录中,而`about.html`文件将被输出到`dist/about/`目录中。如果未指定`outputPath`属性,则默认为`dist/`目录。
需要注意的是,`outputPath`属性只能指定目录路径,不能指定文件名。文件名通过`filename`属性指定。