vue.config.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. const CompressionWebpackPlugin = require('compression-webpack-plugin');
  2. const { transformElementScss } = require('ele-admin/lib/utils/dynamic-theme');
  3. const path = require('path');
  4. const { name } = require('./package.json');
  5. function resolve (dir) {
  6. return path.join(__dirname, dir);
  7. }
  8. module.exports = {
  9. publicPath: '/eam',
  10. lintOnSave: false,
  11. productionSourceMap: false,
  12. configureWebpack: {
  13. performance: {
  14. maxAssetSize: 2000000,
  15. maxEntrypointSize: 2000000
  16. },
  17. output: {
  18. // 把子应用打包成 umd 库格式
  19. library: {
  20. type: 'umd',
  21. name: `${name}`
  22. },
  23. chunkLoadingGlobal: `webpackJsonp_${name}`
  24. }
  25. },
  26. devServer: {
  27. // 代理跨域的配置
  28. proxy: {
  29. // 当我们的本地的请求 有/api的时候,就会代理我们的请求地址向另外一个服务器发出请求
  30. '/api': {
  31. target: 'http://192.168.3.51:18086', // 测试环境
  32. // target: 'http://124.71.68.31:50001',
  33. changeOrigin: true, // 只有这个值为true的情况下 才表示开启跨域
  34. pathRewrite: {
  35. '^/api': ''
  36. }
  37. }
  38. }
  39. },
  40. chainWebpack (config) {
  41. config.plugins.delete('prefetch');
  42. // set svg-sprite-loader
  43. // config.module.rule('svg').exclude.add(resolve('./src/icons')).end();
  44. // config.module
  45. // .rule('icons')
  46. // .test(/\.svg$/)
  47. // .include.add(resolve('./src/icons'))
  48. // .end()
  49. // .use('svg-sprite-loader')
  50. // .loader('svg-sprite-loader')
  51. // .options({
  52. // symbolId: 'icon-[name]'
  53. // })
  54. // .end();
  55. config.module.rule('svg').exclude.add(resolve('src/icons')).end();
  56. config.module
  57. .rule('icons')
  58. .test(/\.svg$/)
  59. .include.add(resolve('src/icons'))
  60. .end()
  61. .use('svg-sprite-loader')
  62. .loader('svg-sprite-loader')
  63. .options({
  64. symbolId: 'icon-[name]'
  65. })
  66. .end();
  67. if (process.env.NODE_ENV !== 'development') {
  68. // gzip 压缩
  69. config.plugin('compressionPlugin').use(
  70. new CompressionWebpackPlugin({
  71. test: /\.(js|css|html)$/,
  72. threshold: 10240
  73. })
  74. );
  75. }
  76. },
  77. css: {
  78. loaderOptions: {
  79. sass: {
  80. sassOptions: {
  81. outputStyle: 'expanded',
  82. importer: transformElementScss()
  83. }
  84. }
  85. }
  86. }
  87. };