钱包项目配置.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. const path = require("path");
  2. /**
  3. * resolve
  4. * @param {*} dir
  5. * @returns
  6. */
  7. function resolve(dir) {
  8. return path.join(__dirname, dir);
  9. }
  10. /**
  11. * 生成版本号(时间戳 按小时)
  12. * @returns {String}
  13. */
  14. function getTimeStampVersion() {
  15. const now = new Date();
  16. const year = now.getFullYear();
  17. const month = now.getMonth() + 1;
  18. const date = now.getDate();
  19. const hour = now.getHours();
  20. const minutes = now.getMinutes();
  21. const padZero = (n) => String(n).padStart(2, "0");
  22. return `${year}${padZero(month)}${padZero(date)}${padZero(hour)}${padZero(
  23. minutes
  24. )}`;
  25. }
  26. const appVersion = getTimeStampVersion();
  27. const assetsDir = "assets";
  28. module.exports = {
  29. publicPath: "./",
  30. assetsDir: assetsDir,
  31. lintOnSave: process.env.NODE_ENV === "development",
  32. productionSourceMap: false,
  33. devServer: {
  34. proxy: {
  35. "/super_cloud/api": {
  36. // target: 'https://wx.palmnest.com',
  37. target: "https://superdesk.avic-s.com",
  38. changeOrigin: true,
  39. secure: false,
  40. onProxyReq(proxyReq, req, res) {
  41. proxyReq.removeHeader("origin");
  42. },
  43. },
  44. "/app/index.php": {
  45. // target: 'https://wx.palmnest.com',
  46. target: "https://superdesk.avic-s.com",
  47. changeOrigin: true,
  48. secure: false,
  49. onProxyReq(proxyReq, req, res) {
  50. proxyReq.removeHeader("origin");
  51. },
  52. },
  53. },
  54. },
  55. css: {
  56. loaderOptions: {
  57. less: {
  58. modifyVars: {
  59. hack: `true; @import '~@/styles/variable.less';`,
  60. },
  61. },
  62. },
  63. },
  64. chainWebpack(config) {
  65. if (process.env.NODE_ENV === "production") {
  66. // js和css 使用版本号
  67. config.output.filename(`${assetsDir}/js/[name].${appVersion}.js`).end();
  68. config.output
  69. .chunkFilename(`${assetsDir}/js/[name].${appVersion}.js`)
  70. .end();
  71. config
  72. .plugin("extract-css")
  73. .tap((args) => {
  74. args[0].filename = `${assetsDir}/css/[name].${appVersion}.css`;
  75. args[0].chunkFilename = `${assetsDir}/css/[name].${appVersion}.css`;
  76. return args;
  77. })
  78. .end();
  79. }
  80. // 删除预加载
  81. config.plugins.delete("preload");
  82. config.plugins.delete("prefetch");
  83. // HtmlWebpackPlugin
  84. config
  85. .plugin("html")
  86. .tap((args) => {
  87. args[0].title = process.env.VUE_APP_TITLE;
  88. return args;
  89. })
  90. .end();
  91. // DefinePlugin
  92. config
  93. .plugin("define")
  94. .tap((args) => {
  95. args[0]["process.env"].APP_VERSION = appVersion;
  96. return args;
  97. })
  98. .end();
  99. },
  100. };