vue.config.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. const path = require("path");
  2. // npm install --save-dev hard-source-webpack-plugin
  3. const HardSourceWebpackPlugin = require('hard-source-webpack-plugin');
  4. // function resolve(dir) {
  5. // return path.join(__dirname, dir)
  6. // }
  7. const CompressionPlugin = require("compression-webpack-plugin");
  8. const isProd = process.env.NODE_ENV === "production";
  9. const Timestamp = new Date().getTime();
  10. const webpack = require("webpack");
  11. module.exports = {
  12. configureWebpack: {
  13. // 支持全局jquery
  14. plugins: [
  15. new webpack.ProvidePlugin({
  16. $: "jquery",
  17. jQuery: "jquery",
  18. "windows.jQuery": "jquery"
  19. })
  20. ]
  21. },
  22. assetsDir: "assets",
  23. publicPath:
  24. process.env.VUE_APP_MERGE == 1
  25. ? process.env.VUE_APP_BASE_URL_MFE + "/"
  26. : "", //合并三个应用
  27. lintOnSave: false,
  28. productionSourceMap: process.env.NODE_ENV == "development" ? true : false, //process.env.NODE_ENV == 'development' ? true : false
  29. pluginOptions: {
  30. "style-resources-loader": {
  31. preProcessor: "less",
  32. patterns: [path.resolve(__dirname, "src/styles/mixins.less")]
  33. }
  34. },
  35. chainWebpack: (config) => {
  36. // 开发环境,cach能减少run dev,run build的70%的运行时间
  37. // production 环境,由于文件需要加时间戳,导致缓存没有意义。去掉随机文件名的配置,可以减少60%的打包时间。
  38. // 最终,开发环境,加载cach插件;production环境,不加载!
  39. if (!isProd) {
  40. config.plugin('cache').use(HardSourceWebpackPlugin);
  41. // config.cache(true);
  42. }
  43. // 移除prefetch插件,避免加载多余的资源
  44. config.plugins.delete('prefetch');
  45. if (isProd) {
  46. config.output.filename("js/[name]." + Timestamp + ".js").end();
  47. config.output.chunkFilename("js/[name]." + Timestamp + ".js").end();
  48. config.plugin("extract-css").tap((args) => [
  49. {
  50. filename: `css/[name].${Timestamp}.css`,
  51. chunkFilename: `css/[name].${Timestamp}.css`
  52. }
  53. ]);
  54. }
  55. config.module
  56. .rule("fonts")
  57. .use("url-loader")
  58. .loader("url-loader")
  59. .tap((options) => {
  60. options["limit"] = 4096;
  61. options["publicPath"] = process.env.VUE_APP_BASE_URL_MFE + "/"; // **重点:添加路径
  62. return options;
  63. });
  64. // if prod is on
  65. // assets require on cdn
  66. // if (isProd) {
  67. // //isProd
  68. // config.plugin("html").tap((args) => {
  69. // args[0].cdn = assetsCDN;
  70. // return args;
  71. // });
  72. // }
  73. if (process.env.NODE_ENV === 'production') {
  74. config.plugin('compressionPlugin').use(
  75. new CompressionPlugin({
  76. filename: '[path].gz[query]', // 压缩后的文件名(保持原文件名,后缀加.gz)
  77. algorithm: 'gzip', // 使用gzip压缩
  78. test: /\.(js|css|less)$/, // 匹配文件名
  79. threshold: 10240, // 对超过10k的数据压缩
  80. minRatio: 0.8, // 压缩率小于0.8才会压缩
  81. deleteOriginalAssets: true // 删除源文件
  82. }));
  83. }
  84. },
  85. css: {
  86. loaderOptions: {
  87. less: {
  88. modifyVars: {
  89. 'primary-color': '#1890ff',
  90. 'font-family': '宋体',
  91. 'border-radius-base': '4px',
  92. 'link-color': '#1890FF',
  93. 'btn-border-radius-base': '4px',
  94. 'btn-default-bg': '#FFFFFF',
  95. 'btn-default-border': '#1890ff',
  96. 'btn-default-color': '#1890FF',
  97. 'btn-disable-color': '#9C9FAC',
  98. 'select-border-color': '#CED0D8',
  99. 'select-item-active-bg': '#F5F6F7',
  100. 'select-item-selected-bg': '#F6F7FA',
  101. 'select-dropdown-line-height': '#F6F7FA',
  102. 'layout-header-height': '56px',
  103. 'layout-body-background': '#FFFFFF', //底背景色,原为默认灰底
  104. 'table-row-hover-bg': '#F5F6F7',
  105. 'form-item-trailing-colon': 'false',
  106. 'label-color': '#41475E',
  107. 'input-bg': '#FFFFFF',
  108. 'input-border-color': '#CED0D8',
  109. 'card-background': '#FFFFFF',
  110. 'card-radius': '4px',
  111. 'card-skeleton-bg': '#9C9FAC',
  112. 'table-row-hover-bg': '#fafafa',
  113. 'form-item-margin-bottom': '0px',
  114. },
  115. javascriptEnabled: true
  116. }
  117. }
  118. },
  119. devServer: {
  120. host: 'localhost',
  121. port: 8084,
  122. disableHostCheck: true,
  123. proxy: {
  124. "/DFMEA": {
  125. target: "http://localhost:8082",//接口的地址
  126. // target: "http://1.117.58.199:8090",//接口的地址
  127. changeOrigin: true,
  128. pathRewrite: {
  129. "^/DFMEA": "/DFMEA"
  130. }
  131. }
  132. }
  133. }
  134. };