美文网首页
vue-cli3 config

vue-cli3 config

作者: Clover园 | 来源:发表于2019-04-24 22:34 被阅读0次
1.baseUrl
 /** 区分打包环境与开发环境
   * process.env.NODE_ENV==='production'  (打包环境)
   * process.env.NODE_ENV==='development' (开发环境)
   * baseUrl:process.env.NODE_ENV==='production'?"https://cdn.didabisai.com/front/":'front/',
   */
  // 项目部署的基础路径
  // 我们默认假设你的应用将会部署在域名的根部,
  // 例如 https://www.my-app.com/
  // 如果你的应用部署在一个子路径下,那么你需要在这里
  // 指定子路径。比如将你的应用部署在
  // https://www.foobar.com/my-app/
  // 那么将这个值改为 '/my-app/'



module.exports = {
  // 基本路径/ 构建好的文件输出到哪里
  baseUrl: process.env.NODE_ENV === 'production'? '/': '/',
  // 输出文件目录
  outputDir: 'dist', // 默认dist// 用于嵌套生成的静态资产(js,css,img,fonts)目录
  // assetsDir: '',
  // 指定生成的 index.html 的输出路径 (相对于 outputDir)。也可以是一个绝对路径
  indexPath: 'index.html', // Default: 'index.html'
  filenameHashing: true,
  // 构建多页时使用
  pages: undefined,
  // eslint-loader是否在保存的时候检查 使用带有浏览器内编译器的完整构建版本
  lintOnSave: true,
  // 是否使用包含运行时编译器的Vue核心的构建
  runtimeCompiler: false,
  // 默认情况下 babel-loader 会忽略所有 node_modules 中的文件。如果你想要通过 Babel 显式转译一个依赖,可以在这个选项中列出来
  transpileDependencies: [],
  // 如果你不需要生产环境的 source map,可以将其设置为 false 以加速生产环境构建。
  productionSourceMap: false,
//多页配置
pages: {
    index: {
      // entry for the pages
      entry: 'src/pages/index/index.js',
      // the source template
      template: 'src/pages/index/index.html',
      // output as dist/index.html
      filename: 'index.html',
      // when using title option,
      // template title tag needs to be <title><%= htmlWebpackPlugin.options.title %></title>
      title: '首页',
      // chunks to include on this pages, by default includes
      // extracted common chunks and vendor chunks.
      chunks: ['chunk-vendors', 'chunk-common', 'index']
    }
  // 如果这个值是一个对象,则会通过 webpack-merge 合并到最终的配置中。如果这个值是一个函数,则会接收被解析的配置作为参数。该函数及可以修改配置并不返回任何东西,也可以返回一个被克隆或合并过的配置版本。
  configureWebpack: config => {
    if (process.env.NODE_ENV === 'production') {
      // 为生产环境修改配置...
    } else {
      // 为开发环境修改配置...
    }

 config.resolve.alias
      .set("@", resolve("src")) // key,value自行定义,比如.set('@@',     resolve('src/components'))
      .set("_c", resolve("src/components"))
      .set("_conf", resolve("config"));
  },
  // 是一个函数,会接收一个基于 webpack-chain 的 ChainableConfig 实例。允许对内部的 webpack 配置进行更细粒度的修改。
  chainWebpack: config => {
    /*config.module
      .rule('images')
      .use('url-loader')
        .loader('url-loader')
        .tap(options => {
          // 修改它的选项...
          return options
        })*/

    /* 因为是多页面,所以取消 chunks,每个页面只对应一个单独的 JS / CSS
        config.optimization
          .splitChunks({
            cacheGroups: {}
          });

        // 'src/lib' 目录下为外部库文件,不参与 eslint 检测
        config.module
          .rule('eslint')
          .exclude
          .add('/Users/maybexia/Downloads/FE/community_built-in/src/lib')
          .end()
    */
  },
  // css相关配置
  css: {
    // 启用 CSS modules
    modules: false,
    // 是否使用css分离插件
    extract: true,
    // 开启 CSS source maps?
    sourceMap: false,
    // css预设器配置项
    loaderOptions: {},
  },
  // webpack-dev-server 相关配置
  devServer: {
    host: '0.0.0.0',
    port: 8080,
    https: false,
    open: true,
    hotOnly: false,
    proxy: {// 设置代理
      "/api": {
          //代理路径 例如 https://baidu.com
          target:  "https://baidu.com",
          // 将主机标头的原点更改为目标URL
          changeOrigin: true,
          ws: true,
          pathRewrite: {
            "^/api": ""
          }
        }
    },
    before: app => {},
  },
 // 构建时开启多进程处理 babel 编译
  parallel: require('os').cpus().length > 1,
  // PWA 插件相关配置
  pwa: {},
  // 第三方插件配置
  pluginOptions: {
  // ...
  }
}
//举例
devServer: {
    // host: "localhost",
    port: 80, // 端口号
    // https: false, // https:{type:Boolean}
    // open: true, //配置自动启动浏览器
    // proxy: 'http://localhost:4000' // 配置跨域处理,只有一个代理
    // 配置多个代理
    proxy: {
      "/zte-crm-ccs-core": {
        // target: "http://10.40.198.55:8080",//后端某个人接口
        // target: "http://10.40.158.112:8080",
        //  target: 'http://10.40.140.43:8010/',
         target: 'http://ccsesm.zte.com.cn/',
        pathRewrite:{
          '^/zte-crm-ccs-core':'/zte-crm-ccs-core'
        },
        // 如果要代理 websockets
        ws: true,
        changeOrigin: true
      },
      "/zte-crm-ccs-datasourceinfo": {
        target: 'http://ccsesm.zte.com.cn/',
        pathRewrite:{
          '^/zte-crm-ccs-datasourceinfo':'/zte-crm-ccs-datasourceinfo'
        },
        ws: true,
        changeOrigin: true
      },
    },
    disableHostCheck: true
  }

相关文章

网友评论

      本文标题:vue-cli3 config

      本文链接:https://www.haomeiwen.com/subject/inzngqtx.html