vue.config.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. const path = require('path')
  2. const webpack = require('webpack')
  3. const packageJson = require('./package.json')
  4. const GitRevisionPlugin = require('git-revision-webpack-plugin')
  5. const GitRevision = new GitRevisionPlugin()
  6. const buildDate = JSON.stringify(new Date().toLocaleString())
  7. const createThemeColorReplacerPlugin = require('./config/plugin.config')
  8. function resolve (dir) {
  9. return path.join(__dirname, dir)
  10. }
  11. // check Git
  12. function getGitHash () {
  13. try {
  14. return GitRevision.version()
  15. } catch (e) {}
  16. return 'unknown'
  17. }
  18. // eslint-disable-next-line no-unused-vars
  19. const isProd = process.env.NODE_ENV === 'production'
  20. // eslint-disable-next-line no-unused-vars
  21. const assetsCDN = {
  22. // webpack build externals
  23. externals: {
  24. vue: 'Vue',
  25. 'vue-router': 'VueRouter',
  26. vuex: 'Vuex',
  27. axios: 'axios'
  28. },
  29. css: [],
  30. // https://unpkg.com/browse/vue@2.6.10/
  31. js: [
  32. '//cdn.jsdelivr.net/npm/vue@2.6.14/dist/vue.min.js',
  33. '//cdn.jsdelivr.net/npm/vue-router@3.5.1/dist/vue-router.min.js',
  34. '//cdn.jsdelivr.net/npm/vuex@3.1.1/dist/vuex.min.js',
  35. '//cdn.jsdelivr.net/npm/axios@0.21.1/dist/axios.min.js'
  36. ]
  37. }
  38. // vue.config.js
  39. const vueConfig = {
  40. configureWebpack: {
  41. // webpack plugins
  42. plugins: [
  43. // Ignore all locale files of moment.js
  44. new webpack.IgnorePlugin({
  45. contextRegExp: /^\.\/locale$/,
  46. resourceRegExp: /moment$/
  47. }),
  48. new webpack.DefinePlugin({
  49. APP_VERSION: `"${packageJson.version}"`,
  50. GIT_HASH: JSON.stringify(getGitHash()),
  51. BUILD_DATE: buildDate
  52. })
  53. ]
  54. // en_US: `if prod, add externals`
  55. // zh_CN: `这里是用来控制编译忽略外部依赖的,与 config.plugin('html') 配合可以编译时引入外部CDN文件依赖`
  56. // externals: isProd ? assetsCDN.externals : {}
  57. },
  58. chainWebpack: (config) => {
  59. config.resolve.alias.set('@$', resolve('src'))
  60. // fixed svg-loader by https://github.com/damianstasik/vue-svg-loader/issues/185#issuecomment-1126721069
  61. const svgRule = config.module.rule('svg')
  62. // Remove regular svg config from root rules list
  63. config.module.rules.delete('svg')
  64. config.module
  65. .rule('svg')
  66. // Use svg component rule
  67. .oneOf('svg_as_component')
  68. .resourceQuery(/inline/)
  69. .test(/\.(svg)(\?.*)?$/)
  70. .use('babel-loader')
  71. .loader('babel-loader')
  72. .end()
  73. .use('vue-svg-loader')
  74. .loader('vue-svg-loader')
  75. .options({
  76. svgo: {
  77. plugins: [
  78. { prefixIds: true },
  79. { cleanupIDs: true },
  80. { convertShapeToPath: false },
  81. { convertStyleToAttrs: true }
  82. ]
  83. }
  84. })
  85. .end()
  86. .end()
  87. // Otherwise use original svg rule
  88. .oneOf('svg_as_regular')
  89. .merge(svgRule.toConfig())
  90. .end()
  91. // en_US: If prod is on assets require on cdn
  92. // zh_CN: 如果是 prod 模式,则引入 CDN 依赖文件,有需要减少包大小请自行解除依赖
  93. //
  94. // if (isProd) {
  95. // config.plugin('html').tap(args => {
  96. // args[0].cdn = assetsCDN
  97. // return args
  98. // })
  99. // }
  100. },
  101. css: {
  102. loaderOptions: {
  103. less: {
  104. modifyVars: {
  105. // less vars,customize Stock Agent theme
  106. // 'primary-color': '#F5222D',
  107. // 'link-color': '#F5222D',
  108. 'border-radius-base': '2px'
  109. },
  110. // DO NOT REMOVE THIS LINE
  111. javascriptEnabled: true
  112. }
  113. }
  114. },
  115. publicPath: './', // 打包路径,使用相对路径生成的dist文件夹下的index可以打开
  116. outputDir: 'dist', // 输出文件目录
  117. devServer: {
  118. // development server port 8000
  119. port: 8000,
  120. host: '0.0.0.0',
  121. // If you want to turn on the proxy, please remove the mockjs /src/main.jsL11
  122. proxy: {
  123. '/': {
  124. // target: 'https://admin.inside-ibkr.com',
  125. target: process.env.VUE_APP_API_BASE_URL,
  126. ws: true,
  127. secure: false, // 如果是https请求 需要设置为true
  128. changeOrigin: true,
  129. pathRewrite: {
  130. '^/': ''
  131. }
  132. }
  133. }
  134. },
  135. // disable source map in production
  136. productionSourceMap: false,
  137. lintOnSave: false,
  138. // babel-loader no-ignore node_modules/*
  139. transpileDependencies: []
  140. }
  141. // preview.pro.loacg.com only do not use in your production;
  142. if (process.env.VUE_APP_PREVIEW === 'true') {
  143. // add `ThemeColorReplacer` plugin to webpack plugins
  144. vueConfig.configureWebpack.plugins.push(createThemeColorReplacerPlugin())
  145. }
  146. module.exports = vueConfig