vue.config.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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. const timestamp = new Date().getTime()
  34. module.exports = defineConfig({
  35. publicPath,
  36. assetsDir,
  37. outputDir,
  38. lintOnSave,
  39. transpileDependencies,
  40. devServer: {
  41. compress: true,
  42. client: {
  43. progress: false,
  44. overlay: {
  45. warnings: false,
  46. errors: true,
  47. },
  48. },
  49. hot: true,
  50. open: {
  51. target: [`http://localhost:${devPort}`],
  52. },
  53. port: devPort,
  54. // setupMiddlewares: require('./mock'),
  55. // 注释掉的地方是前端配置代理访问后端的示例,如无特别需求,不建议使用!!!
  56. // baseURL必须为/xxx,而不是后端服务器,请先了解代理逻辑,再设置前端代理
  57. // !!!一定要注意!!!
  58. // 1、这里配置了跨域及代理只针对开发环境生效
  59. // 2、不建议你在前端配置跨域,建议你后端配置Allow-Origin,Method,Headers,放行token字段,一步到位
  60. // 3、后端配置了跨域,就不需要前端再配置,会发生Origin冲突
  61. // 4、webpack5版本前端配置代理无法与mock同时使用,如果一定要用前端代理,需注释setupMiddlewares: require('./mock')
  62. proxy: {
  63. [baseURL]: {
  64. target: `http://api.dwbszbs.dev.xmnk.cn/admin`,
  65. // target: `https://zbs.admin.xueyousuohuo.cn/admin`,
  66. ws: true,
  67. changeOrigin: true,
  68. pathRewrite: {
  69. [`^${baseURL}`]: '',
  70. },
  71. },
  72. },
  73. },
  74. pwa: {
  75. workboxOptions: {
  76. skipWaiting: true,
  77. clientsClaim: true,
  78. },
  79. themeColor: '#ffffff',
  80. msTileColor: '#ffffff',
  81. appleMobileWebAppCapable: 'yes',
  82. appleMobileWebAppStatusBarStyle: 'black',
  83. manifestOptions: {
  84. name: '大卫博士学位争霸赛',
  85. short_name: '大卫博士学位争霸赛',
  86. background_color: '#ffffff',
  87. },
  88. iconPaths: {
  89. favicon32: 'favicon.ico',
  90. favicon16: 'favicon.ico',
  91. appleTouchIcon: 'favicon.ico',
  92. maskIcon: 'favicon.ico',
  93. msTileImage: 'favicon.ico',
  94. },
  95. },
  96. configureWebpack() {
  97. return {
  98. resolve: {
  99. alias: {
  100. '~': resolve(__dirname, '.'),
  101. '@': resolve(__dirname, 'src'),
  102. '/#': resolve(__dirname, 'types'),
  103. '@vab': resolve(__dirname, 'library'),
  104. '@gp': resolve('library/plugins/vab'),
  105. 'vue-i18n': 'vue-i18n/dist/vue-i18n.cjs.js',
  106. },
  107. fallback: {
  108. fs: false,
  109. path: require.resolve('path-browserify'),
  110. },
  111. },
  112. output: {
  113. // 修改输出js目录名及文件名
  114. filename: `js/[name]-${timestamp}.js`,
  115. chunkFilename: `js/[name]-${timestamp}.js`,
  116. },
  117. plugins: createVuePlugin(),
  118. performance: {
  119. hints: false,
  120. },
  121. }
  122. },
  123. chainWebpack(config) {
  124. //为了防止忘记配置而造成项目无法打包,请保留以下提示
  125. if (process.env.NODE_ENV === 'production') {
  126. if (
  127. process['env'].VUE_GITHUB_USER_NAME == 'test' &&
  128. process['env'].VUE_APP_SECRET_KEY == 'preview'
  129. )
  130. console.log(
  131. '检测到您的用户名和key未配置,key在购买时通过邮件邀请函发放,请仔细阅读文档并进行配置'
  132. )
  133. }
  134. createChainWebpack(process.env.NODE_ENV, config)
  135. },
  136. runtimeCompiler: false,
  137. productionSourceMap: false,
  138. css: {
  139. sourceMap: false,
  140. extract:
  141. process.env.NODE_ENV === 'production'
  142. ? {
  143. ignoreOrder: true,
  144. }
  145. : false,
  146. loaderOptions: {
  147. sass: {
  148. sassOptions: { outputStyle: 'expanded' },
  149. additionalData(content, { rootContext, resourcePath }) {
  150. const relativePath = relative(rootContext, resourcePath)
  151. if (
  152. relativePath.replace(/\\/g, '/') !==
  153. 'library/styles/variables/variables.module.scss'
  154. )
  155. return `@use "~@vab/styles/variables/variables.module.scss" as *;${content}`
  156. return content
  157. },
  158. },
  159. },
  160. },
  161. })