优化调整插件文件

This commit is contained in:
xiaogang 2024-08-13 14:40:19 +08:00
parent 504853e509
commit fd7f59740f
6 changed files with 49 additions and 59 deletions

View File

@ -6,4 +6,4 @@
# VITE_YCNC_MERCH_CODE = '100610100019029'
# 邮储奶茶活动(正式环境)
VITE_BASE_URL = 'https://milk.api.cdlsxd.cn'
VITE_YCNC_MERCH_CODE = '100510102210712'
VITE_YCNC_MERCH_CODE = '100510102294138'

View File

@ -13,10 +13,8 @@ uniapp的路由文件插件默认自动扫描src/pages下的所有.vue文件
**vite.config.js**
vite打包配置文件主要是一些插件
**custom.pages.js**
指定打包扫描的目录(默认 .src/pages),以及需要打包的模块(例:ycnc)和指定特定模块的特定页面(需要显示指定.vue后缀,例:'ycnc/index.vue')
**build.js**
输出需要排除的模块以及模块的部分页面(这个很少用,必须清楚该模块各页面之间的业务情况再决定)
**delete.js**
指定打包扫描的目录(默认 .src/pages),以及需要打包的模块(例:ycnc)和指定特定模块的特定页面(需要显示指定.vue后缀,例:'ycnc/index.vue')
**vite.plugin.js**
打包后针对static拷贝多余的文件再删除的插件脚本(vite使用的详见vite.config.js)
### 各个模块的说明

View File

@ -1,49 +0,0 @@
import fs from 'fs'
import path from 'path'
import config from './custom.page.js'
const { pages, pagesInclude } = config
const getPages = () => {
const srcPath = path.resolve(__dirname, pages)
//所有的模块
const allModule = fs.readdirSync(srcPath);
// console.log('allModule',allModule);
//指定的完整模块
const completeModule = pagesInclude.filter(item => item.indexOf('.vue') === -1)
// console.log('completeModule',completeModule);
//需要排除的整个模块
const excludeModule = allModule.filter(item => !completeModule.includes(item))
// console.log('excludeModule',excludeModule);
//指定特定页面的模块
const targetpageModule = pagesInclude.filter(item => item.indexOf('.vue') >= 0)
// console.log(targetpageModule);
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.readdirSync(path.resolve(__dirname,pages,ele)).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]);
return {
exclude:[...excludeModule,...excludePages],
}
}
export default getPages

View File

@ -1,7 +1,46 @@
import fs from 'fs'
import path from 'path'
const config = {
pages:'./src/pages',
pagesInclude:['ycnc']
}
const { pages, pagesInclude } = config
export default config
const getPages = () => {
const srcPath = path.resolve(__dirname, pages)
//所有的模块
const allModule = fs.readdirSync(srcPath);
//指定的完整模块
const completeModule = pagesInclude.filter(item => item.indexOf('.vue') === -1)
//需要排除的整个模块
const excludeModule = allModule.filter(item => !completeModule.includes(item))
//指定特定页面的模块
const targetpageModule = pagesInclude.filter(item => item.indexOf('.vue') >= 0)
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.readdirSync(path.resolve(__dirname,pages,ele)).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]);
return {
exclude:[...excludeModule,...excludePages],
}
}
export default getPages

View File

@ -4,13 +4,12 @@ import UniPages from '@uni-helper/vite-plugin-uni-pages'
import UnoCSS from 'unocss/vite'
import zipPack from "vite-plugin-zip-pack"
import dayjs from "dayjs";
import vitePluginRemoveDir from './delete'; // 自己写的删除插件
import vitePluginRemoveDir from './vite.plugin'; // 自己写的删除插件
import getPages from './build'
import getPages from './custom.page'
const {exclude} = getPages();
const excludeStaticModule = exclude.filter(item => item.indexOf('.vue') === -1)
// const timeStringNow = dayjs().format("YYYY-MM-DD HH-mm-ss")
const timeStringNow = dayjs().format("MM-DD HH-mm-ss")
@ -34,6 +33,9 @@ export default defineConfig(({ command, mode }) => {
outFileName: `${UNI_PLATFORM}-${timeStringNow}.zip`, //文件名不能包含\/:*?"<>|
pathPrefix: ''
}),
]
],
esbuild: {
drop: ["console", "debugger"], //打包去掉console,debugger
},
}
})