vue.config.js 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. <<<<<<< HEAD
  2. const fs = require('fs')
  3. const path = require('path')
  4. const { defineConfig } = require('@vue/cli-service')
  5. const moment = require('moment')
  6. const CompressionPlugin = require('compression-webpack-plugin')
  7. const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin')
  8. const CopyWebpackPlugin = require('copy-webpack-plugin')
  9. const convertPath = (dir) => path.resolve(__dirname, dir)
  10. const outputDir = convertPath('app/dist') // 打包输出目录
  11. module.exports = defineConfig({
  12. transpileDependencies: [/node_modules/],
  13. productionSourceMap: false, // 打包取消.map
  14. publicPath: './',
  15. outputDir,
  16. pages: {
  17. indexPath: {
  18. entry: process.env.VUE_APP_ROOT + 'main.ts',
  19. template: process.env.VUE_APP_ROOT + 'index.html',
  20. filename: 'index.html',
  21. title: process.env.VUE_APP_NAME,
  22. meta: {
  23. revised: moment(new Date()).format('YYYYMMDDHHmmss') // 打包生成版本号
  24. }
  25. }
  26. },
  27. devServer: {
  28. client: {
  29. overlay: false
  30. }
  31. },
  32. css: {
  33. extract: true, // 是否使用css分离插件 ExtractTextPlugin
  34. sourceMap: false,
  35. loaderOptions: {
  36. postcss: {
  37. postcssOptions: {
  38. config: process.env.VUE_APP_ROOT, // 自定义 postcss.config.js 文件路径,https://webpack.docschina.org/loaders/postcss-loader/#postcss-options
  39. }
  40. }
  41. }
  42. },
  43. chainWebpack: (config) => {
  44. config.resolve.alias
  45. .set('@public', convertPath('public/'))
  46. .set('@pc', convertPath('src/packages/pc/'))
  47. .set('@mobile', convertPath('src/packages/mobile/'))
  48. config.plugin('compressionPlugin')
  49. .use(new CompressionPlugin({
  50. test: /\.js$|\.html$|\.css/, // 匹配文件名
  51. threshold: 10240, // 对超过10k的数据压缩
  52. }))
  53. config.plugin('fork-ts-checker')
  54. .use(new ForkTsCheckerWebpackPlugin({
  55. typescript: {
  56. memoryLimit: 4096,
  57. },
  58. }))
  59. },
  60. configureWebpack: (config) => {
  61. const oem = process.env.VUE_APP_OEM
  62. // const manifestPath = oem ? convertPath(oem + 'manifest.json') : convertPath('public/manifest.json')
  63. // const manifestContents = fs.readFileSync(manifestPath, 'utf-8')
  64. // const manifest = JSON.parse(manifestContents)
  65. // console.log(manifest)
  66. if (process.env.NODE_ENV === 'production' && !process.argv.includes('test')) {
  67. const configPath = oem ? convertPath(oem + 'config/appconfig.json') : convertPath('public/config/appconfig.json')
  68. const cfgContents = fs.readFileSync(configPath, 'utf-8')
  69. const cfg = JSON.parse(cfgContents)
  70. // 自动修改版本号
  71. if (process.argv.includes('ver')) {
  72. const arr = cfg.version.split('.').map(Number)
  73. arr[arr.length - 1] += 1 // 版本号自动+1
  74. // 版本号100进1
  75. for (let i = arr.length - 1; i >= 0; i--) {
  76. if (i > 0 && arr[i] > 99) {
  77. arr[i] = 0
  78. if (arr[i - 1] > -1) {
  79. arr[i - 1] += 1
  80. }
  81. }
  82. }
  83. cfg.version = arr.join('.')
  84. cfg.versionCode = (Number(cfg.versionCode) + 1).toString()
  85. }
  86. cfg.appName = process.env.VUE_APP_NAME
  87. cfg.tradeChannel = process.env.VUE_APP_TRADE_CHANNEL
  88. fs.writeFileSync(configPath, JSON.stringify(cfg, null, 2))
  89. console.log(cfg)
  90. }
  91. if (oem) {
  92. // 打包时复制指定目录文件到目标目录
  93. config.plugins.push(new CopyWebpackPlugin({
  94. patterns: [
  95. {
  96. from: convertPath(oem), // 指定目录
  97. to: outputDir, // 目标目录
  98. force: true, // 强制覆盖文件
  99. }
  100. ]
  101. }))
  102. }
  103. }
  104. })
  105. =======
  106. const fs = require('fs')
  107. const path = require('path')
  108. const { defineConfig } = require('@vue/cli-service')
  109. const moment = require('moment')
  110. const CompressionPlugin = require('compression-webpack-plugin')
  111. const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin')
  112. const CopyWebpackPlugin = require('copy-webpack-plugin')
  113. const convertPath = (dir) => path.resolve(__dirname, dir)
  114. const outputDir = convertPath('app/dist') // 打包输出目录
  115. module.exports = defineConfig({
  116. transpileDependencies: [/node_modules/],
  117. productionSourceMap: false, // 打包取消.map
  118. publicPath: './',
  119. outputDir,
  120. pages: {
  121. indexPath: {
  122. entry: process.env.VUE_APP_ROOT + 'main.ts',
  123. template: process.env.VUE_APP_ROOT + 'index.html',
  124. filename: 'index.html',
  125. title: process.env.VUE_APP_NAME,
  126. meta: {
  127. revised: moment(new Date()).format('YYYYMMDDHHmmss') // 打包生成版本号
  128. }
  129. }
  130. },
  131. devServer: {
  132. client: {
  133. overlay: false
  134. }
  135. },
  136. css: {
  137. extract: true, // 是否使用css分离插件 ExtractTextPlugin
  138. sourceMap: false,
  139. loaderOptions: {
  140. postcss: {
  141. postcssOptions: {
  142. config: process.env.VUE_APP_ROOT, // 自定义 postcss.config.js 文件路径,https://webpack.docschina.org/loaders/postcss-loader/#postcss-options
  143. }
  144. }
  145. }
  146. },
  147. chainWebpack: (config) => {
  148. config.resolve.alias
  149. .set('@public', convertPath('public/'))
  150. .set('@pc', convertPath('src/packages/pc/'))
  151. .set('@mobile', convertPath('src/packages/mobile/'))
  152. config.plugin('compressionPlugin')
  153. .use(new CompressionPlugin({
  154. test: /\.js$|\.html$|\.css/, // 匹配文件名
  155. threshold: 10240, // 对超过10k的数据压缩
  156. }))
  157. config.plugin('fork-ts-checker')
  158. .use(new ForkTsCheckerWebpackPlugin({
  159. typescript: {
  160. memoryLimit: 4096,
  161. },
  162. }))
  163. },
  164. configureWebpack: (config) => {
  165. const oem = process.env.VUE_APP_OEM
  166. // const manifestPath = oem ? convertPath(oem + 'manifest.json') : convertPath('public/manifest.json')
  167. // const manifestContents = fs.readFileSync(manifestPath, 'utf-8')
  168. // const manifest = JSON.parse(manifestContents)
  169. // console.log(manifest)
  170. if (process.env.NODE_ENV === 'production' && !process.argv.includes('test')) {
  171. const configPath = oem ? convertPath(oem + 'config/appconfig.json') : convertPath('public/config/appconfig.json')
  172. const cfgContents = fs.readFileSync(configPath, 'utf-8')
  173. const cfg = JSON.parse(cfgContents)
  174. // 自动修改版本号
  175. if (process.argv.includes('ver')) {
  176. const arr = cfg.version.split('.').map(Number)
  177. arr[arr.length - 1] += 1 // 版本号自动+1
  178. // 版本号100进1
  179. for (let i = arr.length - 1; i >= 0; i--) {
  180. if (i > 0 && arr[i] > 99) {
  181. arr[i] = 0
  182. if (arr[i - 1] > -1) {
  183. arr[i - 1] += 1
  184. }
  185. }
  186. }
  187. cfg.version = arr.join('.')
  188. cfg.versionCode = (Number(cfg.versionCode) + 1).toString()
  189. }
  190. cfg.appName = process.env.VUE_APP_NAME
  191. cfg.tradeChannel = process.env.VUE_APP_TRADE_CHANNEL
  192. fs.writeFileSync(configPath, JSON.stringify(cfg, null, 2))
  193. console.log(cfg)
  194. }
  195. if (oem) {
  196. // 打包时复制指定目录文件到目标目录
  197. config.plugins.push(new CopyWebpackPlugin({
  198. patterns: [
  199. {
  200. from: convertPath(oem), // 指定目录
  201. to: outputDir, // 目标目录
  202. force: true, // 强制覆盖文件
  203. }
  204. ]
  205. }))
  206. }
  207. }
  208. })
  209. >>>>>>> 5afce088 (xxxx)