Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle resolve.alias as an array #430

Merged
merged 1 commit into from
Jul 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions examples/vue/.storybook/main.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
const { resolve } = require('path');
const { mergeConfig } = require('vite');

export default {
framework: '@storybook/vue3',
stories: ['../stories/**/*.stories.mdx', '../stories/**/*.stories.@(js|jsx|ts|tsx)'],
Expand All @@ -11,7 +14,9 @@ export default {
previewMdx2: true,
},
async viteFinal(config, { configType }) {
// customize the Vite config here
return config;
// Demonstrates use of mergeConfig and resolve.alias as an array
return mergeConfig(config, {
resolve: { alias: [{ find: '@assets', replacement: resolve(__dirname, '..', 'stories', 'assets') }] },
});
},
};
16 changes: 8 additions & 8 deletions examples/vue/stories/Introduction.stories.mdx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Meta } from '@storybook/addon-docs';
import Code from './assets/code-brackets.svg';
import Colors from './assets/colors.svg';
import Comments from './assets/comments.svg';
import Direction from './assets/direction.svg';
import Flow from './assets/flow.svg';
import Plugin from './assets/plugin.svg';
import Repo from './assets/repo.svg';
import StackAlt from './assets/stackalt.svg';
import Code from '@assets/code-brackets.svg';
import Colors from '@assets/colors.svg';
import Comments from '@assets/comments.svg';
import Direction from '@assets/direction.svg';
import Flow from '@assets/flow.svg';
import Plugin from '@assets/plugin.svg';
import Repo from '@assets/repo.svg';
import StackAlt from '@assets/stackalt.svg';

<Meta title="Introduction" />

Expand Down
7 changes: 3 additions & 4 deletions packages/builder-vite/code-generator-plugin.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as fs from 'fs';
import * as path from 'path';
import { mergeConfig } from 'vite';
import { transformIframeHtml } from './transform-iframe-html';
import { generateIframeScriptCode } from './codegen-iframe-script';
import { generateModernIframeScriptCode } from './codegen-modern-iframe-script';
Expand Down Expand Up @@ -64,13 +65,11 @@ export function codeGeneratorPlugin(options: ExtendedOptions): Plugin {
require.resolve('react-dom/client', { paths: [config.root || process.cwd()] });
} catch (e) {
if (isNodeError(e) && e.code === 'MODULE_NOT_FOUND') {
config.resolve = {
...config.resolve,
config.resolve = mergeConfig(config.resolve ?? {}, {
alias: {
...config.resolve?.alias,
'react-dom/client': path.resolve(__dirname, '..', 'input', 'react-dom-client-placeholder.js'),
},
};
});
}
}
},
Expand Down