Kaynağa Gözat

feat: 添加 vue.config.js 配置文件,包含 webpack 配置和开发服务器代理设置

xie 3 hafta önce
ebeveyn
işleme
e18e71d273
1 değiştirilmiş dosya ile 113 ekleme ve 0 silme
  1. 113 0
      vue.config.js

+ 113 - 0
vue.config.js

@@ -0,0 +1,113 @@
+const CompressionWebpackPlugin = require('compression-webpack-plugin');
+const { transformElementScss } = require('ele-admin/lib/utils/dynamic-theme');
+const path = require('path');
+const { name } = require('./package.json');
+
+function resolve(dir) {
+  return path.join(__dirname, dir);
+}
+
+module.exports = {
+  publicPath: '/aps',
+  lintOnSave: false,
+  productionSourceMap: false,
+  configureWebpack: {
+    performance: {
+      maxAssetSize: 2000000,
+      maxEntrypointSize: 2000000
+    },
+    output: {
+      // 把子应用打包成 umd 库格式
+      library: {
+        type: 'umd',
+        name: `${name}`
+      },
+
+      chunkLoadingGlobal: `webpackJsonp_${name}`
+    }
+  },
+  devServer: {
+    // 代理跨域的配置
+    proxy: {
+      // 当我们的本地的请求 有/api的时候,就会代理我们的请求地址向另外一个服务器发出请求
+      '/api': {
+        // target: 'http://192.168.1.210:86/',
+        // target: 'http://192.168.1.103:18086',
+        // target: 'http://192.168.1.158:18086',
+        target: 'http://192.168.1.158:18086',
+        // target: 'http://192.168.1.251:18086',
+        // target: 'http://192.168.1.144:18086',
+        // target: 'http://192.168.1.251:18186',
+        // target: 'http://192.168.1.211:18086',
+        // target: 'http://192.168.1.251:18186',
+        // target: 'http://192.168.1.102:18086',
+        // target: 'http://aiot.zoomwin.com.cn:51001/api',
+        // target: 'http://192.168.1.125:18086',
+        // target: 'http://192.168.1.19:18086',
+        // target: 'http://192.168.1.116:18086',
+
+        changeOrigin: true, // 只有这个值为true的情况下 才表示开启跨域
+        pathRewrite: {
+          '^/api': ''
+        }
+      }
+    },
+    headers: {
+      'Access-Control-Allow-Origin': '*'
+    }
+  },
+  chainWebpack(config) {
+    config.plugins.delete('prefetch');
+    // set svg-sprite-loader
+    // config.module.rule('svg').exclude.add(resolve('./src/icons')).end();
+    // config.module
+    //   .rule('icons')
+    //   .test(/\.svg$/)
+    //   .include.add(resolve('./src/icons'))
+    //   .end()
+    //   .use('svg-sprite-loader')
+    //   .loader('svg-sprite-loader')
+    //   .options({
+    //     symbolId: 'icon-[name]'
+    //   })
+    //   .end();
+    config.module
+      .rule('file-loader')
+      .test(/\.(pdf|docx|doc|xlsx|xls|mp4)$/)
+      .use('file-loader?name=[path][name].[ext]')
+      .loader('file-loader')
+      .end();
+    config.module.rule('svg').exclude.add(resolve('src/icons')).end();
+    config.module
+      .rule('icons')
+      .test(/\.svg$/)
+      .include.add(resolve('src/icons'))
+      .end()
+      .use('svg-sprite-loader')
+      .loader('svg-sprite-loader')
+      .options({
+        symbolId: 'icon-[name]'
+      })
+      .end();
+
+    if (process.env.NODE_ENV !== 'development') {
+      // gzip 压缩
+      config.plugin('compressionPlugin').use(
+        new CompressionWebpackPlugin({
+          test: /\.(js|css|html)$/,
+          threshold: 10240
+        })
+      );
+    }
+  },
+  css: {
+    loaderOptions: {
+      sass: {
+        sassOptions: {
+          outputStyle: 'expanded',
+          importer: transformElementScss()
+        }
+      }
+    }
+  }
+};