diff --git a/code/lib/csf-plugin/package.json b/code/lib/csf-plugin/package.json index 725feeba83b7..c3c9e45f60fe 100644 --- a/code/lib/csf-plugin/package.json +++ b/code/lib/csf-plugin/package.json @@ -22,15 +22,16 @@ "sideEffects": false, "exports": { ".": { - "require": "./dist/cjs/index.js", - "import": "./dist/esm/index.mjs", - "types": "./dist/types/index.d.ts" + "node": "./dist/index.js", + "require": "./dist/index.js", + "import": "./dist/index.mjs", + "types": "./dist/index.d.ts" }, "./package.json": "./package.json" }, - "main": "dist/cjs/index.js", - "module": "dist/esm/index.js", - "types": "dist/types/index.d.ts", + "main": "dist/index.js", + "module": "dist/index.mjs", + "types": "dist/index.d.ts", "files": [ "dist/**/*", "README.md", @@ -39,7 +40,7 @@ ], "scripts": { "check": "../../../scripts/node_modules/.bin/tsc --noEmit", - "prep": "node ../../../scripts/prepare.js" + "prep": "../../../scripts/prepare/bundle.ts" }, "dependencies": { "@storybook/csf-tools": "7.0.0-beta.19", @@ -54,7 +55,14 @@ "bundler": { "entries": [ "./src/index.ts" - ] + ], + "externals": [ + "webpack", + "vite", + "rollup", + "esbuild" + ], + "platform": "node" }, "gitHead": "da902f312eb354d20aa83bf0f0035b9744f93791" } diff --git a/code/lib/csf-plugin/src/index.ts b/code/lib/csf-plugin/src/index.ts index d75d169b9c96..397daf274aab 100644 --- a/code/lib/csf-plugin/src/index.ts +++ b/code/lib/csf-plugin/src/index.ts @@ -34,4 +34,7 @@ export const unplugin = createUnplugin((options) => { }; }); -export const { vite, rollup, webpack, esbuild } = unplugin; +export const { esbuild } = unplugin; +export const { webpack } = unplugin; +export const { rollup } = unplugin; +export const { vite } = unplugin; diff --git a/scripts/prepare/bundle.ts b/scripts/prepare/bundle.ts index 006688647985..bdff2cc6aeff 100755 --- a/scripts/prepare/bundle.ts +++ b/scripts/prepare/bundle.ts @@ -15,7 +15,7 @@ import { exec } from '../utils/exec'; type Formats = 'esm' | 'cjs'; type BundlerConfig = { entries: string[]; - untypedEntries: string[]; + externals: string[]; platform: Options['platform']; pre: string; post: string; @@ -33,7 +33,14 @@ const run = async ({ cwd, flags }: { cwd: string; flags: string[] }) => { name, dependencies, peerDependencies, - bundler: { entries = [], untypedEntries = [], platform, pre, post, formats = ['esm', 'cjs'] }, + bundler: { + entries = [], + externals: extraExternals = [], + platform, + pre, + post, + formats = ['esm', 'cjs'], + }, } = (await fs.readJson(join(cwd, 'package.json'))) as PackageJsonWithBundlerConfig; if (pre) { @@ -53,10 +60,11 @@ const run = async ({ cwd, flags }: { cwd: string; flags: string[] }) => { const outDir = join(process.cwd(), 'dist'); const externals = [ name, + ...extraExternals, ...Object.keys(dependencies || {}), ...Object.keys(peerDependencies || {}), ]; - const allEntries = [...entries, ...untypedEntries].map((e: string) => slash(join(cwd, e))); + const allEntries = entries.map((e: string) => slash(join(cwd, e))); const { dtsBuild, dtsConfig, tsConfigExists } = await getDTSConfigs({ formats,