@embeddable.com/sdk-react 2.2.3 → 2.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.esm.js +14 -2
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +14 -2
- package/lib/index.js.map +1 -1
- package/package.json +1 -1
- package/templates/embeddable-entry-point.jsx.template +24 -0
package/lib/index.esm.js
CHANGED
|
@@ -656,13 +656,25 @@ async function runViteBuild(ctx) {
|
|
|
656
656
|
define: { "process.env.NODE_ENV": '"production"' },
|
|
657
657
|
});
|
|
658
658
|
}
|
|
659
|
-
const
|
|
659
|
+
const IMPORT_REPLACE_TOKEN = "{{LAZY_IMPORTS}}";
|
|
660
|
+
const ERROR_FALLBACK_COMPONENT_IMPORT_TOKEN = "{{ERROR_FALLBACK_COMPONENT_IMPORT}}";
|
|
661
|
+
const ERROR_FALLBACK_COMPONENT_TOKEN = "{{ERROR_FALLBACK_COMPONENT}}";
|
|
662
|
+
const ERROR_FALLBACK_COMPONENT_DEFAULT_NAME = "ErrorFallbackComponent";
|
|
660
663
|
async function injectImports(ctx, filesList) {
|
|
661
664
|
const imports = filesList
|
|
662
665
|
.map(([fileName, filePath]) => `\t${fileName}: React.lazy(() => import('./${path.relative(ctx.client.rootDir, filePath)}'))`)
|
|
663
666
|
.join(",\n");
|
|
667
|
+
let errorBoundaryImport = "";
|
|
668
|
+
let errorFallbackComponent = "null";
|
|
669
|
+
if (ctx.client.errorFallbackComponent) {
|
|
670
|
+
errorBoundaryImport = `import ${ERROR_FALLBACK_COMPONENT_DEFAULT_NAME} from './${path.relative(ctx.client.rootDir, ctx.client.errorFallbackComponent)}';`;
|
|
671
|
+
errorFallbackComponent = ERROR_FALLBACK_COMPONENT_DEFAULT_NAME;
|
|
672
|
+
}
|
|
664
673
|
const content = await fs$1.readFile(path.resolve(ctx["sdk-react"].templatesDir, `${ctx["sdk-react"].outputOptions.componentsEntryPointFilename}.template`), "utf8");
|
|
665
|
-
await fs$1.writeFile(path.resolve(ctx.client.rootDir, ctx["sdk-react"].outputOptions.componentsEntryPointFilename), content
|
|
674
|
+
await fs$1.writeFile(path.resolve(ctx.client.rootDir, ctx["sdk-react"].outputOptions.componentsEntryPointFilename), content
|
|
675
|
+
.replace(IMPORT_REPLACE_TOKEN, imports)
|
|
676
|
+
.replace(ERROR_FALLBACK_COMPONENT_IMPORT_TOKEN, errorBoundaryImport)
|
|
677
|
+
.replace(ERROR_FALLBACK_COMPONENT_TOKEN, errorFallbackComponent));
|
|
666
678
|
}
|
|
667
679
|
|
|
668
680
|
var build = async (ctx) => {
|