Skip to content

Commit

Permalink
open optimizeInclude config for module again, and fixed @vitescv/elem…
Browse files Browse the repository at this point in the history
…entui optimize reload by first access
  • Loading branch information
cczw2010 committed Jan 19, 2024
1 parent 225339f commit 4f7459c
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 13 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,8 @@ export default {
external:[],
// 💡 扩展vite.config.js的rollupOptions.output.manualChunks设置项,!!!该项,2.0.0更换为vite5之后,该项已经失效
manualChunks:{},
// 💡 扩展vite.config.optimizeDeps.include,适当的讲内部的依赖预渲染可以提高项目初始化速度
optimizeInclude:[]
}

```
Expand Down
3 changes: 1 addition & 2 deletions packages/elementui/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ export default {
],
// 💡 外部化的包
external:[],
// 💡 扩展vite.config.js的rollupOptions.output.manualChunks设置项
manualChunks:{'elementui': ['element-ui','@vitescv/elementui']},
optimizeInclude:['@vitescv/elementui/components']
}

11 changes: 3 additions & 8 deletions src/moduleLib.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ function initModuleConfigs(){
UIResolvers:[],
alias: {'vue':require.resolve('vue')},
optimizeInclude:[],
optimizeExclude:[],
})
}
/**
Expand All @@ -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,
Expand All @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand Down Expand Up @@ -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 可以强制依赖预构建,而忽略之前已经缓存过的、已经优化过的依赖。
Expand Down

0 comments on commit 4f7459c

Please sign in to comment.