8000 feat: WebIndexPlugin - Possibility to shape how bundles are emitted (… · fuse-box/fuse-box@f1ac7d5 · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
This repository was archived by the owner on Jun 20, 2023. It is now read-only.

Commit f1ac7d5

Browse files
tomitrescaknchanged
authored andcommitted
feat: WebIndexPlugin - Possibility to shape how bundles are emitted (#1144)
I have a scenario in which I am only loading JS if I am on a specific browser, supporting ES6 with async await. For all other browsers I am disabling the app. It is a corporate app so don't judge. I can now do: ```html <script type="text/javascript"> function isGeneratorSupported() { try { eval('(function*(){})()'); return true; } catch (err) { return false; } } let c = document.getElementById('hiddenContent'); if (!isGeneratorSupported() || /MSIE \d|Trident.*rv:/.test(navigator.userAgent)) { c.style.display = 'block'; } else { $bundles } </script> ``` and ```js WebIndexPlugin({ template: 'src/client/index.html', emitBundles: bundles => bundles .map(b => `document.write('<script type="text/javascript" src="${b}"><\\/script>');`) .join('\n') }), ```
1 parent 600b204 commit f1ac7d5

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/plugins/WebIndexPlugin.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export interface IndexPluginOptions {
2121
async?: boolean;
2222
pre?: { relType: 'fetch' | 'load' };
2323
resolve?: { (output: UserOutput): string };
24+
emitBundles?: (bundles: string[]) => string;
2425
}
2526
export class WebIndexPluginClass implements Plugin {
2627
constructor(public opts?: IndexPluginOptions) {
@@ -83,9 +84,9 @@ $bundles
8384
}
8485
}
8586

86-
let jsTags = bundlePaths.map(bundle =>
87-
`<script ${this.opts.async ? 'async' : ''} type="text/javascript" src="${bundle}"></script>`
88-
).join("\n");
87+
let jsTags 5892 = this.opts.emitBundles
88+
? this.opts.emitBundles(bundlePaths)
89+
: bundlePaths.map(bundle => `<script ${this.opts.async ? 'async' : ''} type="text/javascript" src="${bundle}"></script>`).join('\n');
8990

9091
let preloadTags;
9192
if (this.opts.pre) {

0 commit comments

Comments
 (0)
0