webpack5使用内置缓存,页面和组件的json文件的usingComponents为空
- Dominant language
- JavaScript
- Stars
- 41.6k
- Forks
- 3.7k
- Avg merge
- 7h 6m
- Merged PRs (30d)
- 6
Description
### 项目信息
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为空**的状态,文件内容如下
上述中使用过组件,但是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缓存进行编译
Contributor guide
Assessment
This issue has not been assessed yet.