vue.config.js 3.3 KB

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