From 61625d4cc1d3e92f9a716fc3a3bb0fae37511ba7 Mon Sep 17 00:00:00 2001 From: Hanric Date: Fri, 13 Dec 2024 11:26:24 +0800 Subject: [PATCH] fix(rspack): import plugin from sub path (#3349) Co-authored-by: Zack Jackson <25274700+ScriptedAlchemy@users.noreply.github.com> --- .changeset/six-yaks-teach.md | 5 +++++ packages/enhanced/src/rspack.ts | 2 +- packages/rspack/package.json | 8 ++++++++ packages/rspack/rollup.config.js | 5 +++++ packages/rspack/src/ModuleFederationPlugin.ts | 2 +- 5 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 .changeset/six-yaks-teach.md diff --git a/.changeset/six-yaks-teach.md b/.changeset/six-yaks-teach.md new file mode 100644 index 0000000000..9faee34875 --- /dev/null +++ b/.changeset/six-yaks-teach.md @@ -0,0 +1,5 @@ +--- +'@module-federation/rspack': patch +--- + +fix(rspack): import plugin from sub path diff --git a/packages/enhanced/src/rspack.ts b/packages/enhanced/src/rspack.ts index 7e5f44c7e6..98e64b3906 100644 --- a/packages/enhanced/src/rspack.ts +++ b/packages/enhanced/src/rspack.ts @@ -1 +1 @@ -export { ModuleFederationPlugin } from '@module-federation/rspack'; +export { ModuleFederationPlugin } from '@module-federation/rspack/plugin'; diff --git a/packages/rspack/package.json b/packages/rspack/package.json index 1d4657fe60..09bd7cb0f4 100644 --- a/packages/rspack/package.json +++ b/packages/rspack/package.json @@ -39,12 +39,20 @@ "import": "./dist/index.esm.js", "require": "./dist/index.cjs.js", "types": "./dist/index.cjs.d.ts" + }, + "./plugin": { + "types": "./dist/plugin.cjs.d.ts", + "import": "./dist/plugin.esm.mjs", + "require": "./dist/plugin.cjs.js" } }, "typesVersions": { "*": { ".": [ "./dist/index.cjs.d.ts" + ], + "plugin": [ + "./dist/plugin.cjs.d.ts" ] } }, diff --git a/packages/rspack/rollup.config.js b/packages/rspack/rollup.config.js index 529f337f44..bb37e988aa 100644 --- a/packages/rspack/rollup.config.js +++ b/packages/rspack/rollup.config.js @@ -1,9 +1,14 @@ const copy = require('rollup-plugin-copy'); const replace = require('@rollup/plugin-replace'); +const path = require('path'); module.exports = (rollupConfig, projectOptions) => { const pkg = require('./package.json'); + rollupConfig.input['plugin'] = path.resolve( + process.cwd(), + './packages/rspack/src/ModuleFederationPlugin.ts', + ); rollupConfig.plugins.push( replace({ __VERSION__: JSON.stringify(pkg.version), diff --git a/packages/rspack/src/ModuleFederationPlugin.ts b/packages/rspack/src/ModuleFederationPlugin.ts index e0f87411bb..b8344efd6c 100644 --- a/packages/rspack/src/ModuleFederationPlugin.ts +++ b/packages/rspack/src/ModuleFederationPlugin.ts @@ -1,4 +1,4 @@ -import { +import type { Compiler, ModuleFederationPluginOptions, RspackPluginInstance,