Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(build): Add
mermaidRendererPlugin.js
- Loading branch information
1 parent
92a979f
commit a64a176
Showing
5 changed files
with
59 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import esbuild from "esbuild"; | ||
import process from "process"; | ||
|
||
export const mermaidRendererPlugin = { | ||
name: 'mermaidRendererPlugin', | ||
setup(build) { | ||
build.onResolve({ filter: /mermaid_renderer\.esbuild$/ }, args => { | ||
return { | ||
watchFiles: ['src/mermaid_renderer.js'], | ||
path: args.path, | ||
namespace: 'mermaid-binary', | ||
} | ||
}); | ||
build.onLoad({ filter: /mermaid_renderer\.esbuild$/, namespace: 'mermaid-binary' }, async (args) => { | ||
const result = await esbuild.build({ | ||
entryPoints: ['src/mermaid_renderer.js'], | ||
bundle: true, | ||
format: 'cjs', | ||
target: 'chrome106', | ||
logLevel: 'info', | ||
sourcemap: false, | ||
treeShaking: true, | ||
write: false, | ||
mainFields: ['module', 'main'], | ||
minify: true, | ||
}).catch(() => process.exit(1)); | ||
|
||
const fileContents = ` | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<title>Mermaid Chart</title> | ||
</head> | ||
<body> | ||
<div id="graphDiv"></div> | ||
<script type="text/javascript"> | ||
${result.outputFiles[0].text} | ||
</script> | ||
</body> | ||
</html> | ||
`; | ||
|
||
return { | ||
contents: fileContents, | ||
loader: 'binary', | ||
} | ||
}) | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters