优化调整插件文件
This commit is contained in:
parent
504853e509
commit
fd7f59740f
|
@ -6,4 +6,4 @@
|
||||||
# VITE_YCNC_MERCH_CODE = '100610100019029'
|
# VITE_YCNC_MERCH_CODE = '100610100019029'
|
||||||
# 邮储奶茶活动(正式环境)
|
# 邮储奶茶活动(正式环境)
|
||||||
VITE_BASE_URL = 'https://milk.api.cdlsxd.cn'
|
VITE_BASE_URL = 'https://milk.api.cdlsxd.cn'
|
||||||
VITE_YCNC_MERCH_CODE = '100510102210712'
|
VITE_YCNC_MERCH_CODE = '100510102294138'
|
|
@ -14,9 +14,7 @@ uniapp的路由文件插件,默认自动扫描src/pages下的所有.vue文件
|
||||||
vite打包配置文件,主要是一些插件
|
vite打包配置文件,主要是一些插件
|
||||||
**custom.pages.js**
|
**custom.pages.js**
|
||||||
指定打包扫描的目录(默认 .src/pages),以及需要打包的模块(例:ycnc)和指定特定模块的特定页面(需要显示指定.vue后缀,例:'ycnc/index.vue')
|
指定打包扫描的目录(默认 .src/pages),以及需要打包的模块(例:ycnc)和指定特定模块的特定页面(需要显示指定.vue后缀,例:'ycnc/index.vue')
|
||||||
**build.js**
|
**vite.plugin.js**
|
||||||
输出需要排除的模块以及模块的部分页面(这个很少用,必须清楚该模块各页面之间的业务情况再决定)
|
|
||||||
**delete.js**
|
|
||||||
打包后针对static拷贝多余的文件,再删除的插件脚本(vite使用的,详见vite.config.js)
|
打包后针对static拷贝多余的文件,再删除的插件脚本(vite使用的,详见vite.config.js)
|
||||||
|
|
||||||
### 各个模块的说明
|
### 各个模块的说明
|
||||||
|
|
49
build.js
49
build.js
|
@ -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
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,46 @@
|
||||||
|
|
||||||
|
import fs from 'fs'
|
||||||
|
import path from 'path'
|
||||||
|
|
||||||
const config = {
|
const config = {
|
||||||
pages:'./src/pages',
|
pages:'./src/pages',
|
||||||
pagesInclude:['ycnc']
|
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
|
||||||
|
|
|
@ -4,13 +4,12 @@ import UniPages from '@uni-helper/vite-plugin-uni-pages'
|
||||||
import UnoCSS from 'unocss/vite'
|
import UnoCSS from 'unocss/vite'
|
||||||
import zipPack from "vite-plugin-zip-pack"
|
import zipPack from "vite-plugin-zip-pack"
|
||||||
import dayjs from "dayjs";
|
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 {exclude} = getPages();
|
||||||
const excludeStaticModule = exclude.filter(item => item.indexOf('.vue') === -1)
|
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")
|
const timeStringNow = dayjs().format("MM-DD HH-mm-ss")
|
||||||
|
|
||||||
|
|
||||||
|
@ -34,6 +33,9 @@ export default defineConfig(({ command, mode }) => {
|
||||||
outFileName: `${UNI_PLATFORM}-${timeStringNow}.zip`, //文件名不能包含\/:*?"<>|
|
outFileName: `${UNI_PLATFORM}-${timeStringNow}.zip`, //文件名不能包含\/:*?"<>|
|
||||||
pathPrefix: ''
|
pathPrefix: ''
|
||||||
}),
|
}),
|
||||||
]
|
],
|
||||||
|
esbuild: {
|
||||||
|
drop: ["console", "debugger"], //打包去掉console,debugger
|
||||||
|
},
|
||||||
}
|
}
|
||||||
})
|
})
|
Loading…
Reference in New Issue