Skip to content

Commit

Permalink
feat(rspack): update executor to be in line with webpack (#28913)
Browse files Browse the repository at this point in the history
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
ndcunningham authored Nov 14, 2024
1 parent d8f9161 commit da60c38
Show file tree
Hide file tree
Showing 10 changed files with 581 additions and 78 deletions.
243 changes: 243 additions & 0 deletions docs/generated/packages/rspack/executors/rspack.json
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,203 @@
"generatePackageJson": {
"type": "boolean",
"description": "Generates a `package.json` and pruned lock file with the project's `node_module` dependencies populated for installing in a container. If a `package.json` exists in the project's directory, it will be reused with dependencies populated."
},
"additionalEntryPoints": {
"type": "array",
"items": {
"type": "object",
"properties": {
"entryName": {
"type": "string",
"description": "Name of the additional entry file."
},
"entryPath": {
"type": "string",
"description": "Path to the additional entry file.",
"x-completion-type": "file",
"x-completion-glob": "**/*@(.js|.ts)"
}
}
}
},
"buildLibsFromSource": {
"type": "boolean",
"description": "Read buildable libraries from source instead of building them separately. If set to `false`, the `tsConfig` option must also be set to remap paths.",
"default": true
},
"extractCss": {
"type": "boolean",
"description": "Extract CSS into a `.css` file."
},
"externalDependencies": {
"oneOf": [
{ "type": "string", "enum": ["none", "all"] },
{ "type": "array", "items": { "type": "string" } }
],
"description": "Dependencies to keep external to the bundle. (`all` (default), `none`, or an array of module names)"
},
"generateIndexHtml": {
"type": "boolean",
"description": "Generates `index.html` file to the output path. This can be turned off if using a webpack plugin to generate HTML such as `html-webpack-plugin`."
},
"memoryLimit": {
"type": "number",
"description": "Memory limit for type checking service process in `MB`."
},
"namedChunks": {
"type": "boolean",
"description": "Names the produced bundles according to their entry file."
},
"outputHashing": {
"type": "string",
"description": "Define the output filename cache-busting hashing mode.",
"enum": ["none", "all", "media", "bundles"]
},
"poll": {
"type": "number",
"description": "Enable and define the file watching poll time period."
},
"polyfills": {
"type": "string",
"description": "Polyfills to load before application",
"x-completion-type": "file",
"x-completion-glob": "**/*@(.js|.ts|.tsx)"
},
"postcssConfig": {
"type": "string",
"description": "Set a path to PostCSS config that applies to the app and all libs. Defaults to `undefined`, which auto-detects postcss.config.js files in each `app`/`lib` directory."
},
"progress": {
"type": "boolean",
"description": "Log progress to the console while building."
},
"publicPath": {
"type": "string",
"description": "Set a public path for assets resources with absolute paths."
},
"rebaseRootRelative": {
"type": "boolean",
"description": "Whether to rebase absolute path for assets in postcss cli resources."
},
"runtimeChunk": {
"type": "boolean",
"description": "Use a separate bundle containing the runtime."
},
"scripts": {
"type": "array",
"description": "External Scripts which will be included before the main application entry.",
"items": {
"oneOf": [
{
"type": "object",
"properties": {
"input": {
"type": "string",
"description": "The file to include.",
"x-completion-type": "file",
"x-completion-glob": "**/*@(.css|.scss|.less|.sass|.styl|.stylus)"
},
"bundleName": {
"type": "string",
"description": "The bundle name for this extra entry point."
},
"inject": {
"type": "boolean",
"description": "If the bundle will be referenced in the HTML file.",
"default": true
}
},
"additionalProperties": false,
"required": ["input"]
},
{
"type": "string",
"description": "The file to include.",
"x-completion-type": "file",
"x-completion-glob": "**/*@(.css|.scss|.less|.sass|.styl|.stylus)"
}
]
}
},
"standardRspackConfigFunction": {
"type": "boolean",
"description": "Set to true if the rspack config exports a standard rspack function, not an Nx-specific one. See: https://rspack.dev/config/",
"default": false
},
"statsJson": {
"type": "boolean",
"description": "Generates a 'stats.json' file which can be analyzed using tools such as: 'webpack-bundle-analyzer' See: https://rspack.dev/guide/optimization/analysis"
},
"stylePreprocessorOptions": {
"description": "Options to pass to style preprocessors.",
"type": "object",
"properties": {
"includePaths": {
"description": "Paths to include. Paths will be resolved to project root.",
"type": "array",
"items": { "type": "string" }
}
},
"additionalProperties": false
},
"styles": {
"type": "array",
"description": "External Styles which will be included with the application",
"items": {
"oneOf": [
{
"type": "object",
"properties": {
"input": {
"type": "string",
"description": "The file to include.",
"x-completion-type": "file",
"x-completion-glob": "**/*@(.css|.scss|.less|.sass|.styl|.stylus)"
},
"bundleName": {
"type": "string",
"description": "The bundle name for this extra entry point."
},
"inject": {
"type": "boolean",
"description": "If the bundle will be referenced in the HTML file.",
"default": true
}
},
"additionalProperties": false,
"required": ["input"]
},
{
"type": "string",
"description": "The file to include.",
"x-completion-type": "file",
"x-completion-glob": "**/*@(.css|.scss|.less|.sass|.styl|.stylus)"
}
]
}
},
"transformers": {
"type": "array",
"description": "List of TypeScript Compiler Transfomers Plugins.",
"aliases": ["tsPlugins"],
"items": {
"oneOf": [
{ "type": "string" },
{
"type": "object",
"properties": {
"name": { "type": "string" },
"options": { "type": "object", "additionalProperties": true }
},
"additionalProperties": false,
"required": ["name"]
}
]
}
},
"vendorChunk": {
"type": "boolean",
"description": "Use a separate bundle containing only vendor libraries."
}
},
"required": ["rspackConfig"],
Expand Down Expand Up @@ -188,6 +385,52 @@
},
{ "type": "string" }
]
},
"extraEntryPoint": {
"oneOf": [
{
"type": "object",
"properties": {
"input": {
"type": "string",
"description": "The file to include.",
"x-completion-type": "file",
"x-completion-glob": "**/*@(.css|.scss|.less|.sass|.styl|.stylus)"
},
"bundleName": {
"type": "string",
"description": "The bundle name for this extra entry point."
},
"inject": {
"type": "boolean",
"description": "If the bundle will be referenced in the HTML file.",
"default": true
}
},
"additionalProperties": false,
"required": ["input"]
},
{
"type": "string",
"description": "The file to include.",
"x-completion-type": "file",
"x-completion-glob": "**/*@(.css|.scss|.less|.sass|.styl|.stylus)"
}
]
},
"transformerPattern": {
"oneOf": [
{ "type": "string" },
{
"type": "object",
"properties": {
"name": { "type": "string" },
"options": { "type": "object", "additionalProperties": true }
},
"additionalProperties": false,
"required": ["name"]
}
]
}
},
"presets": []
Expand Down
9 changes: 9 additions & 0 deletions docs/generated/packages/webpack/executors/webpack.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@
"type": "boolean",
"description": "Use a separate bundle containing the runtime."
},
"skipTypeChecking": {
"alias": "typeCheck",
"type": "boolean",
"description": "Skip the type checking. Default is `false`."
},
"sourceMap": {
"description": "Output sourcemaps. Use 'hidden' for use with error reporting tools without generating sourcemap comment.",
"oneOf": [{ "type": "boolean" }, { "type": "string" }]
Expand All @@ -81,6 +86,10 @@
"type": "boolean",
"description": "Log progress to the console while building."
},
"poll": {
"type": "number",
"description": "Enable and define the file watching poll time period."
},
"assets": {
"type": "array",
"description": "List of static application assets.",
Expand Down
55 changes: 55 additions & 0 deletions packages/rspack/src/executors/rspack/lib/config.ts
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;
}
}
Loading

0 comments on commit da60c38

Please sign in to comment.