metro.common.config.js 949 B

1234567891011121314151617181920212223242526272829303132333435
  1. const { hasBuildInfo, writeBuildInfo, clean } = require('./build.js');
  2. const {mergeConfig, getDefaultConfig} = require('@react-native/metro-config');
  3. function createModuleIdFactory() {
  4. const fileToIdMap = new Map();
  5. let nextId = 0;
  6. clean('./config/bundleCommonInfo.json');
  7. // 如果是业务 模块请以 10000000 来自增命名
  8. return (path) => {
  9. let id = fileToIdMap.get(path);
  10. if (typeof id !== 'number') {
  11. id = nextId++;
  12. fileToIdMap.set(path, id);
  13. !hasBuildInfo('./config/bundleCommonInfo.json', path) &&
  14. writeBuildInfo(
  15. './config/bundleCommonInfo.json',
  16. path,
  17. fileToIdMap.get(path)
  18. );
  19. }
  20. return id;
  21. };
  22. }
  23. const config = {
  24. serializer: {
  25. createModuleIdFactory: createModuleIdFactory, // 给 bundle 一个id 避免冲突 cli 源码中这个id 是从1 开始 自增的
  26. },
  27. };
  28. module.exports = mergeConfig(getDefaultConfig(__dirname), config);