Skip to content

Commit

Permalink
Merge pull request #29157 from storybookjs/valentin/fix-svelte-vite-p…
Browse files Browse the repository at this point in the history
…lugin

Build: Shim CJS-only globals in ESM output
  • Loading branch information
valentinpalkovic authored Nov 1, 2024
2 parents bc837ac + f85d62c commit 3b5851a
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions code/frameworks/sveltekit/src/plugins/mock-sveltekit-stores.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
import { resolve } from 'node:path';
import { dirname, resolve } from 'node:path';
import { fileURLToPath } from 'node:url';

import type { Plugin } from 'vite';

// @ts-expect-error We are building for CJS and ESM, so we have to use import.meta.url for the ESM output
const filename = __filename ?? fileURLToPath(import.meta.url);
const dir = dirname(filename);

export async function mockSveltekitStores() {
return {
name: 'storybook:sveltekit-mock-stores',
config: () => ({
resolve: {
alias: {
'$app/forms': resolve(__dirname, '../src/mocks/app/forms.ts'),
'$app/navigation': resolve(__dirname, '../src/mocks/app/navigation.ts'),
'$app/stores': resolve(__dirname, '../src/mocks/app/stores.ts'),
'$app/forms': resolve(dir, '../src/mocks/app/forms.ts'),
'$app/navigation': resolve(dir, '../src/mocks/app/navigation.ts'),
'$app/stores': resolve(dir, '../src/mocks/app/stores.ts'),
},
},
}),
Expand Down

0 comments on commit 3b5851a

Please sign in to comment.