vue.config.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. /* eslint-disable @typescript-eslint/no-unused-vars */
  2. /**
  3. * @description vue.config.js全局配置
  4. */
  5. const {
  6. baseURL,
  7. title,
  8. devPort,
  9. assetsDir,
  10. outputDir,
  11. lintOnSave,
  12. publicPath,
  13. transpileDependencies,
  14. } = require('./src/config')
  15. const dayjs = require('dayjs')
  16. const pkg = require('./package.json')
  17. const { resolve, relative } = require('path')
  18. const { defineConfig } = require('@vue/cli-service')
  19. const {
  20. createVuePlugin,
  21. createChainWebpack,
  22. } = require('./library/build/index.ts')
  23. const info = {
  24. ...pkg,
  25. lastBuildTime: dayjs().format('YYYY-MM-DD HH:mm:ss'),
  26. }
  27. process.env.VUE_APP_TITLE = title
  28. process.env.VUE_APP_AUTHOR = pkg.author
  29. process.env.VUE_APP_INFO = JSON.stringify(info)
  30. process.env.VUE_APP_UPDATE_TIME = info.lastBuildTime
  31. process.env.VUE_APP_GITHUB_USER_NAME = process.env.VUE_GITHUB_USER_NAME
  32. process.env.VUE_APP_RANDOM = `${info.lastBuildTime}-${process.env.VUE_GITHUB_USER_NAME}`
  33. module.exports = defineConfig({
  34. publicPath,
  35. assetsDir,
  36. outputDir,
  37. lintOnSave,
  38. transpileDependencies,
  39. devServer: {
  40. compress: true,
  41. client: {
  42. progress: false,
  43. overlay: {
  44. warnings: false,
  45. errors: true,
  46. },
  47. },
  48. hot: true,
  49. open: {
  50. target: [`http://localhost:${devPort}`],
  51. },
  52. port: devPort,
  53. // setupMiddlewares: require('./mock'),
  54. // 注释掉的地方是前端配置代理访问后端的示例,如无特别需求,不建议使用!!!
  55. // baseURL必须为/xxx,而不是后端服务器,请先了解代理逻辑,再设置前端代理
  56. // !!!一定要注意!!!
  57. // 1、这里配置了跨域及代理只针对开发环境生效
  58. // 2、不建议你在前端配置跨域,建议你后端配置Allow-Origin,Method,Headers,放行token字段,一步到位
  59. // 3、后端配置了跨域,就不需要前端再配置,会发生Origin冲突
  60. // 4、webpack5版本前端配置代理无法与mock同时使用,如果一定要用前端代理,需注释setupMiddlewares: require('./mock')
  61. proxy: {
  62. [baseURL]: {
  63. target: `http://jczl.site.xmnk.cn/admin`,
  64. ws: true,
  65. changeOrigin: true,
  66. pathRewrite: {
  67. [`^${baseURL}`]: '',
  68. },
  69. },
  70. },
  71. },
  72. pwa: {
  73. workboxOptions: {
  74. skipWaiting: true,
  75. clientsClaim: true,
  76. },
  77. themeColor: '#ffffff',
  78. msTileColor: '#ffffff',
  79. appleMobileWebAppCapable: 'yes',
  80. appleMobileWebAppStatusBarStyle: 'black',
  81. manifestOptions: {
  82. name: 'Vue Admin Better - Admin Plus',
  83. short_name: 'Admin Plus',
  84. background_color: '#ffffff',
  85. },
  86. },
  87. configureWebpack() {
  88. return {
  89. resolve: {
  90. alias: {
  91. '~': resolve(__dirname, '.'),
  92. '@': resolve(__dirname, 'src'),
  93. '/#': resolve(__dirname, 'types'),
  94. '@vab': resolve(__dirname, 'library'),
  95. '@gp': resolve('library/plugins/vab'),
  96. 'vue-i18n': 'vue-i18n/dist/vue-i18n.cjs.js',
  97. },
  98. fallback: {
  99. fs: false,
  100. path: require.resolve('path-browserify'),
  101. },
  102. },
  103. plugins: createVuePlugin(),
  104. performance: {
  105. hints: false,
  106. },
  107. }
  108. },
  109. chainWebpack(config) {
  110. //为了防止忘记配置而造成项目无法打包,请保留以下提示
  111. if (process.env.NODE_ENV === 'production') {
  112. if (
  113. process['env'].VUE_GITHUB_USER_NAME == 'test' &&
  114. process['env'].VUE_APP_SECRET_KEY == 'preview'
  115. )
  116. console.log(
  117. '检测到您的用户名和key未配置,key在购买时通过邮件邀请函发放,请仔细阅读文档并进行配置'
  118. )
  119. }
  120. createChainWebpack(process.env.NODE_ENV, config)
  121. },
  122. runtimeCompiler: false,
  123. productionSourceMap: false,
  124. css: {
  125. sourceMap: false,
  126. extract:
  127. process.env.NODE_ENV === 'production'
  128. ? {
  129. ignoreOrder: true,
  130. }
  131. : false,
  132. loaderOptions: {
  133. sass: {
  134. sassOptions: { outputStyle: 'expanded' },
  135. additionalData(content, { rootContext, resourcePath }) {
  136. const relativePath = relative(rootContext, resourcePath)
  137. if (
  138. relativePath.replace(/\\/g, '/') !==
  139. 'library/styles/variables/variables.module.scss'
  140. )
  141. return `@use "~@vab/styles/variables/variables.module.scss" as *;${content}`
  142. return content
  143. },
  144. },
  145. },
  146. },
  147. })