vue.config.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. const path = require('path');
  2. const webpack = require('webpack');
  3. const createThemeColorReplacerPlugin = require('./config/plugin.config');
  4. // npm install --save-dev hard-source-webpack-plugin
  5. const HardSourceWebpackPlugin = require('hard-source-webpack-plugin');
  6. const {blue} = require("@ant-design/colors")
  7. function resolve(dir) {
  8. return path.join(__dirname, dir);
  9. }
  10. const CompressionPlugin = require("compression-webpack-plugin");
  11. const isProd = process.env.NODE_ENV === 'production'; // process.env.NODE_ENV === 'production';
  12. const Timestamp = new Date().getTime();
  13. const assetsCDN = {
  14. // webpack build externals
  15. externals: {
  16. vue: 'Vue',
  17. 'vue-router': 'VueRouter',
  18. vuex: 'Vuex',
  19. axios: 'axios'
  20. },
  21. css: [],
  22. // https://unpkg.com/browse/vue@2.6.10/
  23. js: [
  24. '//cdn.jsdelivr.net/npm/vue@2.6.10/dist/vue.min.js',
  25. '//cdn.jsdelivr.net/npm/vue-router@3.1.3/dist/vue-router.min.js',
  26. '//cdn.jsdelivr.net/npm/vuex@3.1.1/dist/vuex.min.js',
  27. '//cdn.jsdelivr.net/npm/axios@0.19.0/dist/axios.min.js'
  28. ]
  29. };
  30. // vue.config.js
  31. const vueConfig = {
  32. publicPath: process.env.VUE_APP_MERGE == 1 ? process.env.VUE_APP_BASE_URL_FM : '',
  33. configureWebpack: {
  34. // webpack plugins
  35. plugins: [
  36. // Ignore all locale files of moment.js
  37. new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/)
  38. ]
  39. },
  40. chainWebpack: config => {
  41. // 开发环境,cach能减少run dev,run build的70%的运行时间
  42. // production 环境,由于文件需要加时间戳,导致缓存没有意义。去掉随机文件名的配置,可以减少60%的打包时间。
  43. // 最终,开发环境,加载cach插件;production环境,不加载!
  44. if (!isProd) {
  45. config.plugin('cache').use(HardSourceWebpackPlugin);
  46. // config.cache(true);
  47. }
  48. // 移除prefetch插件,避免加载多余的资源
  49. config.plugins.delete('prefetch');
  50. if (isProd) {
  51. config.output.filename('js/[name].' + Timestamp + '.js').end();
  52. config.output.chunkFilename('js/[name].' + Timestamp + '.js').end();
  53. config.plugin('extract-css').tap(args => [
  54. {
  55. filename: `css/[name].${Timestamp}.css`,
  56. chunkFilename: `css/[name].${Timestamp}.css`
  57. }
  58. ]);
  59. }
  60. config.resolve.alias.set('@$', resolve('src'));
  61. const svgRule = config.module.rule('svg');
  62. svgRule.uses.clear();
  63. svgRule
  64. .oneOf('inline')
  65. .resourceQuery(/inline/)
  66. .use('vue-svg-icon-loader')
  67. .loader('vue-svg-icon-loader')
  68. .end()
  69. .end()
  70. .oneOf('external')
  71. .use('file-loader')
  72. .loader('file-loader')
  73. .options({
  74. name: 'assets/[name].[hash:8].[ext]'
  75. });
  76. // if prod is on
  77. // assets require on cdn
  78. if (isProd) {
  79. config.plugin('html').tap(args => {
  80. args[0].cdn = assetsCDN;
  81. return args;
  82. });
  83. }
  84. if (process.env.NODE_ENV === 'production') {
  85. config.plugin('compressionPlugin').use(
  86. new CompressionPlugin({
  87. filename: '[path].gz[query]', // 压缩后的文件名(保持原文件名,后缀加.gz)
  88. algorithm: 'gzip', // 使用gzip压缩
  89. test: /\.(js|css|less)$/, // 匹配文件名
  90. threshold: 10240, // 对超过10k的数据压缩
  91. minRatio: 0.8, // 压缩率小于0.8才会压缩
  92. deleteOriginalAssets: true // 删除源文件
  93. }));
  94. }
  95. },
  96. css: {
  97. loaderOptions: {
  98. less: {
  99. modifyVars: {
  100. 'primary-color': '#002FA7',
  101. 'border-radius-base': '10px',
  102. // 面包屑
  103. 'breadcrumb-base-color': '#fff',
  104. 'breadcrumb-separator-color': '#fff',
  105. 'breadcrumb-link-color-hove': '#fff',
  106. 'breadcrumb-last-item-color': '#fff',
  107. 'breadcrumb-link-color': '#fff',
  108. 'breadcrumb-font-size': '15px',
  109. // 面包屑
  110. // ****** 左侧菜单 ******
  111. //菜单背景颜色
  112. 'menu-dark-bg': 'linear-gradient(to right, #215278, #21527F, #215288, #21528A, #21528A, #21528A, #215288, #21527F, #215278)',
  113. //子菜单颜色
  114. 'menu-dark-submenu-bg': 'linear-gradient(#215278, #21527F, #215288, #21528A, #21528A, #21528A, #215288, #21527F, #215278)',
  115. 'menu-icon-size': '15px',
  116. 'menu-icon-size-lg': '16px',
  117. 'menu-item-active-bg': '#ffffff',
  118. 'menu-dark-highlight-color': '#6b89ff',
  119. 'menu-dark-item-active-bg': '#fff',
  120. 'menu-dark-selected-item-icon-color': '#a4009d',
  121. 'menu-dark-selected-item-text-color': '#1890ff',
  122. 'menu-dark-popup-bg': '#fff',
  123. 'menu-dark-color': '#fff',
  124. // ****** 左侧菜单 ******
  125. //卡片
  126. 'card-radius': '10px',
  127. },
  128. // DO NOT REMOVE THIS LINE
  129. javascriptEnabled: true
  130. }
  131. }
  132. },
  133. // disable source map in production
  134. productionSourceMap: process.env.NODE_ENV === 'development', //process.env.NODE_ENV === 'development' ? true : false
  135. lintOnSave: false,
  136. // babel-loader no-ignore node_modules/*
  137. transpileDependencies: [],
  138. devServer: {
  139. host: 'localhost',
  140. port: 8081,
  141. disableHostCheck: true,
  142. proxy: {
  143. "/DFMEA": {
  144. target: "http://localhost:8082",//接口的地址
  145. // target: "http://139.196.74.209:8090",//接口的地址
  146. changeOrigin: true
  147. // pathRewrite: {
  148. // "^/DFMEA": ""
  149. // }
  150. }
  151. }
  152. }
  153. };
  154. // preview.pro.loacg.com only do not use in your production;
  155. if (process.env.VUE_APP_PREVIEW === 'true') {
  156. // add `ThemeColorReplacer` plugin to webpack plugins
  157. vueConfig.configureWebpack.plugins.push(createThemeColorReplacerPlugin());
  158. }
  159. module.exports = vueConfig;