-
-
Notifications
You must be signed in to change notification settings - Fork 595
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
91 additions
and
67 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
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import { RawContainerPluginOptions, BuiltinPlugin } from "@rspack/binding"; | ||
import { BuiltinPluginName, RspackBuiltinPlugin } from "../builtin-plugin/base"; | ||
import { | ||
EntryRuntime, | ||
Filename, | ||
LibraryOptions, | ||
getRawEntryRuntime, | ||
getRawLibrary | ||
} from "../config"; | ||
import { isNil } from "../util"; | ||
import { parseOptions } from "../container/options"; | ||
import { Compiler } from "../Compiler"; | ||
|
||
export type ContainerPluginOptions = { | ||
exposes: Exposes; | ||
filename?: Filename; | ||
library?: LibraryOptions; | ||
name: string; | ||
runtime?: EntryRuntime; | ||
shareScope?: string; | ||
}; | ||
export type Exposes = (ExposesItem | ExposesObject)[] | ExposesObject; | ||
export type ExposesItem = string; | ||
export type ExposesItems = ExposesItem[]; | ||
export type ExposesObject = { | ||
[k: string]: ExposesConfig | ExposesItem | ExposesItems; | ||
}; | ||
export type ExposesConfig = { | ||
import: ExposesItem | ExposesItems; | ||
name?: string; | ||
}; | ||
|
||
export class ContainerPlugin extends RspackBuiltinPlugin { | ||
name = BuiltinPluginName.ContainerPlugin; | ||
_options: RawContainerPluginOptions; | ||
_library; | ||
|
||
constructor(options: ContainerPluginOptions) { | ||
super(); | ||
const library = (this._library = options.library || { | ||
type: "var", | ||
name: options.name | ||
}); | ||
const runtime = options.runtime; | ||
this._options = { | ||
name: options.name, | ||
shareScope: options.shareScope || "default", | ||
library: getRawLibrary(library), | ||
runtime: !isNil(runtime) ? getRawEntryRuntime(runtime) : undefined, | ||
filename: options.filename, | ||
exposes: parseOptions( | ||
options.exposes, | ||
item => ({ | ||
import: Array.isArray(item) ? item : [item], | ||
name: undefined | ||
}), | ||
item => ({ | ||
import: Array.isArray(item.import) ? item.import : [item.import], | ||
name: item.name || undefined | ||
}) | ||
).map(([key, r]) => ({ key, ...r })) | ||
}; | ||
} | ||
|
||
raw(compiler: Compiler): BuiltinPlugin { | ||
const library = this._library; | ||
if (!compiler.options.output.enabledLibraryTypes!.includes(library.type)) { | ||
compiler.options.output.enabledLibraryTypes!.push(library.type); | ||
} | ||
return { | ||
name: this.name as any, | ||
options: this._options | ||
}; | ||
} | ||
} |
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
1 change: 0 additions & 1 deletion
1
webpack-test/configCases/container/container-entry/test.filter.js
This file was deleted.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
webpack-test/configCases/container/container-entry/webpack.config.js
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