vue.config.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. const path = require('path')
  2. const webpack = require('webpack')
  3. const GitRevisionPlugin = require('git-revision-webpack-plugin')
  4. const GitRevision = new GitRevisionPlugin()
  5. const buildDate = JSON.stringify(new Date().toLocaleString())
  6. const createThemeColorReplacerPlugin = require('./config/plugin.config')
  7. function resolve (dir) {
  8. return path.join(__dirname, dir)
  9. }
  10. // check Git
  11. function getGitHash () {
  12. try {
  13. return GitRevision.version()
  14. } catch (e) {}
  15. return 'unknown'
  16. }
  17. const isProd = process.env.NODE_ENV === 'production'
  18. const assetsCDN = {
  19. // webpack build externals
  20. externals: {
  21. vue: 'Vue',
  22. 'vue-router': 'VueRouter',
  23. vuex: 'Vuex',
  24. axios: 'axios'
  25. },
  26. css: [],
  27. // https://unpkg.com/browse/vue@2.6.10/
  28. js: [
  29. '//cdn.jsdelivr.net/npm/vue@2.6.10/dist/vue.min.js',
  30. '//cdn.jsdelivr.net/npm/vue-router@3.1.3/dist/vue-router.min.js',
  31. '//cdn.jsdelivr.net/npm/vuex@3.1.1/dist/vuex.min.js',
  32. '//cdn.jsdelivr.net/npm/axios@0.19.0/dist/axios.min.js'
  33. ]
  34. }
  35. // vue.config.js
  36. const vueConfig = {
  37. assetsDir: '',
  38. publicPath: './',
  39. configureWebpack: {
  40. // webpack plugins
  41. plugins: [
  42. // Ignore all locale files of moment.js
  43. new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/),
  44. new webpack.DefinePlugin({
  45. APP_VERSION: `"${require('./package.json').version}"`,
  46. GIT_HASH: JSON.stringify(getGitHash()),
  47. BUILD_DATE: buildDate
  48. })
  49. ],
  50. // if prod, add externals
  51. externals: isProd ? assetsCDN.externals : {}
  52. },
  53. chainWebpack: (config) => {
  54. config.resolve.alias
  55. .set('@$', resolve('src'))
  56. const svgRule = config.module.rule('svg')
  57. svgRule.uses.clear()
  58. svgRule
  59. .oneOf('inline')
  60. .resourceQuery(/inline/)
  61. .use('vue-svg-icon-loader')
  62. .loader('vue-svg-icon-loader')
  63. .end()
  64. .end()
  65. .oneOf('external')
  66. .use('file-loader')
  67. .loader('file-loader')
  68. .options({
  69. name: 'assets/[name].[hash:8].[ext]'
  70. })
  71. // if prod is on
  72. // assets require on cdn
  73. if (isProd) {
  74. config.plugin('html').tap(args => {
  75. args[0].cdn = assetsCDN
  76. return args
  77. })
  78. }
  79. },
  80. css: {
  81. loaderOptions: {
  82. less: {
  83. modifyVars: {
  84. // less vars,customize ant design theme
  85. // 'primary-color': '#F5222D',
  86. // 'link-color': '#F5222D',
  87. 'border-radius-base': '2px'
  88. },
  89. // DO NOT REMOVE THIS LINE
  90. javascriptEnabled: true
  91. }
  92. }
  93. },
  94. devServer: {
  95. // development server port 8000
  96. port: 18000,
  97. // If you want to turn on the proxy, please remove the mockjs /src/main.jsL11
  98. proxy: {
  99. '/api': {
  100. // target: 'http://192.168.1.21:39090',
  101. // target: 'http://192.168.1.198:39090',
  102. // target: 'https://open.luojigou.vip/town-crm',
  103. target: 'https://open.api.luojigou.vip/town-crm',
  104. ws: false,
  105. secure: false,
  106. changeOrigin: true,
  107. pathRewrite: {
  108. '^/api': ''
  109. }
  110. }
  111. }
  112. },
  113. // disable source map in production
  114. productionSourceMap: false,
  115. lintOnSave: false,
  116. // babel-loader no-ignore node_modules/*
  117. transpileDependencies: []
  118. }
  119. // preview.pro.loacg.com only do not use in your production;
  120. if (process.env.VUE_APP_PREVIEW === 'true') {
  121. console.log('VUE_APP_PREVIEW', true)
  122. // add `ThemeColorReplacer` plugin to webpack plugins
  123. vueConfig.configureWebpack.plugins.push(createThemeColorReplacerPlugin())
  124. }
  125. module.exports = vueConfig