-
-
Notifications
You must be signed in to change notification settings - Fork 268
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(enhanced): support get public path (#2638)
Co-authored-by: ScriptedAlchemy <zackaryjackson@bytedance.com>
- Loading branch information
1 parent
6838379
commit 88445e7
Showing
18 changed files
with
176 additions
and
33 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,8 @@ | ||
--- | ||
'@module-federation/dts-plugin': patch | ||
'@module-federation/enhanced': patch | ||
'@module-federation/manifest': patch | ||
'@module-federation/sdk': patch | ||
--- | ||
|
||
Support getPublicPath in compiler plugins |
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
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
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
32 changes: 32 additions & 0 deletions
32
packages/enhanced/src/lib/container/runtime/RemoteEntryPlugin.ts
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,32 @@ | ||
import type { Compiler, WebpackPluginInstance } from 'webpack'; | ||
import pBtoa from 'btoa'; | ||
|
||
export class RemoteEntryPlugin implements WebpackPluginInstance { | ||
readonly name = 'VmokRemoteEntryPlugin'; | ||
private _name: string; | ||
private _getPublicPath: string; | ||
|
||
constructor(name: string, getPublicPath: string) { | ||
this._name = name; | ||
this._getPublicPath = getPublicPath; | ||
} | ||
|
||
apply(compiler: Compiler): void { | ||
let code; | ||
if (!this._getPublicPath.startsWith('function')) { | ||
code = `${ | ||
compiler.webpack.RuntimeGlobals.publicPath | ||
} = new Function(${JSON.stringify(this._getPublicPath)})()`; | ||
} else { | ||
code = `(${this._getPublicPath})()`; | ||
} | ||
const base64Code = pBtoa(code); | ||
const dataUrl = `data:text/javascript;base64,${base64Code}`; | ||
|
||
compiler.hooks.afterPlugins.tap('VmokRemoteEntryPlugin', () => { | ||
new compiler.webpack.EntryPlugin(compiler.context, dataUrl, { | ||
name: this._name, | ||
}).apply(compiler); | ||
}); | ||
} | ||
} |
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
Oops, something went wrong.