-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(rspack): update executor to be in line with webpack (#28913)
This PR brings the rspack executor `@nx/rspack:rspack` inline with webpack. It also prepares the executor to be used with the soon to be implemented `NxRspackAppPlugin` so that we can support executor and inferred targets.
- Loading branch information
1 parent
d8f9161
commit da60c38
Showing
10 changed files
with
581 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { join } from 'path'; | ||
import { ExecutorContext } from '@nx/devkit'; | ||
import { type Configuration } from '@rspack/core'; | ||
import { | ||
composePluginsSync, | ||
isNxRspackComposablePlugin, | ||
} from '../../../utils/config'; | ||
import { resolveUserDefinedRspackConfig } from '../../../utils/resolve-user-defined-rspack-config'; | ||
import { withNx } from '../../../utils/with-nx'; | ||
import { withWeb } from '../../../utils/with-web'; | ||
import { type NormalizedRspackExecutorSchema } from '../schema'; | ||
|
||
export async function getRspackConfigs( | ||
options: NormalizedRspackExecutorSchema & { devServer?: any }, | ||
context: ExecutorContext | ||
): Promise<Configuration | Configuration[]> { | ||
let userDefinedConfig = resolveUserDefinedRspackConfig( | ||
options.rspackConfig, | ||
options.tsConfig | ||
); | ||
|
||
if (typeof userDefinedConfig.then === 'function') { | ||
userDefinedConfig = await userDefinedConfig; | ||
} | ||
|
||
const config = ( | ||
options.target === 'web' | ||
? composePluginsSync(withNx(options), withWeb(options)) | ||
: withNx(options) | ||
)({}, { options, context }); | ||
|
||
if ( | ||
(typeof userDefinedConfig === 'function' && | ||
isNxRspackComposablePlugin(userDefinedConfig)) || | ||
!options.standardRspackConfigFunction | ||
) { | ||
// Old behavior, call the Nx-specific rspack config function that user exports | ||
return await userDefinedConfig(config, { | ||
options, | ||
context, | ||
configuration: context.configurationName, | ||
}); | ||
} else if (userDefinedConfig) { | ||
if (typeof userDefinedConfig === 'function') { | ||
// assume it's an async standard rspack config function which operates similar to webpack | ||
// https://webpack.js.org/configuration/configuration-types/#exporting-a-promise | ||
return await userDefinedConfig(process.env.NODE_ENV, {}); | ||
} | ||
// New behavior, we want the rspack config to export object | ||
return userDefinedConfig; | ||
} else { | ||
// Fallback case, if we cannot find a rspack config path | ||
return config; | ||
} | ||
} |
Oops, something went wrong.