vue.config.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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_DVP + "/"
  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_DVP + "/"; // **重点:添加路径
  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. // 'table-sticky-scroll-bar-bg': '#1890FF',
  93. 'link-color': '#1890FF',
  94. 'btn-border-radius-base': '4px',
  95. // 'btn-primary-bg': 'linear-gradient(180deg, #00BEBE 0%, #1890FF 100%)',
  96. 'btn-default-bg': '#FFFFFF',
  97. 'btn-default-border': '#1890FF',
  98. 'btn-default-color': '#1890FF',
  99. 'btn-disable-color': '#9C9FAC',
  100. // 'btn-disable-bg': 'rgba(4, 11, 41, 0.12)',
  101. // 'btn-disable-border': 'rgba(4, 11, 41, 0.12)',
  102. 'select-border-color': '#CED0D8',
  103. 'select-item-active-bg': '#F5F6F7',
  104. 'select-item-selected-bg': '#F6F7FA',
  105. 'select-dropdown-line-height': '#F6F7FA',
  106. 'layout-header-height': '56px',
  107. 'layout-body-background': '#FFFFFF', //底背景色,原为默认灰底
  108. 'table-row-hover-bg':'#F5F6F7',
  109. 'form-item-trailing-colon': 'false',
  110. 'label-color': '#41475E',
  111. 'input-bg': '#FFFFFF',
  112. 'input-border-color': '#CED0D8',
  113. // 'input-placeholder-color': '#9C9FAC',
  114. 'card-background': '#FFFFFF',
  115. 'card-radius': '4px',
  116. 'card-skeleton-bg': '#9C9FAC',
  117. // 'pagination-font-family': '宋体',
  118. // 'pagination-item-size': '24px',
  119. // 'pagination-item-bg-active': '#1890FF',
  120. 'table-row-hover-bg': '#fafafa',
  121. // 表单margin底部
  122. 'form-item-margin-bottom': '0px',
  123. },
  124. javascriptEnabled: true
  125. }
  126. }
  127. },
  128. devServer: {
  129. host: 'localhost',
  130. port: 8084,
  131. disableHostCheck: true,
  132. proxy: {
  133. "/DFMEA": {
  134. target: "http://localhost:8082",//接口的地址
  135. // target: "http://1.117.58.199:8090",//接口的地址
  136. changeOrigin: true,
  137. pathRewrite: {
  138. "^/DFMEA": "/DFMEA"
  139. }
  140. }
  141. }
  142. }
  143. };