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

[NextJS] Use .dynamic instead of .module for lazy loading modules #730

Merged
merged 3 commits into from
Jun 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions samples/nextjs/scripts/templates/component-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ export interface ComponentFile {
componentName: string;
}

const isLazyLoadingModule = (componentPath: string) => componentPath.includes('.module');
const isLazyLoadingModule = (componentPath: string) => componentPath.includes('.dynamic');

const removeModuleNameEnding = (moduleName: string) => moduleName.replace(/\.?module$/i, '');
const removeDynamicModuleNameEnding = (moduleName: string) =>
moduleName.replace(/\.?dynamic$/i, '');

/**
* Generates the contents of the component factory file using a predefined string template.
Expand All @@ -26,7 +27,7 @@ import dynamic from 'next/dynamic'
${components
.map((component) => {
if (isLazyLoadingModule(component.path)) {
const moduleName = removeModuleNameEnding(component.moduleName);
const moduleName = removeDynamicModuleNameEnding(component.moduleName);
return `const ${moduleName} = {
module: () => import('${component.path}'),
element: () => dynamic(${moduleName}.module)
Expand All @@ -43,11 +44,11 @@ ${components
(component) =>
`components.set('${
isLazyLoadingModule(component.path)
? removeModuleNameEnding(component.componentName)
? removeDynamicModuleNameEnding(component.componentName)
: component.componentName
}', ${
isLazyLoadingModule(component.path)
? removeModuleNameEnding(component.moduleName)
? removeDynamicModuleNameEnding(component.moduleName)
: component.moduleName
});`
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
AppRoute,
Item,
GraphQlConnectedDemo as GrapQLConnectedDemoDatasource,
} from './GraphQL-ConnectedDemo.module.graphql';
} from './GraphQL-ConnectedDemo.dynamic.graphql';
import { StyleguideComponentProps } from 'lib/component-props';
import config from 'temp/config';

Expand Down