mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-09-24 09:49:46 +02:00
build(esbuild): support multiple IIFE packages
Support multiple IIFE packages by namespacing all of them into a `globalThis.__esbuild_esm_mermaid_nm` object.
This commit is contained in:
@@ -58,6 +58,7 @@ export const getBuildConfig = (options: MermaidBuildOptions): BuildOptions => {
|
|||||||
format,
|
format,
|
||||||
minify,
|
minify,
|
||||||
options: { name, file, packageName },
|
options: { name, file, packageName },
|
||||||
|
globalName = 'mermaid',
|
||||||
} = options;
|
} = options;
|
||||||
const external: string[] = ['require', 'fs', 'path'];
|
const external: string[] = ['require', 'fs', 'path'];
|
||||||
const outFileName = getFileName(name, options);
|
const outFileName = getFileName(name, options);
|
||||||
@@ -68,6 +69,7 @@ export const getBuildConfig = (options: MermaidBuildOptions): BuildOptions => {
|
|||||||
},
|
},
|
||||||
metafile,
|
metafile,
|
||||||
minify,
|
minify,
|
||||||
|
globalName,
|
||||||
logLevel: 'info',
|
logLevel: 'info',
|
||||||
chunkNames: `chunks/${outFileName}/[name]-[hash]`,
|
chunkNames: `chunks/${outFileName}/[name]-[hash]`,
|
||||||
define: {
|
define: {
|
||||||
@@ -89,11 +91,12 @@ export const getBuildConfig = (options: MermaidBuildOptions): BuildOptions => {
|
|||||||
if (format === 'iife') {
|
if (format === 'iife') {
|
||||||
output.format = 'iife';
|
output.format = 'iife';
|
||||||
output.splitting = false;
|
output.splitting = false;
|
||||||
output.globalName = '__esbuild_esm_mermaid';
|
const originalGlobalName = output.globalName ?? 'mermaid';
|
||||||
|
output.globalName = `__esbuild_esm_mermaid_nm[${JSON.stringify(originalGlobalName)}]`;
|
||||||
// Workaround for removing the .default access in esbuild IIFE.
|
// Workaround for removing the .default access in esbuild IIFE.
|
||||||
// https://github.com/mermaid-js/mermaid/pull/4109#discussion_r1292317396
|
// https://github.com/mermaid-js/mermaid/pull/4109#discussion_r1292317396
|
||||||
output.footer = {
|
output.footer = {
|
||||||
js: 'globalThis.mermaid = globalThis.__esbuild_esm_mermaid.default;',
|
js: `globalThis[${JSON.stringify(originalGlobalName)}] = globalThis.${output.globalName}.default;`,
|
||||||
};
|
};
|
||||||
output.outExtension = { '.js': '.js' };
|
output.outExtension = { '.js': '.js' };
|
||||||
} else {
|
} else {
|
||||||
|
Reference in New Issue
Block a user