VUECLI3配置-跨域-ESLINT-GZIP-MAP

注意:cue-cli3以后的版本没有webpack.json文件,需要自己在项目根目录创建vue.config.js文件进行配置文件的配置

新建vue.config.js文件,按照需求配置以下文件

// 引入gzip压缩文件
const CompressionPlugin = require(‘compression-webpack-plugin’)
// 引入移除clog的插件----已卸载
// npm install uglifyjs-webpack-plugin --save
// const UglifyJsPlugin = require(‘uglifyjs-webpack-plugin’)

module.exports = {
  publicPath: ‘./’,
  outputDir: ‘dist’, // build输出目录
  // assetsDir: ‘assets’, // 静态资源目录(js, css, img)
  lintOnSave: false, // 是否开启eslint
  // disableHostCheck: true,
  // 关掉后打包的dist/js内就没有map文件了
  productionSourceMap: false,
  // 开启gzip压缩
  configureWebpack: config => {
  if (process.env.NODE_ENV === ‘production’) {
  return {
  // GZip压缩
  plugins: [
    new CompressionPlugin({
    test: /.jsKaTeX parse error: Can't use function '\.' in math mode at position 2: |\̲.̲html|.css/, //正则匹配要压缩的文件类型
    threshold: 10240, //对大于10k的文件进行压缩
    deleteOriginalAssets: false //是否删除源文件
    }),
    // 取消console.log();
    // new UglifyJsPlugin({
    // uglifyOptions: {
    // compress: {
    // // warnings: false,
    // drop_debugger: true, // console
    // drop_console: true,
    // pure_funcs:[‘console.log’] // 移除console
    // },
    // },
    // sourceMap: false,
    // parallel: true,
    // })
    ]
    }
   }
  },
  devServer: {
  disableHostCheck: true,
  open: true, // 是否自动弹出浏览器页面
  // host: ‘localhost’, // 连其他网络
  host: ‘192.168.1.28’, // 设置为自己电脑的IP方便在同一局域网上面的任何设备上面访问调试页面
  port: ‘8080’,
  https: false, // 是否使用https协议
  hotOnly: false, // 是否开启热更新
  // 需要解决跨域的服务器
  // proxy: {
    // ‘/api’: {
    // target: ‘http://192.168.1.18:9099’, //如果需要连接同事的电脑本地调接口,只要在同一局域网下跨域到同事的ip即可连接到同事的电脑进行调试
    // changeOrigin: true,
    // ws: true,
    // pathRewrite: {
    // ‘^/api’: ‘/’
    // }
  // },
  proxy: {
    ‘/api’: {
    target: ‘http://wh.crreniidea.com’, // 测试服务器的地址
    changeOrigin: true,
    ws: true,
    pathRewrite: {
    ‘^/api’: ‘/’
    }
  }
// 生产环境
  // proxy: {
    // ‘/api’: {
    // target: ‘http://app.shghjkwhghhny.com.cn:27015’, // 生产服务器的地址
    // changeOrigin: true,
    // ws: true,
    // pathRewrite: {
    // ‘^/api’: ‘/’
    // }
  // }
  }
}
}

你可能感兴趣的:(vue,web,app,vue.js)