marketingSaaS-front_ui/custom.page.js

99 lines
3.0 KiB
JavaScript
Raw Normal View History

2024-07-18 14:15:56 +08:00
import fs from 'fs'
import path from 'path'
2024-07-25 10:36:36 +08:00
/**
* 注意打包主模板页面(pages/index)先删掉dis文件夹.gitignore 注释掉dist
* 打包其它模板需要保留dist
2024-07-25 10:36:36 +08:00
*/
2024-07-15 16:52:24 +08:00
const config = {
pages: './src/pages',
2024-09-14 16:22:05 +08:00
// 吉林工行
2024-08-15 11:35:59 +08:00
// pagesInclude: ['jlgh/coupon.vue', 'jlgh/redeem.vue'],
2024-08-14 17:49:03 +08:00
// pagesInclude: ['jlgh/index.vue'],
// pagesInclude: ['jlgh/login.vue'],
2024-09-12 11:21:30 +08:00
// pagesInclude: ['jlgh/orderDetail.vue'],
2024-09-20 09:55:07 +08:00
// 主模版 -- 白板模板
// pagesInclude: ['index'],
2024-09-14 16:22:05 +08:00
// 兴业银行
// pagesInclude: ['xyyh'],
2024-09-20 09:55:07 +08:00
// 云南邮储
2024-09-26 16:30:37 +08:00
// pagesInclude: ['ynyc/login.vue'],
2024-09-20 09:55:07 +08:00
// pagesInclude: ['ynyc/index.vue'],
2024-09-26 16:30:37 +08:00
// 广州移动
// pagesInclude: ['gzyd/login.vue'],
2024-11-04 16:55:41 +08:00
// 实物需求
// pagesInclude: ['physical/login.vue'],
// pagesInclude: ['physical/index.vue'],
// pagesInclude: ['physical/orderDetail.vue'],
pagesInclude: [
'physical/coupon.vue',
'physical/redeem.vue',
'physical/address.vue',
'physical/createAddress.vue',
],
2024-07-15 16:52:24 +08:00
}
2024-09-20 09:55:07 +08:00
export function getPages() {
const srcPath = path.resolve(__dirname, config.pages)
2024-07-18 14:15:56 +08:00
// 所有的模块
const allModule = fs.readdirSync(srcPath)
// 指定的完整模块
2024-09-20 09:55:07 +08:00
const completeModule = config.pagesInclude.filter((item) => item.indexOf('.vue') === -1)
2024-07-18 14:15:56 +08:00
// 需要排除的整个模块
const excludeModule = allModule.filter((item) => !completeModule.includes(item))
// 指定特定页面的模块
2024-09-20 09:55:07 +08:00
const targetpageModule = config.pagesInclude.filter((item) => item.indexOf('.vue') >= 0)
2024-07-18 14:15:56 +08:00
const targetModule = targetpageModule.reduce((acc, cur) => {
const [dir, file] = cur.split('/')
if (Array.isArray(acc[dir])) {
acc[dir].push(file)
} else {
acc[dir] = [file]
}
return acc
}, {})
// 需要排除的特定的页面
const excludePages = []
Object.keys(targetModule).forEach((ele, index) => {
if (excludeModule.includes(ele)) {
excludeModule.splice(excludeModule.indexOf(ele), 1)
}
const targetPages = fs
2024-09-20 09:55:07 +08:00
.readdirSync(path.resolve(__dirname, config.pages, ele))
2024-07-18 14:15:56 +08:00
.filter((element) => element.indexOf('.vue') >= 0)
const targetExclude = targetPages
.filter((elem) => !targetModule[ele].includes(elem))
.map((current) => `${ele}/${current}`)
excludePages.push(...targetExclude)
})
console.log('排除的模块和页面--->', [...excludeModule, ...excludePages])
2024-09-20 09:55:07 +08:00
console.log('打包的模块和页面--->', config.pagesInclude)
2024-07-18 14:15:56 +08:00
return {
exclude: [...excludeModule, ...excludePages],
2024-09-20 09:55:07 +08:00
include: config.pagesInclude,
2024-07-18 14:15:56 +08:00
}
}
2024-09-20 09:55:07 +08:00
export function createOutputDir(pageInfo) {
2024-07-18 14:15:56 +08:00
const _pages = pageInfo.filter((item) => item.indexOf('.vue') > -1)
if (!_pages.length) {
return pageInfo.join('-')
} else {
const temp = _pages.reduce((acc, cur) => {
const [dir, file] = cur.split('/')
if (Array.isArray(acc[dir])) {
acc[dir].push(file)
} else {
acc[dir] = [file]
}
return acc
}, {})
const result = Object.entries(temp)[0]
return `${result[0]}-${result[1].join('-').replace(/.vue/g, '')}`
}
}
2024-09-20 09:55:07 +08:00
export default {
2024-09-14 16:22:05 +08:00
getPages,
2024-09-20 09:55:07 +08:00
createOutputDir,
2024-09-14 16:22:05 +08:00
}