diff --git a/.env.production b/.env.production index 292ec40..370a255 100644 --- a/.env.production +++ b/.env.production @@ -6,4 +6,4 @@ # VITE_YCNC_MERCH_CODE = '100610100019029' # 邮储奶茶活动(正式环境) VITE_BASE_URL = 'https://milk.api.cdlsxd.cn' -VITE_YCNC_MERCH_CODE = '100510102210712' \ No newline at end of file +VITE_YCNC_MERCH_CODE = '100510102294138' \ No newline at end of file diff --git a/README.md b/README.md index d0561a8..4bf3205 100644 --- a/README.md +++ b/README.md @@ -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) ### 各个模块的说明 diff --git a/build.js b/build.js deleted file mode 100644 index 2198f30..0000000 --- a/build.js +++ /dev/null @@ -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 - - - diff --git a/custom.page.js b/custom.page.js index e940aed..67c67e9 100644 --- a/custom.page.js +++ b/custom.page.js @@ -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 \ No newline at end of file +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 diff --git a/vite.config.js b/vite.config.js index b46077b..e3e030b 100644 --- a/vite.config.js +++ b/vite.config.js @@ -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 + }, } }) \ No newline at end of file diff --git a/delete.js b/vite.plugin.js similarity index 100% rename from delete.js rename to vite.plugin.js