Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

webpack5使用内置缓存,页面和组件的json文件的usingComponents为空 #5157

Open
thecoolbb opened this issue Sep 23, 2024 · 0 comments

Comments

@thecoolbb
Copy link

thecoolbb commented Sep 23, 2024

项目信息

dcloudio版本:2.0.2-4010520240507001
项目类型:mp-weixin
vue.config.js配置:

configureWebpack: {
    cache: {
      type: 'filesystem',
      // cacheDirectory: path.resolve(__dirname, '.temp_cache'),
      profile: true,
    },
}

使用webpack的文件缓存

问题描述

当使用webpack5的内置文件缓存时,会出现usingComponents为空的状态,文件内容如下
企业微信截图_ec079492-1f1c-4cfa-89ec-144466034435
上述中使用过组件,但是usingComponent为空

问题相关调研

当使用webpack5的内置缓存时会执行webpack/lib/Compilation.js

_buildModule(module, callback) {
		module.needBuild(
			{
				compilation: this,
				fileSystemInfo: this.fileSystemInfo,
				valueCacheVersions: this.valueCacheVersions
			},
			(err, needBuild) => {
				if (err) return callback(err);
				if (!needBuild) {
                                 }

                        }
               )
} 

上述中因为使用内置缓存,所以needBuild会为false,导致会不会触发@dcloudio/webpack-uni-mp-loader/lib/script-new.js的loader
所以不会触发下面的代码逻辑


components.forEach(({
      name,
      source
    }) => {
      usingComponents[name] = `/${source}`
    })
updateUsingComponents(resourcePath, usingComponents, type, content)

上述逻辑是识别内部使用到的组件,将组件生成usingComponents更新json对象
而jsonFile在内置的@dcloudio/uni-cli-shared/lib/cache.js中存储json对象
let jsonFileMap = new Map()
因为没有将这个字段在webpack的打包配置中进行缓存,导致打包中json对象的usingComponent字段会为空。
而webpack缓存不会触发loader,所以也不会更新json对象的usingComponent字段。
导致最终写入json文件的时候usingComponent字段不存在。
如果上述有逻辑理解问题可以指明

诉求

支持使用webpack5缓存进行编译

@thecoolbb thecoolbb changed the title webpack5使用内置缓存,组件的json文件的usingComponents为空 webpack5使用内置缓存,页面和组件的json文件的usingComponents为空 Sep 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants