vue.config.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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://api.baiyibucha.dev.xmnk.cn/admin`,
  64. target: `http://api.zjdrkt.dev.xmnk.cn/admin`,
  65. ws: true,
  66. changeOrigin: true,
  67. pathRewrite: {
  68. [`^${baseURL}`]: '',
  69. },
  70. },
  71. },
  72. },
  73. pwa: {
  74. workboxOptions: {
  75. skipWaiting: true,
  76. clientsClaim: true,
  77. },
  78. themeColor: '#ffffff',
  79. msTileColor: '#ffffff',
  80. appleMobileWebAppCapable: 'yes',
  81. appleMobileWebAppStatusBarStyle: 'black',
  82. manifestOptions: {
  83. name: '仲景书院第二课堂综合平台',
  84. short_name: '仲景书院第二课堂综合平台',
  85. background_color: '#ffffff',
  86. },
  87. iconPaths: {
  88. favicon32: 'favicon.ico',
  89. favicon16: 'favicon.ico',
  90. appleTouchIcon: 'favicon.ico',
  91. maskIcon: 'favicon.ico',
  92. msTileImage: 'favicon.ico',
  93. },
  94. },
  95. configureWebpack() {
  96. return {
  97. resolve: {
  98. alias: {
  99. '~': resolve(__dirname, '.'),
  100. '@': resolve(__dirname, 'src'),
  101. '/#': resolve(__dirname, 'types'),
  102. '@vab': resolve(__dirname, 'library'),
  103. '@gp': resolve('library/plugins/vab'),
  104. 'vue-i18n': 'vue-i18n/dist/vue-i18n.cjs.js',
  105. },
  106. fallback: {
  107. fs: false,
  108. path: require.resolve('path-browserify'),
  109. },
  110. },
  111. plugins: createVuePlugin(),
  112. performance: {
  113. hints: false,
  114. },
  115. }
  116. },
  117. chainWebpack(config) {
  118. //为了防止忘记配置而造成项目无法打包,请保留以下提示
  119. if (process.env.NODE_ENV === 'production') {
  120. if (
  121. process['env'].VUE_GITHUB_USER_NAME == 'test' &&
  122. process['env'].VUE_APP_SECRET_KEY == 'preview'
  123. )
  124. console.log(
  125. '检测到您的用户名和key未配置,key在购买时通过邮件邀请函发放,请仔细阅读文档并进行配置'
  126. )
  127. }
  128. createChainWebpack(process.env.NODE_ENV, config)
  129. },
  130. runtimeCompiler: false,
  131. productionSourceMap: false,
  132. css: {
  133. sourceMap: false,
  134. extract:
  135. process.env.NODE_ENV === 'production'
  136. ? {
  137. ignoreOrder: true,
  138. }
  139. : false,
  140. loaderOptions: {
  141. sass: {
  142. sassOptions: { outputStyle: 'expanded' },
  143. additionalData(content, { rootContext, resourcePath }) {
  144. const relativePath = relative(rootContext, resourcePath)
  145. if (
  146. relativePath.replace(/\\/g, '/') !==
  147. 'library/styles/variables/variables.module.scss'
  148. )
  149. return `@use "~@vab/styles/variables/variables.module.scss" as *;${content}`
  150. return content
  151. },
  152. },
  153. },
  154. },
  155. })