Skip to content

Commit

Permalink
Apply correct transform on webpack config
Browse files Browse the repository at this point in the history
  • Loading branch information
KrofDrakula committed Jul 22, 2022
1 parent 35f56f8 commit ea6fbd4
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions app/preact/src/server/framework-preset-preact.ts
Expand Up @@ -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: {
Expand All @@ -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')),
},
},
};
Expand Down

0 comments on commit ea6fbd4

Please sign in to comment.