diff --git a/README.md b/README.md index c777584..2f0d631 100644 --- a/README.md +++ b/README.md @@ -267,6 +267,8 @@ export default { external:[], // 💡 扩展vite.config.js的rollupOptions.output.manualChunks设置项,!!!该项,2.0.0更换为vite5之后,该项已经失效 manualChunks:{}, + // 💡 扩展vite.config.optimizeDeps.include,适当的讲内部的依赖预渲染可以提高项目初始化速度 + optimizeInclude:[] } ``` diff --git a/packages/elementui/config.js b/packages/elementui/config.js index 4c1bbc0..a1e840a 100644 --- a/packages/elementui/config.js +++ b/packages/elementui/config.js @@ -17,7 +17,6 @@ export default { ], // 💡 外部化的包 external:[], - // 💡 扩展vite.config.js的rollupOptions.output.manualChunks设置项 - manualChunks:{'elementui': ['element-ui','@vitescv/elementui']}, + optimizeInclude:['@vitescv/elementui/components'] } diff --git a/src/moduleLib.js b/src/moduleLib.js index e31219b..9527141 100644 --- a/src/moduleLib.js +++ b/src/moduleLib.js @@ -24,7 +24,6 @@ function initModuleConfigs(){ UIResolvers:[], alias: {'vue':require.resolve('vue')}, optimizeInclude:[], - optimizeExclude:[], }) } /** @@ -45,16 +44,17 @@ export async function initModules(options){ moduleConfigs.linkModulePaths.push(resolve(process.env.__VITESCVROOT,'node_modules')) } for (let moduleName in moduleOptions) { - let isPackage = !existsSync(resolve(process.env.__PROJECTROOT,moduleName)) //是否安装的包,而不是内部文件 let moduleIndex = normalizePath(require.resolve(moduleName,{ paths:[process.env.__PROJECTROOT] })) + let isPackage = !existsSync(resolve(process.env.__PROJECTROOT,moduleName)) //是否安装外部的包,而不是内部文件 + let isLink = isPackage && !moduleIndex.startsWith(process.env.__PROJECTROOT) //是否用npm link安装的项目外部测试包 if(!moduleIndex){ console.error(`[vitescv] [${moduleName}] not exit`) continue } try{ - let dir = getModuleRootPathByIndex(moduleIndex,moduleName,isPackage,!moduleIndex.startsWith(process.env.__PROJECTROOT)) + let dir = getModuleRootPathByIndex(moduleIndex,moduleName,isPackage,isLink) let moduleInfo = { idx:moduleMap.size, origin:moduleName, @@ -79,11 +79,6 @@ export async function initModules(options){ if(moduleInfo.isPackage && !moduleInfo.source.startsWith(process.env.__PROJECTROOT)){ moduleConfigs.linkModulePaths.push(join(moduleInfo.dir,'node_modules')) } - - if(isPackage){ - moduleConfigs.optimizeInclude.push(moduleName) - } - moduleMap.set(moduleIndex,moduleInfo) }catch(e){ console.debug(e) diff --git a/vite.config.js b/vite.config.js index a45b701..e44b34f 100644 --- a/vite.config.js +++ b/vite.config.js @@ -20,7 +20,7 @@ export default function(userConfig){ const unpluginvModules = unpluginModules() const isProduction = mode == "production" - console.log(moduleConfigs) + // console.log(moduleConfigs) // const moduleChunks = Object.assign({ // 'vue': ['vue'], // // 'vrouter': ['vue-router','virtual:router-routes'], @@ -155,9 +155,9 @@ export default function(userConfig){ //💡 除了input(index.html)文件来检测需要预构建的依赖项外,指定其他入口文件检索 // entries:[], //💡 默认情况下,不在 node_modules 中的,链接的包不会被预构建。使用此选项可强制预构建链接的包。 - // include:Config.optimizeInclude, + include:Config.optimizeInclude, // include:['element-ui/lib/*.js'], - // include:['@vitescv/elementui > element-ui'], + // include:['@vitescv/elementui > element-ui/lib/*.js'], // 💡 排除的预构建,vitescv/app包含虚拟模块,预构建的时候并不存在,会报错 // exclude:['vitescv/app'], //💡 设置为 true 可以强制依赖预构建,而忽略之前已经缓存过的、已经优化过的依赖。