Skip to content

Commit

Permalink
chore(app-tools): add RouterPlugin name (#4667)
Browse files Browse the repository at this point in the history
* chore(app-tools): add RouterPlugin name

* chore(app-tools): chain id forward compatible
  • Loading branch information
2heal1 authored Sep 18, 2023
1 parent 0988b12 commit 9dd3151
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 2 deletions.
7 changes: 7 additions & 0 deletions .changeset/hot-grapes-shop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@modern-js/app-tools': patch
'@modern-js/utils': patch
---

chore(app-tools): add RouterPlugin name
chore(app-tools): 增加 RouterPlugin 名称
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,12 @@ export const builderPluginAdapterSSR = <B extends Bundler>(
const builderConfig = api.getNormalizedConfig();
const { normalizedConfig } = options;

applyRouterPlugin(chain, options, HtmlBundlerPlugin);
applyRouterPlugin(
chain,
CHAIN_ID.PLUGIN.ROUTER_MANIFEST,
options,
HtmlBundlerPlugin,
);
if (isSSR(normalizedConfig)) {
await applySSRLoaderEntry(chain, options, isServer);
applySSRDataLoader(chain, options);
Expand Down Expand Up @@ -114,6 +119,7 @@ function applyAsyncChunkHtmlPlugin({

function applyRouterPlugin<B extends Bundler>(
chain: BundlerChain,
pluginName: string,
options: Readonly<BuilderOptions<B>>,
HtmlBundlerPlugin: typeof HtmlWebpackPlugin,
) {
Expand All @@ -128,7 +134,7 @@ function applyRouterPlugin<B extends Bundler>(
const workerSSR = Boolean(normalizedConfig.deploy.worker?.ssr);

if (existNestedRoutes || routerManifest || workerSSR) {
chain.plugin('route-plugin').use(RouterPlugin, [
chain.plugin(pluginName).use(RouterPlugin, [
{
HtmlBundlerPlugin,
enableInlineRouteManifests:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ const generateContentHash = (content: string) => {
};

export class RouterPlugin {
readonly name: string = 'RouterPlugin';

private HtmlBundlerPlugin: typeof HtmlWebpackPlugin;

private enableInlineRouteManifests: boolean;
Expand Down
2 changes: 2 additions & 0 deletions packages/toolkit/utils/src/cli/constants/chainId.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,8 @@ export const CHAIN_ID = {
HTML_ASYNC_CHUNK: 'html-async-chunk',
/** SWC_POLYFILL_CHECKER */
SWC_POLYFILL_CHECKER: 'swc-polyfill-checker-plugin',
/** RouterPlugin */
ROUTER_MANIFEST: 'route-plugin',
},
/** Predefined minimizers */
MINIMIZER: {
Expand Down

0 comments on commit 9dd3151

Please sign in to comment.