vue.config.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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. '//unpkg.zhimg.com/vue@2.6.10/dist/vue.min.js',
  30. '//unpkg.zhimg.com/vue-router@3.1.3/dist/vue-router.min.js',
  31. '//unpkg.zhimg.com/vuex@3.1.1/dist/vuex.min.js',
  32. '//unpkg.zhimg.com/axios@0.19.0/dist/axios.min.js'
  33. ]
  34. }
  35. // vue.config.js
  36. const vueConfig = {
  37. configureWebpack: {
  38. // webpack plugins
  39. plugins: [
  40. // Ignore all locale files of moment.js
  41. new webpack.IgnorePlugin({
  42. resourceRegExp: /^\.\/locale$/,
  43. contextRegExp: /moment$/
  44. }),
  45. new webpack.DefinePlugin({
  46. APP_VERSION: `"${require('./package.json').version}"`,
  47. GIT_HASH: JSON.stringify(getGitHash()),
  48. BUILD_DATE: buildDate
  49. })
  50. ],
  51. // if prod, add externals
  52. externals: isProd ? assetsCDN.externals : {}
  53. },
  54. chainWebpack: (config) => {
  55. config.resolve.alias
  56. .set('@$', resolve('src'))
  57. const svgRule = config.module.rule('svg')
  58. svgRule.uses.clear()
  59. svgRule
  60. .oneOf('inline')
  61. .resourceQuery(/inline/)
  62. .use('vue-svg-icon-loader')
  63. .loader('vue-svg-icon-loader')
  64. .end()
  65. .end()
  66. .oneOf('external')
  67. .use('file-loader')
  68. .loader('file-loader')
  69. .options({
  70. name: 'assets/[name].[hash:8].[ext]'
  71. })
  72. // if prod is on
  73. // assets require on cdn
  74. if (isProd) {
  75. config.plugin('html').tap(args => {
  76. args[0].cdn = assetsCDN
  77. return args
  78. })
  79. }
  80. },
  81. css: {
  82. loaderOptions: {
  83. less: {
  84. modifyVars: {
  85. // less vars,customize ant design theme
  86. // 'primary-color': '#F5222D',
  87. // 'link-color': '#F5222D',
  88. 'border-radius-base': '2px'
  89. },
  90. // DO NOT REMOVE THIS LINE
  91. javascriptEnabled: true
  92. }
  93. }
  94. },
  95. devServer: {
  96. // development server port 8000
  97. port: 8000,
  98. proxy: {
  99. // detail: https://cli.vuejs.org/config/#devserver-proxy
  100. [process.env.VUE_APP_BASE_API]: {
  101. // target: `https://ruoyi.setworld.net`,
  102. target: `http://113.249.153.164:7618/api`,
  103. // target:`http://192.168.31.129:8080/`,
  104. changeOrigin: true,
  105. pathRewrite: {
  106. ['^' + process.env.VUE_APP_BASE_API]: ''
  107. }
  108. }
  109. }
  110. },
  111. // disable source map in production
  112. productionSourceMap: false,
  113. lintOnSave: undefined,
  114. // babel-loader no-ignore node_modules/*
  115. transpileDependencies: []
  116. }
  117. // preview.pro.loacg.com only do not use in your production;
  118. if (process.env.VUE_APP_PREVIEW === 'true') {
  119. console.log('VUE_APP_PREVIEW', true)
  120. // add `ThemeColorReplacer` plugin to webpack plugins
  121. vueConfig.configureWebpack.plugins.push(createThemeColorReplacerPlugin())
  122. }
  123. module.exports = vueConfig