config 文件夹中的 index.js

 

  1 //此文件是用来配置各个环境参数
  2 
  3 'use strict'
  4 // Template version: 1.3.1
  5 // see http://vuejs-templates.github.io/webpack for documentation.
  6 
  7 const path = require('path') //此文件是用来配置开发环境和生产环境的配置参数
  8 const devEnv = require('./dev.env')
  9 const prodEnv = require('./prod.env')
 10 var version = ''
 11 
 12 // 时间标识符(用于区分版本)
 13 if (process.env.NODE_ENV === 'production' && prodEnv.VERSION_CONTROL) {
 14   var d = new Date();
 15   var yy = d.getFullYear().toString().slice(2);
 16   var MM = d.getMonth() + 1 >= 10 ? (d.getMonth() + 1) : '0' + (d.getMonth() + 1);
 17   var DD = d.getDate() >= 10 ? d.getDate() : '0' + d.getDate();
 18   var h = d.getHours() >= 10 ? d.getHours() : '0' + d.getHours();
 19   var mm = d.getMinutes() >= 10 ? d.getMinutes() : '0' + d.getMinutes();
 20   version = yy + MM + DD + h + mm;
 21 }
 22 
 23 module.exports = {
 24   //开发环境
 25   dev: {
 26     assetsSubDirectory: 'static', //定义静态资源根目录的子目录static
 27     assetsPublicPath: '/', //静态资源的公开路径
 28     //代理表,用来建一个虚拟api服务器来代理本机的请求,只用于开发模式
 29     proxyTable: devEnv.PROXY_REQUEST === false ? {} : {
 30       '/api': {
 31         target: 'http://127.0.0.1:7001', //设置调用的接口域名和端口
 32         changeOrigin: true, //是否允许跨域
 33         pathRewrite: {
 34           '^/api': '/' //这里理解成用‘/api’代替target里面的地址,后面组件中我们掉接口时直接用api代替 比如我要调用'http://40.00.100.100:3002/user/add',直接写‘/api/user/add’即可
 35         }
 36       }
 37     },
 38 
 39     // Various Dev Server settings
 40     host: 'localhost', // can be overwritten by process.env.HOST
 41     port: 8081, // can be overwritten by process.env.PORT, if port is in use, a free one will be determined
 42     autoOpenBrowser: true, //是否在浏览器中自动打开
 43     errorOverlay: true, //是否查询错误
 44     notifyOnErrors: true, //是否通知错误
 45     poll: false, // https://webpack.js.org/configuration/dev-server/#devserver-watchoptions-
 46 
 47     // 使用Eslint加载器?
 48     // If true, your code will be linted during bundling and
 49     // linting errors and warnings will be shown in the console.
 50     useEslint: true,
 51 
 52     //如果为真,eslint错误和警告也将显示在错误叠加
 53     //在浏览器中。
 54     showEslintErrorsInOverlay: false,
 55 
 56     /**
 57      * Source Maps
 58      */
 59 
 60     // https://webpack.js.org/configuration/devtool/#development
 61     devtool: 'cheap-module-eval-source-map',
 62 
 63     // If you have problems debugging vue-files in devtools,
 64     // set this to false - it *may* help
 65     // https://vue-loader.vuejs.org/en/options.html#cachebusting
 66     cacheBusting: true,
 67 
 68     cssSourceMap: true
 69   },
 70 
 71   build: {
 72     // Template for index.html
 73     index: path.resolve(__dirname, `../dist/${version}/index.html`),
 74 
 75     // Paths
 76     assetsRoot: path.resolve(__dirname, `../dist/${version}`),
 77     assetsSubDirectory: 'static',
 78     assetsPublicPath: './',
 79 
 80     /**
 81      * Source Maps
 82      */
 83 
 84     productionSourceMap: true,
 85     // https://webpack.js.org/configuration/devtool/#production
 86     devtool: 'cheap-module-source-map',
 87 
 88     // Gzip off by default as many popular static hosts such as
 89     // Surge or Netlify already gzip all static assets for you.
 90     // Before setting to `true`, make sure to:
 91     // npm install --save-dev compression-webpack-plugin
 92     productionGzip: false,
 93     productionGzipExtensions: ['js', 'css'],
 94 
 95     // Run the build command with an extra argument to
 96     // View the bundle analyzer report after build finishes:
 97     // `npm run build --report`
 98     // Set to `true` or `false` to always turn it on or off
 99     bundleAnalyzerReport: process.env.npm_config_report
100   }
101 }

 

posted @ 2020-12-02 16:27  思猿客  阅读(749)  评论(0编辑  收藏  举报