Skip to content
This repository has been archived by the owner on Mar 7, 2024. It is now read-only.

Commit

Permalink
fix(cli): 修复生产环境生命周期和自定义组件可能无效的问题
Browse files Browse the repository at this point in the history
fix #905
fix #904
  • Loading branch information
Darmody committed May 8, 2020
1 parent 1935ddd commit 489cf75
Showing 1 changed file with 28 additions and 4 deletions.
32 changes: 28 additions & 4 deletions packages/remax-cli/src/build/utils/modules.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,43 @@
function getModuleResource(module: any) {
if (!module) {
return '';
}

// 跳过 css 模块
if (module.constructor.name === 'CssModule') {
return '';
}

// TODO: 针对不同类型的 module 做处理

return module.resource || module.rootModule?.resource;
}

function getModule(module: any, modules: string[]): string[] {
const resource = getModuleResource(module);

if (!resource) {
return [];
}

return Array.from(
new Set([
module.resource,
resource,
...(module.dependencies as any[]).reduce<string[]>((acc, d) => {
const newModules = [...acc, ...modules];
const module = d.module || d.originModule;

const resource = getModuleResource(module);

if (!d.module?.resource) {
if (!resource) {
return acc;
}

if (newModules.includes(d.module?.resource)) {
if (newModules.includes(resource)) {
return acc;
}

return [...acc, d.module.resource, ...getModule(d.module, [...newModules, d.module.resource])];
return [...acc, resource, ...getModule(module, [...newModules, resource])];
}, []),
])
);
Expand Down

1 comment on commit 489cf75

@vercel
Copy link

@vercel vercel bot commented on 489cf75 May 8, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.