mirror of
https://github.com/storybookjs/storybook.git
synced 2025-04-02 05:03:44 +08:00
Apply correct transform on webpack config
This commit is contained in:
parent
35f56f8c35
commit
ea6fbd4af3
@ -18,6 +18,19 @@ export function babelDefault(config: TransformOptions): TransformOptions {
|
||||
}
|
||||
|
||||
export function webpackFinal(config: Configuration): Configuration {
|
||||
const tsxRule = config.module.rules.find((rule) => (rule.test as RegExp).test?.('main.tsx'));
|
||||
tsxRule.use = (tsxRule.use as any).map((entry: any) => {
|
||||
let newPlugins = entry.options.plugins;
|
||||
if (entry.loader?.includes('babel-loader')) {
|
||||
newPlugins = (entry.options as any).plugins.map((plugin: any) => {
|
||||
if (plugin[0]?.includes?.('@babel/plugin-transform-react-jsx')) {
|
||||
return [plugin[0], { importSource: 'preact', runtime: 'automatic' }];
|
||||
}
|
||||
return plugin;
|
||||
});
|
||||
}
|
||||
return { ...entry, options: { ...entry.options, plugins: newPlugins } };
|
||||
});
|
||||
return {
|
||||
...config,
|
||||
resolve: {
|
||||
@ -27,6 +40,7 @@ export function webpackFinal(config: Configuration): Configuration {
|
||||
react: path.dirname(require.resolve('preact/compat/package.json')),
|
||||
'react-dom/test-utils': path.dirname(require.resolve('preact/test-utils/package.json')),
|
||||
'react-dom': path.dirname(require.resolve('preact/compat/package.json')),
|
||||
'react/jsx-runtime': path.dirname(require.resolve('preact/jsx-runtime/package.json')),
|
||||
},
|
||||
},
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user