@nx/rspack 20.1.0 → 20.2.0-beta.0
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 +8 -6
- package/src/executors/dev-server/dev-server.impl.js +12 -2
- package/src/executors/dev-server/lib/get-dev-server-config.js +1 -1
- package/src/executors/rspack/lib/normalize-options.d.ts +3 -0
- package/src/executors/rspack/lib/normalize-options.js +40 -0
- package/src/executors/rspack/rspack.impl.js +7 -3
- package/src/plugins/utils/apply-base-config.d.ts +5 -0
- package/src/plugins/utils/apply-base-config.js +348 -0
- package/src/plugins/utils/apply-react-config.d.ts +5 -0
- package/src/plugins/utils/apply-react-config.js +45 -0
- package/src/plugins/utils/apply-web-config.js +44 -45
- package/src/plugins/utils/get-terser-ecma-version.d.ts +1 -0
- package/src/plugins/utils/get-terser-ecma-version.js +35 -0
- package/src/plugins/utils/hash-format.js +7 -1
- package/src/plugins/utils/loaders/stylesheet-loaders.js +1 -1
- package/src/plugins/utils/models.d.ts +9 -8
- package/src/plugins/utils/plugins/generate-package-json-plugin.d.ts +15 -0
- package/src/plugins/utils/plugins/generate-package-json-plugin.js +45 -0
- package/src/plugins/utils/plugins/normalize-options.d.ts +4 -0
- package/src/plugins/utils/plugins/normalize-options.js +170 -0
- package/src/plugins/utils/plugins/nx-tsconfig-paths-rspack-plugin.d.ts +10 -0
- package/src/plugins/utils/plugins/nx-tsconfig-paths-rspack-plugin.js +62 -0
- package/src/plugins/utils/plugins/rspack-nx-build-coordination-plugin.d.ts +11 -0
- package/src/plugins/utils/plugins/rspack-nx-build-coordination-plugin.js +94 -0
- package/src/plugins/utils/plugins/stats-json-plugin.d.ts +4 -0
- package/src/plugins/utils/plugins/stats-json-plugin.js +13 -0
- package/src/utils/config.js +3 -2
- package/src/utils/create-compiler.js +25 -4
- package/src/utils/get-copy-patterns.js +1 -1
- package/src/utils/module-federation/share.js +2 -2
- package/src/utils/module-federation/with-module-federation/utils.js +1 -1
- package/src/utils/normalize-assets.js +1 -1
- package/src/utils/with-nx.d.ts +8 -3
- package/src/utils/with-nx.js +26 -184
- package/src/utils/with-react.d.ts +6 -1
- package/src/utils/with-react.js +3 -57
- package/src/utils/with-web.d.ts +0 -1
- package/src/utils/with-web.js +2 -2
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RspackNxBuildCoordinationPlugin = void 0;
|
|
4
|
+
const child_process_1 = require("child_process");
|
|
5
|
+
const client_1 = require("nx/src/daemon/client/client");
|
|
6
|
+
const watch_1 = require("nx/src/command-line/watch/watch");
|
|
7
|
+
const output_1 = require("nx/src/utils/output");
|
|
8
|
+
class RspackNxBuildCoordinationPlugin {
|
|
9
|
+
constructor(buildCmd, skipInitialBuild) {
|
|
10
|
+
this.buildCmd = buildCmd;
|
|
11
|
+
this.currentlyRunning = 'none';
|
|
12
|
+
this.buildCmdProcess = null;
|
|
13
|
+
if (!skipInitialBuild) {
|
|
14
|
+
this.buildChangedProjects();
|
|
15
|
+
}
|
|
16
|
+
if ((0, client_1.isDaemonEnabled)()) {
|
|
17
|
+
this.startWatchingBuildableLibs();
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
output_1.output.warn({
|
|
21
|
+
title: 'Nx Daemon is not enabled. Buildable libs will not be rebuilt on file changes.',
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
apply(compiler) {
|
|
26
|
+
compiler.hooks.beforeCompile.tapPromise('IncrementalDevServerPlugin', async () => {
|
|
27
|
+
while (this.currentlyRunning === 'nx-build') {
|
|
28
|
+
await sleep(50);
|
|
29
|
+
}
|
|
30
|
+
this.currentlyRunning = 'rspack-build';
|
|
31
|
+
});
|
|
32
|
+
compiler.hooks.done.tapPromise('IncrementalDevServerPlugin', async () => {
|
|
33
|
+
this.currentlyRunning = 'none';
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
async startWatchingBuildableLibs() {
|
|
37
|
+
const unregisterFileWatcher = await this.createFileWatcher();
|
|
38
|
+
process.on('exit', () => {
|
|
39
|
+
unregisterFileWatcher();
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
async buildChangedProjects() {
|
|
43
|
+
while (this.currentlyRunning === 'rspack-build') {
|
|
44
|
+
await sleep(50);
|
|
45
|
+
}
|
|
46
|
+
this.currentlyRunning = 'nx-build';
|
|
47
|
+
try {
|
|
48
|
+
return await new Promise((res) => {
|
|
49
|
+
this.buildCmdProcess = (0, child_process_1.exec)(this.buildCmd, {
|
|
50
|
+
windowsHide: false,
|
|
51
|
+
});
|
|
52
|
+
this.buildCmdProcess.stdout.pipe(process.stdout);
|
|
53
|
+
this.buildCmdProcess.stderr.pipe(process.stderr);
|
|
54
|
+
this.buildCmdProcess.on('exit', () => {
|
|
55
|
+
res();
|
|
56
|
+
});
|
|
57
|
+
this.buildCmdProcess.on('error', () => {
|
|
58
|
+
res();
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
finally {
|
|
63
|
+
this.currentlyRunning = 'none';
|
|
64
|
+
this.buildCmdProcess = null;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
createFileWatcher() {
|
|
68
|
+
const runner = new watch_1.BatchFunctionRunner(() => this.buildChangedProjects());
|
|
69
|
+
return client_1.daemonClient.registerFileWatcher({
|
|
70
|
+
watchProjects: 'all',
|
|
71
|
+
}, (err, { changedProjects, changedFiles }) => {
|
|
72
|
+
if (err === 'closed') {
|
|
73
|
+
output_1.output.error({
|
|
74
|
+
title: 'Watch connection closed',
|
|
75
|
+
bodyLines: [
|
|
76
|
+
'The daemon has closed the connection to this watch process.',
|
|
77
|
+
'Please restart your watch command.',
|
|
78
|
+
],
|
|
79
|
+
});
|
|
80
|
+
process.exit(1);
|
|
81
|
+
}
|
|
82
|
+
if (this.buildCmdProcess) {
|
|
83
|
+
this.buildCmdProcess.kill(2);
|
|
84
|
+
this.buildCmdProcess = null;
|
|
85
|
+
}
|
|
86
|
+
// Queue a build
|
|
87
|
+
runner.enqueue(changedProjects, changedFiles);
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
exports.RspackNxBuildCoordinationPlugin = RspackNxBuildCoordinationPlugin;
|
|
92
|
+
function sleep(time) {
|
|
93
|
+
return new Promise((resolve) => setTimeout(resolve, time));
|
|
94
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.StatsJsonPlugin = void 0;
|
|
4
|
+
const core_1 = require("@rspack/core");
|
|
5
|
+
class StatsJsonPlugin {
|
|
6
|
+
apply(compiler) {
|
|
7
|
+
compiler.hooks.emit.tap('StatsJsonPlugin', (compilation) => {
|
|
8
|
+
const data = JSON.stringify(compilation.getStats().toJson('verbose'));
|
|
9
|
+
compilation.assets[`stats.json`] = new core_1.sources.RawSource(data);
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
exports.StatsJsonPlugin = StatsJsonPlugin;
|
package/src/utils/config.js
CHANGED
|
@@ -14,10 +14,10 @@ function composePlugins(...plugins) {
|
|
|
14
14
|
return Object.assign(async function combined(config, ctx) {
|
|
15
15
|
// Rspack may be calling us as a standard config function.
|
|
16
16
|
// Build up Nx context from environment variables.
|
|
17
|
-
// This is to enable `@nx/
|
|
17
|
+
// This is to enable `@nx/rspack/plugin` to work with existing projects.
|
|
18
18
|
if (ctx['env']) {
|
|
19
19
|
ensureNxRspackExecutionContext(ctx);
|
|
20
|
-
// Build this from scratch since what
|
|
20
|
+
// Build this from scratch since what rspack passes us is the env, not config,
|
|
21
21
|
// and `withNX()` creates a new config object anyway.
|
|
22
22
|
config = {};
|
|
23
23
|
}
|
|
@@ -53,6 +53,7 @@ function ensureNxRspackExecutionContext(ctx) {
|
|
|
53
53
|
// These aren't actually needed since NxRspackPlugin and withNx both support them being undefined.
|
|
54
54
|
assets: undefined,
|
|
55
55
|
outputFileName: undefined,
|
|
56
|
+
outputPath: undefined,
|
|
56
57
|
rspackConfig: undefined,
|
|
57
58
|
};
|
|
58
59
|
ctx.context ??= {
|
|
@@ -1,19 +1,40 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
2
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
26
|
exports.createCompiler = createCompiler;
|
|
4
27
|
exports.isMultiCompiler = isMultiCompiler;
|
|
5
|
-
const tslib_1 = require("tslib");
|
|
6
28
|
const core_1 = require("@rspack/core");
|
|
7
|
-
const path = tslib_1.__importStar(require("path"));
|
|
8
29
|
const resolve_user_defined_rspack_config_1 = require("./resolve-user-defined-rspack-config");
|
|
9
30
|
async function createCompiler(options, context) {
|
|
10
|
-
const pathToConfig =
|
|
31
|
+
const pathToConfig = options.rspackConfig;
|
|
11
32
|
let userDefinedConfig = {};
|
|
12
33
|
if (options.tsConfig) {
|
|
13
34
|
userDefinedConfig = (0, resolve_user_defined_rspack_config_1.resolveUserDefinedRspackConfig)(pathToConfig, options.tsConfig);
|
|
14
35
|
}
|
|
15
36
|
else {
|
|
16
|
-
userDefinedConfig = await Promise.resolve(`${pathToConfig}`).then(s =>
|
|
37
|
+
userDefinedConfig = await Promise.resolve(`${pathToConfig}`).then(s => __importStar(require(s))).then((x) => x.default || x);
|
|
17
38
|
}
|
|
18
39
|
if (typeof userDefinedConfig.then === 'function') {
|
|
19
40
|
userDefinedConfig = await userDefinedConfig;
|
|
@@ -5,7 +5,7 @@ function getCopyPatterns(assets) {
|
|
|
5
5
|
return assets.map((asset) => {
|
|
6
6
|
return {
|
|
7
7
|
context: asset.input,
|
|
8
|
-
// Now we remove starting slash to make
|
|
8
|
+
// Now we remove starting slash to make rspack place it from the output root.
|
|
9
9
|
to: asset.output,
|
|
10
10
|
from: asset.glob,
|
|
11
11
|
globOptions: {
|
|
@@ -54,7 +54,7 @@ function shareWorkspaceLibraries(workspaceLibs, tsConfigPath = process.env.NX_TS
|
|
|
54
54
|
return {
|
|
55
55
|
getAliases: () => pathMappings.reduce((aliases, library) => ({
|
|
56
56
|
...aliases,
|
|
57
|
-
// If the library path ends in a wildcard, remove it as
|
|
57
|
+
// If the library path ends in a wildcard, remove it as rspack can't handle this in resolve.alias
|
|
58
58
|
// e.g. path/to/my/lib/* -> path/to/my/lib
|
|
59
59
|
[library.name]: library.path.replace(/\/\*$/, ''),
|
|
60
60
|
}), {}),
|
|
@@ -108,7 +108,7 @@ function shareWorkspaceLibraries(workspaceLibs, tsConfigPath = process.env.NX_TS
|
|
|
108
108
|
* library.path is usually in the form of "/Users/username/path/to/Workspace/path/to/library"
|
|
109
109
|
*
|
|
110
110
|
* When a wildcard is used in the TS path mappings, we want to get everything after the import to
|
|
111
|
-
* re-route the request correctly inline with the
|
|
111
|
+
* re-route the request correctly inline with the rspack resolve.alias
|
|
112
112
|
*/
|
|
113
113
|
(0, path_1.join)(library.name, req.request.split(library.path.replace(devkit_1.workspaceRoot, '').replace('/*', ''))[1])
|
|
114
114
|
: library.name;
|
|
@@ -28,7 +28,7 @@ function getFunctionDeterminateRemoteUrl(isServer = false) {
|
|
|
28
28
|
const serveTarget = remoteConfiguration?.targets?.[target];
|
|
29
29
|
if (!serveTarget) {
|
|
30
30
|
throw new Error(`Cannot automatically determine URL of remote (${remote}). Looked for property "host" in the project's "${serveTarget}" target.\n
|
|
31
|
-
You can also use the tuple syntax in your
|
|
31
|
+
You can also use the tuple syntax in your rspack config to configure your remotes. e.g. \`remotes: [['remote1', 'http://localhost:4201']]\``);
|
|
32
32
|
}
|
|
33
33
|
const host = serveTarget.options?.host ??
|
|
34
34
|
`http${serveTarget.options.ssl ? 's' : ''}://localhost`;
|
|
@@ -34,7 +34,7 @@ function normalizeAssets(assets, root, sourceRoot) {
|
|
|
34
34
|
return {
|
|
35
35
|
...asset,
|
|
36
36
|
input: resolvedAssetPath,
|
|
37
|
-
// Now we remove starting slash to make
|
|
37
|
+
// Now we remove starting slash to make rspack place it from the output root.
|
|
38
38
|
output: asset.output.replace(/^\//, ''),
|
|
39
39
|
};
|
|
40
40
|
}
|
package/src/utils/with-nx.d.ts
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
export
|
|
1
|
+
import { NxAppRspackPluginOptions } from '../plugins/utils/models';
|
|
2
|
+
import { NxComposableRspackPlugin } from './config';
|
|
3
|
+
export type WithNxOptions = Partial<NxAppRspackPluginOptions>;
|
|
4
|
+
/**
|
|
5
|
+
* @param {WithNxOptions} pluginOptions
|
|
6
|
+
* @returns {NxComposableRspackPlugin}
|
|
7
|
+
*/
|
|
8
|
+
export declare function withNx(pluginOptions?: WithNxOptions): NxComposableRspackPlugin;
|
package/src/utils/with-nx.js
CHANGED
|
@@ -1,191 +1,33 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.withNx = withNx;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const core_1 = require("@rspack/core");
|
|
6
|
-
const fs_1 = require("fs");
|
|
7
|
-
const license_webpack_plugin_1 = require("license-webpack-plugin");
|
|
8
|
-
const path = tslib_1.__importStar(require("path"));
|
|
9
|
-
const path_1 = require("path");
|
|
10
|
-
const generate_package_json_plugin_1 = require("../plugins/generate-package-json-plugin");
|
|
11
|
-
const get_copy_patterns_1 = require("./get-copy-patterns");
|
|
12
4
|
const normalize_assets_1 = require("./normalize-assets");
|
|
13
|
-
|
|
5
|
+
const apply_base_config_1 = require("../plugins/utils/apply-base-config");
|
|
6
|
+
const processed = new Set();
|
|
7
|
+
/**
|
|
8
|
+
* @param {WithNxOptions} pluginOptions
|
|
9
|
+
* @returns {NxComposableRspackPlugin}
|
|
10
|
+
*/
|
|
11
|
+
function withNx(pluginOptions = {}) {
|
|
14
12
|
return function makeConfig(config, { options, context }) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
try {
|
|
35
|
-
const rootPackageJson = JSON.parse((0, fs_1.readFileSync)(pathToRootPackageJson, 'utf-8'));
|
|
36
|
-
rootPackageJsonName = rootPackageJson.name;
|
|
37
|
-
}
|
|
38
|
-
catch {
|
|
39
|
-
// do nothing
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
plugins.push(new license_webpack_plugin_1.LicenseWebpackPlugin({
|
|
43
|
-
stats: {
|
|
44
|
-
warnings: false,
|
|
45
|
-
errors: false,
|
|
46
|
-
},
|
|
47
|
-
outputFilename: `3rdpartylicenses.txt`,
|
|
48
|
-
/**
|
|
49
|
-
* Needed to prevent an issue with Rspack and Workspaces where the
|
|
50
|
-
* workspace's root package.json file is added to the dependency tree
|
|
51
|
-
*/
|
|
52
|
-
excludedPackageTest: (packageName) => {
|
|
53
|
-
if (!rootPackageJsonName) {
|
|
54
|
-
return false;
|
|
55
|
-
}
|
|
56
|
-
return packageName === rootPackageJsonName;
|
|
57
|
-
},
|
|
58
|
-
}));
|
|
59
|
-
}
|
|
60
|
-
if (options.generatePackageJson) {
|
|
61
|
-
const mainOutputFile = options.main.split('/').pop().split('.')[0] + '.js';
|
|
62
|
-
plugins.push(new generate_package_json_plugin_1.GeneratePackageJsonPlugin({
|
|
63
|
-
tsConfig: options.tsConfig,
|
|
64
|
-
outputFileName: options.outputFileName ?? mainOutputFile,
|
|
65
|
-
}, context));
|
|
66
|
-
}
|
|
67
|
-
plugins.push(new core_1.rspack.CopyRspackPlugin({
|
|
68
|
-
patterns: (0, get_copy_patterns_1.getCopyPatterns)((0, normalize_assets_1.normalizeAssets)(options.assets, context.root, sourceRoot)),
|
|
69
|
-
}));
|
|
70
|
-
plugins.push(new core_1.rspack.ProgressPlugin());
|
|
71
|
-
options.fileReplacements.forEach((item) => {
|
|
72
|
-
alias[item.replace] = item.with;
|
|
73
|
-
});
|
|
74
|
-
const externals = {};
|
|
75
|
-
let externalsType;
|
|
76
|
-
if (options.target === 'node') {
|
|
77
|
-
const projectDeps = context.projectGraph.dependencies[context.projectName];
|
|
78
|
-
for (const dep of Object.values(projectDeps)) {
|
|
79
|
-
const externalNode = context.projectGraph.externalNodes[dep.target];
|
|
80
|
-
if (externalNode) {
|
|
81
|
-
externals[externalNode.data.packageName] =
|
|
82
|
-
externalNode.data.packageName;
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
externalsType = 'commonjs';
|
|
86
|
-
}
|
|
87
|
-
const updated = {
|
|
88
|
-
...config,
|
|
89
|
-
target: options.target,
|
|
90
|
-
mode: options.mode,
|
|
91
|
-
entry: {},
|
|
92
|
-
context: (0, path_1.join)(context.root, context.projectGraph.nodes[context.projectName].data.root),
|
|
93
|
-
devtool: options.sourceMap === 'hidden'
|
|
94
|
-
? 'hidden-source-map'
|
|
95
|
-
: options.sourceMap
|
|
96
|
-
? 'source-map'
|
|
97
|
-
: false,
|
|
98
|
-
output: {
|
|
99
|
-
path: path.join(context.root, options.outputPath),
|
|
100
|
-
publicPath: '/',
|
|
101
|
-
filename: isProd && options.target !== 'node'
|
|
102
|
-
? '[name].[contenthash:8].js'
|
|
103
|
-
: '[name].js',
|
|
104
|
-
chunkFilename: isProd && options.target !== 'node'
|
|
105
|
-
? '[name].[contenthash:8].js'
|
|
106
|
-
: '[name].js',
|
|
107
|
-
cssFilename: isProd && options.target !== 'node'
|
|
108
|
-
? '[name].[contenthash:8].css'
|
|
109
|
-
: '[name].css',
|
|
110
|
-
cssChunkFilename: isProd && options.target !== 'node'
|
|
111
|
-
? '[name].[contenthash:8].css'
|
|
112
|
-
: '[name].css',
|
|
113
|
-
assetModuleFilename: isProd && options.target !== 'node'
|
|
114
|
-
? '[name].[contenthash:8][ext]'
|
|
115
|
-
: '[name][ext]',
|
|
116
|
-
},
|
|
117
|
-
devServer: {
|
|
118
|
-
...(config.devServer ?? {}),
|
|
119
|
-
port: config.devServer?.port ?? 4200,
|
|
120
|
-
hot: config.devServer?.hot ?? true,
|
|
121
|
-
devMiddleware: {
|
|
122
|
-
...(config.devServer?.devMiddleware ?? {}),
|
|
123
|
-
stats: true,
|
|
124
|
-
},
|
|
125
|
-
},
|
|
126
|
-
module: {
|
|
127
|
-
rules: [
|
|
128
|
-
{
|
|
129
|
-
test: /\.js$/,
|
|
130
|
-
loader: 'builtin:swc-loader',
|
|
131
|
-
exclude: /node_modules/,
|
|
132
|
-
options: {
|
|
133
|
-
jsc: {
|
|
134
|
-
parser: {
|
|
135
|
-
syntax: 'ecmascript',
|
|
136
|
-
},
|
|
137
|
-
externalHelpers: true,
|
|
138
|
-
},
|
|
139
|
-
},
|
|
140
|
-
type: 'javascript/auto',
|
|
141
|
-
},
|
|
142
|
-
{
|
|
143
|
-
test: /\.ts$/,
|
|
144
|
-
loader: 'builtin:swc-loader',
|
|
145
|
-
exclude: /node_modules/,
|
|
146
|
-
options: {
|
|
147
|
-
jsc: {
|
|
148
|
-
parser: {
|
|
149
|
-
syntax: 'typescript',
|
|
150
|
-
decorators: true,
|
|
151
|
-
},
|
|
152
|
-
transform: {
|
|
153
|
-
legacyDecorator: true,
|
|
154
|
-
decoratorMetadata: true,
|
|
155
|
-
},
|
|
156
|
-
externalHelpers: true,
|
|
157
|
-
},
|
|
158
|
-
},
|
|
159
|
-
type: 'javascript/auto',
|
|
160
|
-
},
|
|
161
|
-
],
|
|
162
|
-
},
|
|
163
|
-
plugins: plugins,
|
|
164
|
-
resolve: {
|
|
165
|
-
// There are some issues resolving workspace libs in a monorepo.
|
|
166
|
-
// It looks to be an issue with rspack itself, but will check back after Nx 16 release
|
|
167
|
-
// once I can reproduce a small example repo with rspack only.
|
|
168
|
-
alias,
|
|
169
|
-
// We need to define the extensions that rspack can resolve
|
|
170
|
-
extensions: ['...', '.ts', '.tsx', '.jsx'],
|
|
171
|
-
// tsConfigPath: path.join(context.root, options.tsConfig),
|
|
172
|
-
},
|
|
173
|
-
infrastructureLogging: {
|
|
174
|
-
debug: false,
|
|
175
|
-
},
|
|
176
|
-
externals,
|
|
177
|
-
externalsType,
|
|
178
|
-
stats: {
|
|
179
|
-
colors: true,
|
|
180
|
-
preset: 'normal',
|
|
181
|
-
},
|
|
182
|
-
};
|
|
183
|
-
const mainEntry = options.main
|
|
184
|
-
? options.outputFileName
|
|
185
|
-
? path.parse(options.outputFileName).name
|
|
186
|
-
: 'main'
|
|
187
|
-
: 'main';
|
|
188
|
-
updated.entry[mainEntry] = path.resolve(context.root, options.main);
|
|
189
|
-
return updated;
|
|
13
|
+
if (processed.has(config))
|
|
14
|
+
return config;
|
|
15
|
+
(0, apply_base_config_1.applyBaseConfig)({
|
|
16
|
+
...options,
|
|
17
|
+
...pluginOptions,
|
|
18
|
+
target: options.target ?? 'web',
|
|
19
|
+
assets: options.assets
|
|
20
|
+
? options.assets
|
|
21
|
+
: pluginOptions.assets
|
|
22
|
+
? (0, normalize_assets_1.normalizeAssets)(pluginOptions.assets, options.root, options.sourceRoot)
|
|
23
|
+
: [],
|
|
24
|
+
root: context.root,
|
|
25
|
+
projectName: context.projectName,
|
|
26
|
+
targetName: context.targetName,
|
|
27
|
+
configurationName: context.configurationName,
|
|
28
|
+
projectGraph: context.projectGraph,
|
|
29
|
+
}, config);
|
|
30
|
+
processed.add(config);
|
|
31
|
+
return config;
|
|
190
32
|
};
|
|
191
33
|
}
|
|
@@ -1,3 +1,8 @@
|
|
|
1
1
|
import { Configuration } from '@rspack/core';
|
|
2
2
|
import { NxRspackExecutionContext } from './config';
|
|
3
|
-
|
|
3
|
+
import { WithWebOptions } from './with-web';
|
|
4
|
+
import { SvgrOptions } from '../plugins/utils/models';
|
|
5
|
+
export interface WithReactOptions extends WithWebOptions {
|
|
6
|
+
svgr?: boolean | SvgrOptions;
|
|
7
|
+
}
|
|
8
|
+
export declare function withReact(opts?: WithReactOptions): (config: Configuration, { options, context }: NxRspackExecutionContext) => Configuration;
|
package/src/utils/with-react.js
CHANGED
|
@@ -2,68 +2,14 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.withReact = withReact;
|
|
4
4
|
const with_web_1 = require("./with-web");
|
|
5
|
+
const apply_react_config_1 = require("../plugins/utils/apply-react-config");
|
|
5
6
|
function withReact(opts = {}) {
|
|
6
7
|
return function makeConfig(config, { options, context }) {
|
|
7
|
-
const isDev = process.env.NODE_ENV === 'development' || options.mode === 'development';
|
|
8
8
|
config = (0, with_web_1.withWeb)({ ...opts, cssModules: true })(config, {
|
|
9
9
|
options,
|
|
10
10
|
context,
|
|
11
11
|
});
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
const react = {
|
|
15
|
-
runtime: 'automatic',
|
|
16
|
-
development: isDev,
|
|
17
|
-
refresh: isDev,
|
|
18
|
-
};
|
|
19
|
-
return {
|
|
20
|
-
...config,
|
|
21
|
-
plugins: [
|
|
22
|
-
...(config.plugins || []),
|
|
23
|
-
isDev && new ReactRefreshPlugin(),
|
|
24
|
-
].filter(Boolean),
|
|
25
|
-
module: {
|
|
26
|
-
...config.module,
|
|
27
|
-
rules: [
|
|
28
|
-
...(config.module.rules || []),
|
|
29
|
-
{
|
|
30
|
-
test: /\.jsx$/,
|
|
31
|
-
loader: 'builtin:swc-loader',
|
|
32
|
-
exclude: /node_modules/,
|
|
33
|
-
options: {
|
|
34
|
-
jsc: {
|
|
35
|
-
parser: {
|
|
36
|
-
syntax: 'ecmascript',
|
|
37
|
-
jsx: true,
|
|
38
|
-
},
|
|
39
|
-
transform: {
|
|
40
|
-
react,
|
|
41
|
-
},
|
|
42
|
-
externalHelpers: true,
|
|
43
|
-
},
|
|
44
|
-
},
|
|
45
|
-
type: 'javascript/auto',
|
|
46
|
-
},
|
|
47
|
-
{
|
|
48
|
-
test: /\.tsx$/,
|
|
49
|
-
loader: 'builtin:swc-loader',
|
|
50
|
-
exclude: /node_modules/,
|
|
51
|
-
options: {
|
|
52
|
-
jsc: {
|
|
53
|
-
parser: {
|
|
54
|
-
syntax: 'typescript',
|
|
55
|
-
tsx: true,
|
|
56
|
-
},
|
|
57
|
-
transform: {
|
|
58
|
-
react,
|
|
59
|
-
},
|
|
60
|
-
externalHelpers: true,
|
|
61
|
-
},
|
|
62
|
-
},
|
|
63
|
-
type: 'javascript/auto',
|
|
64
|
-
},
|
|
65
|
-
],
|
|
66
|
-
},
|
|
67
|
-
};
|
|
12
|
+
(0, apply_react_config_1.applyReactConfig)(opts, config);
|
|
13
|
+
return config;
|
|
68
14
|
};
|
|
69
15
|
}
|
package/src/utils/with-web.d.ts
CHANGED
|
@@ -10,7 +10,6 @@ export interface WithWebOptions {
|
|
|
10
10
|
postcssConfig?: string;
|
|
11
11
|
scripts?: Array<ExtraEntryPointClass | string>;
|
|
12
12
|
styles?: Array<ExtraEntryPointClass | string>;
|
|
13
|
-
subresourceIntegrity?: boolean;
|
|
14
13
|
stylePreprocessorOptions?: {
|
|
15
14
|
includePaths?: string[];
|
|
16
15
|
};
|
package/src/utils/with-web.js
CHANGED
|
@@ -23,7 +23,7 @@ function withWeb(pluginOptions = {}) {
|
|
|
23
23
|
}
|
|
24
24
|
function getClientEnvironment(mode) {
|
|
25
25
|
// Grab NODE_ENV and NX_PUBLIC_* environment variables and prepare them to be
|
|
26
|
-
// injected into the application via DefinePlugin in
|
|
26
|
+
// injected into the application via DefinePlugin in rspack configuration.
|
|
27
27
|
const nxPublicKeyRegex = /^NX_PUBLIC_/i;
|
|
28
28
|
const raw = Object.keys(process.env)
|
|
29
29
|
.filter((key) => nxPublicKeyRegex.test(key))
|
|
@@ -31,7 +31,7 @@ function getClientEnvironment(mode) {
|
|
|
31
31
|
env[key] = process.env[key];
|
|
32
32
|
return env;
|
|
33
33
|
}, {});
|
|
34
|
-
// Stringify all values so we can feed into
|
|
34
|
+
// Stringify all values so we can feed into rspack DefinePlugin
|
|
35
35
|
const stringified = {
|
|
36
36
|
'process.env': Object.keys(raw).reduce((env, key) => {
|
|
37
37
|
env[key] = JSON.stringify(raw[key]);
|