@nx/rspack 20.1.0-beta.0 → 20.1.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +17 -10
- package/src/executors/rspack/schema.d.ts +17 -0
- package/src/executors/rspack/schema.json +4 -6
- package/src/plugins/utils/apply-web-config.d.ts +5 -0
- package/src/plugins/utils/apply-web-config.js +383 -0
- package/src/plugins/utils/get-css-module-local-ident.d.ts +1 -0
- package/src/plugins/utils/get-css-module-local-ident.js +17 -0
- package/src/plugins/utils/hash-format.d.ts +7 -0
- package/src/plugins/utils/hash-format.js +22 -0
- package/src/plugins/utils/instantiate-script-plugins.d.ts +2 -0
- package/src/plugins/utils/instantiate-script-plugins.js +42 -0
- package/src/plugins/utils/loaders/stylesheet-loaders.d.ts +72 -0
- package/src/plugins/utils/loaders/stylesheet-loaders.js +119 -0
- package/src/plugins/utils/models.d.ts +229 -0
- package/src/plugins/utils/models.js +2 -0
- package/src/plugins/utils/normalize-entry.d.ts +2 -0
- package/src/plugins/utils/normalize-entry.js +27 -0
- package/src/plugins/utils/plugins/postcss-cli-resources.d.ts +14 -0
- package/src/plugins/utils/plugins/postcss-cli-resources.js +165 -0
- package/src/plugins/utils/plugins/scripts-rspack-plugin.d.ts +16 -0
- package/src/plugins/utils/plugins/scripts-rspack-plugin.js +77 -0
- package/src/utils/config.d.ts +9 -4
- package/src/utils/config.js +52 -5
- package/src/utils/generator-utils.js +1 -0
- package/src/utils/model.d.ts +15 -5
- package/src/utils/module-federation/with-module-federation/with-module-federation-ssr.d.ts +2 -2
- package/src/utils/module-federation/with-module-federation/with-module-federation.d.ts +2 -2
- package/src/utils/read-rspack-options.js +6 -0
- package/src/utils/with-nx.d.ts +2 -2
- package/src/utils/with-react.d.ts +2 -2
- package/src/utils/with-web.d.ts +13 -2
- package/src/utils/with-web.js +16 -102
package/src/utils/config.js
CHANGED
|
@@ -3,20 +3,67 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.nxRspackComposablePlugin = void 0;
|
|
4
4
|
exports.isNxRspackComposablePlugin = isNxRspackComposablePlugin;
|
|
5
5
|
exports.composePlugins = composePlugins;
|
|
6
|
+
exports.composePluginsSync = composePluginsSync;
|
|
7
|
+
const devkit_1 = require("@nx/devkit");
|
|
8
|
+
const configuration_1 = require("nx/src/config/configuration");
|
|
6
9
|
exports.nxRspackComposablePlugin = 'nxRspackComposablePlugin';
|
|
7
10
|
function isNxRspackComposablePlugin(a) {
|
|
8
11
|
return a?.[exports.nxRspackComposablePlugin] === true;
|
|
9
12
|
}
|
|
10
13
|
function composePlugins(...plugins) {
|
|
11
|
-
return Object.
|
|
14
|
+
return Object.assign(async function combined(config, ctx) {
|
|
15
|
+
// Rspack may be calling us as a standard config function.
|
|
16
|
+
// Build up Nx context from environment variables.
|
|
17
|
+
// This is to enable `@nx/webpack/plugin` to work with existing projects.
|
|
18
|
+
if (ctx['env']) {
|
|
19
|
+
ensureNxRspackExecutionContext(ctx);
|
|
20
|
+
// Build this from scratch since what webpack passes us is the env, not config,
|
|
21
|
+
// and `withNX()` creates a new config object anyway.
|
|
22
|
+
config = {};
|
|
23
|
+
}
|
|
12
24
|
for (const plugin of plugins) {
|
|
13
25
|
const fn = await plugin;
|
|
14
26
|
config = await fn(config, ctx);
|
|
15
27
|
}
|
|
16
28
|
return config;
|
|
17
|
-
},
|
|
18
|
-
|
|
19
|
-
enumerable: false,
|
|
20
|
-
writable: false,
|
|
29
|
+
}, {
|
|
30
|
+
[exports.nxRspackComposablePlugin]: true,
|
|
21
31
|
});
|
|
22
32
|
}
|
|
33
|
+
function composePluginsSync(...plugins) {
|
|
34
|
+
return Object.assign(function combined(config, ctx) {
|
|
35
|
+
for (const plugin of plugins) {
|
|
36
|
+
config = plugin(config, ctx);
|
|
37
|
+
}
|
|
38
|
+
return config;
|
|
39
|
+
}, {
|
|
40
|
+
[exports.nxRspackComposablePlugin]: true,
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
function ensureNxRspackExecutionContext(ctx) {
|
|
44
|
+
const projectName = process.env.NX_TASK_TARGET_PROJECT;
|
|
45
|
+
const targetName = process.env.NX_TASK_TARGET_TARGET;
|
|
46
|
+
const configurationName = process.env.NX_TASK_TARGET_CONFIGURATION;
|
|
47
|
+
const projectGraph = (0, devkit_1.readCachedProjectGraph)();
|
|
48
|
+
const projectNode = projectGraph.nodes[projectName];
|
|
49
|
+
ctx.options ??= {
|
|
50
|
+
root: devkit_1.workspaceRoot,
|
|
51
|
+
projectRoot: projectNode.data.root,
|
|
52
|
+
sourceRoot: projectNode.data.sourceRoot ?? projectNode.data.root,
|
|
53
|
+
// These aren't actually needed since NxRspackPlugin and withNx both support them being undefined.
|
|
54
|
+
assets: undefined,
|
|
55
|
+
outputFileName: undefined,
|
|
56
|
+
rspackConfig: undefined,
|
|
57
|
+
};
|
|
58
|
+
ctx.context ??= {
|
|
59
|
+
projectName,
|
|
60
|
+
targetName,
|
|
61
|
+
configurationName,
|
|
62
|
+
projectsConfigurations: (0, devkit_1.readProjectsConfigurationFromProjectGraph)(projectGraph),
|
|
63
|
+
nxJsonConfiguration: (0, configuration_1.readNxJson)(devkit_1.workspaceRoot),
|
|
64
|
+
cwd: process.cwd(),
|
|
65
|
+
root: devkit_1.workspaceRoot,
|
|
66
|
+
isVerbose: process.env['NX_VERBOSE_LOGGING'] === 'true',
|
|
67
|
+
projectGraph,
|
|
68
|
+
};
|
|
69
|
+
}
|
|
@@ -133,6 +133,7 @@ function addOrChangeBuildTarget(tree, options, target) {
|
|
|
133
133
|
outputPath: (0, devkit_1.joinPathFragments)('dist',
|
|
134
134
|
// If standalone project then use the project's name in dist.
|
|
135
135
|
project.root === '.' ? project.name : project.root),
|
|
136
|
+
index: (0, devkit_1.joinPathFragments)(project.root, 'src/index.html'),
|
|
136
137
|
main: determineMain(tree, options),
|
|
137
138
|
tsConfig: determineTsConfig(tree, options),
|
|
138
139
|
rspackConfig: (0, devkit_1.joinPathFragments)(project.root, 'rspack.config.js'),
|
package/src/utils/model.d.ts
CHANGED
|
@@ -1,6 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
export interface ExtraEntryPointClass {
|
|
2
|
+
bundleName?: string;
|
|
3
|
+
inject?: boolean;
|
|
4
|
+
input: string;
|
|
5
|
+
lazy?: boolean;
|
|
6
|
+
}
|
|
7
|
+
export type ExtraEntryPoint = ExtraEntryPointClass | string;
|
|
8
|
+
export type NormalizedEntryPoint = Required<ExtraEntryPointClass>;
|
|
9
|
+
export interface EmittedFile {
|
|
10
|
+
id?: string;
|
|
11
|
+
name?: string;
|
|
12
|
+
file: string;
|
|
13
|
+
extension: string;
|
|
14
|
+
initial: boolean;
|
|
15
|
+
asset?: boolean;
|
|
6
16
|
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { SharedConfigContext } from '../../model';
|
|
2
1
|
import { ModuleFederationConfig, NxModuleFederationConfigOverride } from '../models';
|
|
3
|
-
|
|
2
|
+
import { NxRspackExecutionContext } from '../../config';
|
|
3
|
+
export declare function withModuleFederationForSSR(options: ModuleFederationConfig, configOverride?: NxModuleFederationConfigOverride): Promise<(config: any, { context }: NxRspackExecutionContext) => any>;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { Configuration } from '@rspack/core';
|
|
2
|
-
import { SharedConfigContext } from '../../model';
|
|
3
2
|
import { ModuleFederationConfig, NxModuleFederationConfigOverride } from '../models';
|
|
3
|
+
import { NxRspackExecutionContext } from '../../config';
|
|
4
4
|
/**
|
|
5
5
|
* @param {ModuleFederationConfig} options
|
|
6
6
|
* @param {NxModuleFederationConfigOverride} configOverride
|
|
7
7
|
*/
|
|
8
|
-
export declare function withModuleFederation(options: ModuleFederationConfig, configOverride?: NxModuleFederationConfigOverride): Promise<(config: Configuration, { context }:
|
|
8
|
+
export declare function withModuleFederation(options: ModuleFederationConfig, configOverride?: NxModuleFederationConfigOverride): Promise<(config: Configuration, { context }: NxRspackExecutionContext) => Configuration>;
|
|
@@ -22,6 +22,12 @@ async function readRspackOptions(rspackConfig) {
|
|
|
22
22
|
root: devkit_1.workspaceRoot,
|
|
23
23
|
projectRoot: '',
|
|
24
24
|
sourceRoot: '',
|
|
25
|
+
outputFileName: '',
|
|
26
|
+
assets: [],
|
|
27
|
+
main: '',
|
|
28
|
+
tsConfig: '',
|
|
29
|
+
outputPath: '',
|
|
30
|
+
rspackConfig: '',
|
|
25
31
|
},
|
|
26
32
|
context: {
|
|
27
33
|
root: devkit_1.workspaceRoot,
|
package/src/utils/with-nx.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { Configuration } from '@rspack/core';
|
|
2
|
-
import {
|
|
3
|
-
export declare function withNx(_opts?: {}): (config: Configuration, { options, context }:
|
|
2
|
+
import { NxRspackExecutionContext } from './config';
|
|
3
|
+
export declare function withNx(_opts?: {}): (config: Configuration, { options, context }: NxRspackExecutionContext) => Configuration;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { Configuration } from '@rspack/core';
|
|
2
|
-
import {
|
|
3
|
-
export declare function withReact(opts?: {}): (config: Configuration, { options, context }:
|
|
2
|
+
import { NxRspackExecutionContext } from './config';
|
|
3
|
+
export declare function withReact(opts?: {}): (config: Configuration, { options, context }: NxRspackExecutionContext) => Configuration;
|
package/src/utils/with-web.d.ts
CHANGED
|
@@ -1,9 +1,20 @@
|
|
|
1
1
|
import { Configuration } from '@rspack/core';
|
|
2
|
-
import {
|
|
2
|
+
import { ExtraEntryPointClass } from './model';
|
|
3
|
+
import { NxRspackExecutionContext } from './config';
|
|
3
4
|
export interface WithWebOptions {
|
|
5
|
+
baseHref?: string;
|
|
6
|
+
deployUrl?: string;
|
|
7
|
+
extractCss?: boolean;
|
|
8
|
+
generateIndexHtml?: boolean;
|
|
9
|
+
index?: string;
|
|
10
|
+
postcssConfig?: string;
|
|
11
|
+
scripts?: Array<ExtraEntryPointClass | string>;
|
|
12
|
+
styles?: Array<ExtraEntryPointClass | string>;
|
|
13
|
+
subresourceIntegrity?: boolean;
|
|
4
14
|
stylePreprocessorOptions?: {
|
|
5
15
|
includePaths?: string[];
|
|
6
16
|
};
|
|
7
17
|
cssModules?: boolean;
|
|
18
|
+
ssr?: boolean;
|
|
8
19
|
}
|
|
9
|
-
export declare function withWeb(
|
|
20
|
+
export declare function withWeb(pluginOptions?: WithWebOptions): (config: Configuration, { options, context }: NxRspackExecutionContext) => Configuration;
|
package/src/utils/with-web.js
CHANGED
|
@@ -1,110 +1,24 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.withWeb = withWeb;
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
function withWeb(opts = {}) {
|
|
4
|
+
const apply_web_config_1 = require("../plugins/utils/apply-web-config");
|
|
5
|
+
const processed = new Set();
|
|
6
|
+
function withWeb(pluginOptions = {}) {
|
|
8
7
|
return function makeConfig(config, { options, context }) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const includePaths = [];
|
|
12
|
-
if (opts?.stylePreprocessorOptions?.includePaths?.length > 0) {
|
|
13
|
-
opts.stylePreprocessorOptions.includePaths.forEach((includePath) => includePaths.push(path.resolve(context.root, includePath)));
|
|
8
|
+
if (processed.has(config)) {
|
|
9
|
+
return config;
|
|
14
10
|
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
},
|
|
27
|
-
module: {
|
|
28
|
-
...config.module,
|
|
29
|
-
rules: [
|
|
30
|
-
...(config.module.rules || []),
|
|
31
|
-
{
|
|
32
|
-
test: /\.css$/,
|
|
33
|
-
type: opts?.cssModules ? 'css/module' : undefined,
|
|
34
|
-
},
|
|
35
|
-
{
|
|
36
|
-
test: /\.css$/,
|
|
37
|
-
type: 'css',
|
|
38
|
-
use: [
|
|
39
|
-
{
|
|
40
|
-
loader: require.resolve('postcss-loader'),
|
|
41
|
-
},
|
|
42
|
-
],
|
|
43
|
-
},
|
|
44
|
-
{
|
|
45
|
-
test: /\.scss$|\.sass$/,
|
|
46
|
-
type: opts?.cssModules ? 'css/module' : undefined,
|
|
47
|
-
use: [
|
|
48
|
-
{
|
|
49
|
-
loader: require.resolve('sass-loader'),
|
|
50
|
-
options: {
|
|
51
|
-
sourceMap: !!options.sourceMap,
|
|
52
|
-
sassOptions: {
|
|
53
|
-
fiber: false,
|
|
54
|
-
// bootstrap-sass requires a minimum precision of 8
|
|
55
|
-
precision: 8,
|
|
56
|
-
includePaths,
|
|
57
|
-
},
|
|
58
|
-
},
|
|
59
|
-
},
|
|
60
|
-
],
|
|
61
|
-
},
|
|
62
|
-
{
|
|
63
|
-
test: /.less$/,
|
|
64
|
-
type: opts?.cssModules ? 'css/module' : undefined,
|
|
65
|
-
use: [
|
|
66
|
-
{
|
|
67
|
-
loader: require.resolve('less-loader'),
|
|
68
|
-
options: {
|
|
69
|
-
sourceMap: !!options.sourceMap,
|
|
70
|
-
lessOptions: {
|
|
71
|
-
javascriptEnabled: true,
|
|
72
|
-
...lessPathOptions,
|
|
73
|
-
},
|
|
74
|
-
},
|
|
75
|
-
},
|
|
76
|
-
],
|
|
77
|
-
},
|
|
78
|
-
{
|
|
79
|
-
test: /\.styl$/,
|
|
80
|
-
use: [
|
|
81
|
-
{
|
|
82
|
-
loader: require.resolve('stylus-loader'),
|
|
83
|
-
options: {
|
|
84
|
-
sourceMap: !!options.sourceMap,
|
|
85
|
-
stylusOptions: {
|
|
86
|
-
include: includePaths,
|
|
87
|
-
},
|
|
88
|
-
},
|
|
89
|
-
},
|
|
90
|
-
],
|
|
91
|
-
},
|
|
92
|
-
].filter((a) => !!a),
|
|
93
|
-
},
|
|
94
|
-
plugins: [
|
|
95
|
-
...config.plugins,
|
|
96
|
-
new core_1.rspack.HtmlRspackPlugin({
|
|
97
|
-
template: options.indexHtml
|
|
98
|
-
? path.join(context.root, options.indexHtml)
|
|
99
|
-
: path.join(projectRoot, 'src/index.html'),
|
|
100
|
-
...(options.baseHref ? { base: { href: options.baseHref } } : {}),
|
|
101
|
-
}),
|
|
102
|
-
new core_1.rspack.EnvironmentPlugin({
|
|
103
|
-
NODE_ENV: isProd ? 'production' : 'development',
|
|
104
|
-
}),
|
|
105
|
-
new core_1.rspack.DefinePlugin(getClientEnvironment(isProd ? 'production' : undefined).stringified),
|
|
106
|
-
],
|
|
107
|
-
};
|
|
11
|
+
(0, apply_web_config_1.applyWebConfig)({
|
|
12
|
+
...options,
|
|
13
|
+
...pluginOptions,
|
|
14
|
+
root: context.root,
|
|
15
|
+
projectName: context.projectName,
|
|
16
|
+
targetName: context.targetName,
|
|
17
|
+
configurationName: context.configurationName,
|
|
18
|
+
projectGraph: context.projectGraph,
|
|
19
|
+
}, config);
|
|
20
|
+
processed.add(config);
|
|
21
|
+
return config;
|
|
108
22
|
};
|
|
109
23
|
}
|
|
110
24
|
function getClientEnvironment(mode) {
|