Skip to content

Commit

Permalink
fix(react): preserve dedicated rspack config file
Browse files Browse the repository at this point in the history
  • Loading branch information
pawel-twardziak committed Dec 7, 2024
1 parent 5d61191 commit 92d88a8
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 36 deletions.
60 changes: 24 additions & 36 deletions packages/react/src/generators/application/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -321,43 +321,31 @@ export async function applicationGeneratorInternal(
tasks.push(routingTask);
setDefaults(host, options);

if (options.bundler === 'rspack' && options.style === 'styled-jsx') {
logger.warn(
`${pc.bold('styled-jsx')} is not supported by ${pc.bold(
'Rspack'
)}. We've added ${pc.bold(
'babel-loader'
)} to your project, but using babel will slow down your build.`
);

tasks.push(
addDependenciesToPackageJson(
host,
{},
{ 'babel-loader': babelLoaderVersion }
)
);
if (options.bundler === 'rspack') {
if (options.style === 'styled-jsx') {
logger.warn(
`${pc.bold('styled-jsx')} is not supported by ${pc.bold(
'Rspack'
)}. We've added ${pc.bold(
'babel-loader'
)} to your project, but using babel will slow down your build.`
);

host.write(
joinPathFragments(options.appProjectRoot, 'rspack.config.js'),
stripIndents`
const { composePlugins, withNx, withReact } = require('@nx/rspack');
module.exports = composePlugins(withNx(), withReact(), (config) => {
config.module.rules.push({
test: /\\.[jt]sx$/i,
use: [
{
loader: 'babel-loader',
options: {
presets: ['@babel/preset-typescript'],
plugins: ['styled-jsx/babel'],
},
},
],
});
return config;
});
`
tasks.push(
addDependenciesToPackageJson(
host,
{},
{ 'babel-loader': babelLoaderVersion }
)
);
}
/**
* override the default config
*/
host.delete(joinPathFragments(options.appProjectRoot, 'rspack.config.js'));
host.rename(
joinPathFragments(options.appProjectRoot, 'tmp-rspack.config.js'),
joinPathFragments(options.appProjectRoot, 'rspack.config.js')
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,18 @@ module.exports = composePlugins(
(config) => {
// Update the rspack config as needed here.
// e.g. `config.plugins.push(new MyPlugin())`
<%_ if (style === 'styled-jsx') { _%>config.module.rules.push({
test: /\.[jt]sx$/i,
use: [
{
loader: 'babel-loader',
options: {
presets: ['@babel/preset-typescript'],
plugins: ['styled-jsx/babel'],
},
},
],
});<%_ } _%>
return config;
}
);
Expand Down

0 comments on commit 92d88a8

Please sign in to comment.