|
|
@@ -1,15 +1,19 @@
|
|
|
-const { resolve } = require('path')
|
|
|
+const fs = require('fs')
|
|
|
+const path = require('path')
|
|
|
const { defineConfig } = require('@vue/cli-service')
|
|
|
const moment = require('moment')
|
|
|
const CompressionPlugin = require('compression-webpack-plugin')
|
|
|
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin')
|
|
|
const CopyWebpackPlugin = require('copy-webpack-plugin')
|
|
|
|
|
|
+const convertPath = (dir) => path.resolve(__dirname, dir)
|
|
|
+const outputDir = convertPath('app/dist') // 打包输出目录
|
|
|
+
|
|
|
module.exports = defineConfig({
|
|
|
transpileDependencies: [/node_modules/],
|
|
|
productionSourceMap: false, // 打包取消.map
|
|
|
publicPath: './',
|
|
|
- outputDir: './app/dist',
|
|
|
+ outputDir,
|
|
|
pages: {
|
|
|
indexPath: {
|
|
|
entry: process.env.VUE_APP_ROOT + 'main.ts',
|
|
|
@@ -39,8 +43,8 @@ module.exports = defineConfig({
|
|
|
},
|
|
|
chainWebpack: (config) => {
|
|
|
config.resolve.alias
|
|
|
- .set('@pc', resolve(__dirname, 'src/packages/pc/'))
|
|
|
- .set('@mobile', resolve(__dirname, 'src/packages/mobile/'))
|
|
|
+ .set('@pc', convertPath('src/packages/pc/'))
|
|
|
+ .set('@mobile', convertPath('src/packages/mobile/'))
|
|
|
|
|
|
config.plugin('compressionPlugin')
|
|
|
.use(new CompressionPlugin({
|
|
|
@@ -57,13 +61,44 @@ module.exports = defineConfig({
|
|
|
},
|
|
|
configureWebpack: (config) => {
|
|
|
const oem = process.env.VUE_APP_OEM
|
|
|
+
|
|
|
+ // const manifestPath = oem ? convertPath(oem + 'manifest.json') : convertPath('public/manifest.json')
|
|
|
+ // const manifestContents = fs.readFileSync(manifestPath, 'utf-8')
|
|
|
+ // const manifest = JSON.parse(manifestContents)
|
|
|
+ // console.log(manifest)
|
|
|
+
|
|
|
+
|
|
|
+ // 打包自动修改版本号
|
|
|
+ if (process.env.NODE_ENV === 'production') {
|
|
|
+ const configPath = oem ? convertPath(oem + 'config/appconfig.json') : convertPath('public/config/appconfig.json')
|
|
|
+ const cfgContents = fs.readFileSync(configPath, 'utf-8')
|
|
|
+ const cfg = JSON.parse(cfgContents)
|
|
|
+
|
|
|
+ const arr = cfg.version.split('.').map(Number)
|
|
|
+ arr[arr.length - 1] += 1 // 版本号自动+1
|
|
|
+
|
|
|
+ // 版本号100进1
|
|
|
+ for (let i = arr.length - 1; i >= 0; i--) {
|
|
|
+ if (i > 0 && arr[i] > 99) {
|
|
|
+ arr[i] = 0
|
|
|
+ if (arr[i - 1] > -1) {
|
|
|
+ arr[i - 1] += 1
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ cfg.version = arr.join('.')
|
|
|
+ cfg.versionCode = (Number(cfg.versionCode) + 1).toString()
|
|
|
+ fs.writeFileSync(configPath, JSON.stringify(cfg, null, 2))
|
|
|
+ }
|
|
|
+
|
|
|
if (oem) {
|
|
|
// 打包时复制指定目录文件到目标目录
|
|
|
config.plugins.push(new CopyWebpackPlugin({
|
|
|
patterns: [
|
|
|
{
|
|
|
- from: resolve(__dirname, oem), // 指定目录
|
|
|
- to: resolve(__dirname, './app/dist'), // 目标目录
|
|
|
+ from: convertPath(oem), // 指定目录
|
|
|
+ to: outputDir, // 目标目录
|
|
|
force: true, // 强制覆盖文件
|
|
|
}
|
|
|
]
|