34修改脚手架默认配置

修改脚手架默认配置

配置参考

vue.config.js 是一个可选的配置文件,如果项目的 (和 package.json 同级的) 根目录中存在这个文件,那么它会被 @vue/cli-service 自动加载。你也可以使用 package.json 中的 vue 字段,但是注意这种写法需要你严格遵照 JSON 的格式来写。

这个文件应该导出一个包含了选项的对象:

// vue.config.js
/**
 * @type {import('@vue/cli-service').ProjectOptions}
 */
module.exports = {
  // 选项...
}

或者

// vue.config.js
const { defineConfig } = require('@vue/cli-service')
module.exports = defineConfig({
  // 选项
})

pages#

  • Type: Object
  • Default: undefined
module.exports = {
  pages: {
    index: {
      // 入口
      entry: 'src/index/main.js',
      // 模板来源
      template: 'public/index.html',
      // 在 dist/index.html 的输出
      filename: 'index.html',
      // 当使用 title 选项时,
      // template 中的 title 标签需要是 <title><%= htmlWebpackPlugin.options.title %></title>
      title: 'Index Page',
      // 在这个页面中包含的块,默认情况下会包含
      // 提取出来的通用 chunk 和 vendor chunk。
      chunks: ['chunk-vendors', 'chunk-common', 'index']
    },
    // 当使用只有入口的字符串格式时,
    // 模板会被推导为 `public/subpage.html`
    // 并且如果找不到的话,就回退到 `public/index.html`。
    // 输出文件名会被推导为 `subpage.html`。
    subpage: 'src/subpage/main.js'
  }
}

lintOnSave#

  • Type: boolean | 'warning' | 'default' | 'error'

  • Default: 'default'

// vue.config.js
module.exports = {
  lintOnSave: false // 关闭语法检查; true 警告不报错
}

​ 当 lintOnSave 是一个 truthy 的值时,eslint-loader 在开发和生产构建下都会被启用。如果你想要在生产构建时禁用 eslint-loader,你可以用如下配置:

// vue.config.js
module.exports = {
  lintOnSave: process.env.NODE_ENV !== 'production'
}

更多配置参考,点击这里跳转 | Vue CLI (vuejs.org)

posted @ 2022-09-06 17:21  Redskaber  阅读(58)  评论(0)    收藏  举报