vue.config.js 3.5 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. // const isProd = process.env.NODE_ENV === 'production'
  11. // const assetsCDN = {
  12. // // webpack build externals
  13. // externals: {
  14. // vue: 'Vue',
  15. // 'vue-router': 'VueRouter',
  16. // vuex: 'Vuex',
  17. // axios: 'axios'
  18. // },
  19. // css: [],
  20. // // https://unpkg.com/browse/vue@2.6.10/
  21. // js: [
  22. // '//lib.baomitu.com/vue/2.6.10/vue.min.js',
  23. // '//lib.baomitu.com/vue-router/3.1.3/vue-router.min.js',
  24. // '//lib.baomitu.com/vuex/3.1.1/vuex.min.js',
  25. // '//lib.baomitu.com/axios/0.19.0/axios.min.js'
  26. // ]
  27. // }
  28. // vue.config.js
  29. const vueConfig = {
  30. // 部署应用包时的基本 URL
  31. publicPath: process.env.NODE_ENV === 'production' ? './' : '/',
  32. configureWebpack: {
  33. // webpack plugins
  34. plugins: [
  35. // Ignore all locale files of moment.js
  36. // new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/),
  37. // new webpack.DefinePlugin({
  38. // APP_VERSION: `"${require('./package.json').version}"`,
  39. // GIT_HASH: JSON.stringify(GitRevision.version()),
  40. // BUILD_DATE: buildDate
  41. // })
  42. ],
  43. // if prod, add externals
  44. // externals: isProd ? assetsCDN.externals : {}
  45. },
  46. chainWebpack: (config) => {
  47. config.resolve.alias
  48. .set('@$', resolve('src'))
  49. const svgRule = config.module.rule('svg')
  50. svgRule.uses.clear()
  51. svgRule
  52. .oneOf('inline')
  53. .resourceQuery(/inline/)
  54. .use('vue-svg-icon-loader')
  55. .loader('vue-svg-icon-loader')
  56. .end()
  57. .end()
  58. .oneOf('external')
  59. .use('file-loader')
  60. .loader('file-loader')
  61. .options({
  62. name: 'assets/[name].[hash:8].[ext]'
  63. })
  64. // if prod is on
  65. // assets require on cdn
  66. // if (isProd) {
  67. // config.plugin('html').tap(args => {
  68. // args[0].cdn = assetsCDN
  69. // return args
  70. // })
  71. // }
  72. },
  73. css: {
  74. // 定位css文件
  75. sourceMap: true,
  76. loaderOptions: {
  77. less: {
  78. modifyVars: {
  79. // less vars,customize ant design theme
  80. // VIP金色
  81. // 'primary-color': '#d6893b',
  82. // 'link-color': '#bc791c',
  83. // 默认蓝
  84. 'primary-color': '#1890ff',
  85. 'link-color': '#1890ff',
  86. 'font-size-base': '13px',
  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: 8120,
  97. // 本地开发代理:/api/xxx → http://127.0.0.1:18080/store/xxx(Java 版后端)
  98. proxy: {
  99. '/api': {
  100. target: 'http://127.0.0.1:18080',
  101. ws: false,
  102. changeOrigin: true,
  103. pathRewrite: {
  104. '^/api': '/store'
  105. }
  106. }
  107. }
  108. },
  109. // disable source map in production
  110. productionSourceMap: false,
  111. lintOnSave: false,
  112. // babel-loader no-ignore node_modules/*
  113. transpileDependencies: []
  114. }
  115. // preview.pro.loacg.com only do not use in your production;
  116. if (process.env.VUE_APP_PREVIEW === 'true') {
  117. console.log('VUE_APP_PREVIEW', true)
  118. // add `ThemeColorReplacer` plugin to webpack plugins
  119. vueConfig.configureWebpack.plugins.push(createThemeColorReplacerPlugin())
  120. }
  121. module.exports = vueConfig