@nx/rspack 24.0.0 → 24.0.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/dist/src/plugins/nx-app-rspack-plugin/nx-app-rspack-plugin.d.ts +1 -1
- package/dist/src/plugins/nx-app-rspack-plugin/nx-app-rspack-plugin.js +17 -4
- package/dist/src/plugins/utils/apply-base-config.js +29 -0
- package/dist/src/plugins/utils/apply-web-config.js +13 -10
- package/dist/src/plugins/utils/get-browserslist-targets.d.ts +7 -0
- package/dist/src/plugins/utils/get-browserslist-targets.js +110 -0
- package/dist/src/plugins/utils/get-terser-ecma-version.js +1 -1
- package/dist/src/plugins/utils/loaders/stylesheet-loaders.d.ts +3 -3
- package/dist/src/plugins/utils/loaders/stylesheet-loaders.js +11 -5
- package/dist/src/plugins/utils/models.d.ts +1 -1
- package/package.json +6 -6
|
@@ -8,7 +8,7 @@ import { READY_SIGNAL_PLUGIN } from '../../utils/dev-server-ready-signal';
|
|
|
8
8
|
* - Stylesheets handling
|
|
9
9
|
* - index.html and package.json generation
|
|
10
10
|
*
|
|
11
|
-
* Web-only features, such as stylesheets and images, are only supported when `target`
|
|
11
|
+
* Web-only features, such as stylesheets and images, are only supported when `target` runs in a browser, such as `web`, `webworker` or `browserslist`.
|
|
12
12
|
*/
|
|
13
13
|
export declare class NxAppRspackPlugin {
|
|
14
14
|
private readonly options;
|
|
@@ -6,6 +6,7 @@ const normalize_options_1 = require("../utils/plugins/normalize-options");
|
|
|
6
6
|
const dev_server_ready_signal_1 = require("../../utils/dev-server-ready-signal");
|
|
7
7
|
const apply_base_config_1 = require("../utils/apply-base-config");
|
|
8
8
|
const apply_web_config_1 = require("../utils/apply-web-config");
|
|
9
|
+
const load_rspack_core_1 = require("../../utils/load-rspack-core");
|
|
9
10
|
/**
|
|
10
11
|
* This plugin provides features to build Node and Web applications.
|
|
11
12
|
* - TS Support (including tsconfig paths
|
|
@@ -13,7 +14,7 @@ const apply_web_config_1 = require("../utils/apply-web-config");
|
|
|
13
14
|
* - Stylesheets handling
|
|
14
15
|
* - index.html and package.json generation
|
|
15
16
|
*
|
|
16
|
-
* Web-only features, such as stylesheets and images, are only supported when `target`
|
|
17
|
+
* Web-only features, such as stylesheets and images, are only supported when `target` runs in a browser, such as `web`, `webworker` or `browserslist`.
|
|
17
18
|
*/
|
|
18
19
|
class NxAppRspackPlugin {
|
|
19
20
|
constructor(options = {}) {
|
|
@@ -46,9 +47,7 @@ class NxAppRspackPlugin {
|
|
|
46
47
|
if (compiler.options.target) {
|
|
47
48
|
this.options.target = compiler.options.target;
|
|
48
49
|
}
|
|
49
|
-
if (this.options.target
|
|
50
|
-
this.options.target === 'webworker' ||
|
|
51
|
-
this.options.ssr) {
|
|
50
|
+
if (isBrowserTarget(compiler, this.options.target) || this.options.ssr) {
|
|
52
51
|
(0, apply_web_config_1.applyWebConfig)(this.options, compiler.options, {
|
|
53
52
|
useNormalizedEntry: true,
|
|
54
53
|
compiler,
|
|
@@ -58,3 +57,17 @@ class NxAppRspackPlugin {
|
|
|
58
57
|
}
|
|
59
58
|
exports.NxAppRspackPlugin = NxAppRspackPlugin;
|
|
60
59
|
_a = dev_server_ready_signal_1.READY_SIGNAL_PLUGIN;
|
|
60
|
+
// Let rspack resolve the platform so `browserslist` targets count by the browsers they list.
|
|
61
|
+
function isBrowserTarget(compiler, target) {
|
|
62
|
+
const { config } = (0, load_rspack_core_1.loadRspackCore)(compiler);
|
|
63
|
+
const options = config.getNormalizedRspackOptions({
|
|
64
|
+
context: compiler.options.context,
|
|
65
|
+
target: target,
|
|
66
|
+
// Rspack throws for targets without a default chunk format, such as `es2020`.
|
|
67
|
+
output: { chunkFormat: false },
|
|
68
|
+
});
|
|
69
|
+
// Read the applied defaults: rspack 1.6 and earlier return nothing from this call.
|
|
70
|
+
config.applyRspackOptionsDefaults(options);
|
|
71
|
+
return (options.externalsPresets.web === true &&
|
|
72
|
+
options.externalsPresets.node === false);
|
|
73
|
+
}
|
|
@@ -3,6 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.applyBaseConfig = applyBaseConfig;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const path = tslib_1.__importStar(require("path"));
|
|
6
|
+
const devkit_1 = require("@nx/devkit");
|
|
7
|
+
const fs_1 = require("fs");
|
|
6
8
|
const license_webpack_plugin_1 = require("license-webpack-plugin");
|
|
7
9
|
const js_1 = require("@nx/js");
|
|
8
10
|
const version_utils_1 = require("../../utils/version-utils");
|
|
@@ -12,6 +14,7 @@ const generate_package_json_plugin_1 = require("./plugins/generate-package-json-
|
|
|
12
14
|
const hash_format_1 = require("./hash-format");
|
|
13
15
|
const nx_tsconfig_paths_rspack_plugin_1 = require("./plugins/nx-tsconfig-paths-rspack-plugin");
|
|
14
16
|
const get_terser_ecma_version_1 = require("./get-terser-ecma-version");
|
|
17
|
+
const get_browserslist_targets_1 = require("./get-browserslist-targets");
|
|
15
18
|
const nodeExternals = require("webpack-node-externals");
|
|
16
19
|
const internal_1 = require("@nx/js/internal");
|
|
17
20
|
const get_non_buildable_libs_1 = require("./get-non-buildable-libs");
|
|
@@ -328,6 +331,7 @@ function applyNxDependentConfig(options, config, { useNormalizedEntry } = {}, rs
|
|
|
328
331
|
plugins.push(new ProgressPlugin({ profile: options.verbose }));
|
|
329
332
|
}
|
|
330
333
|
if (options.extractLicenses) {
|
|
334
|
+
const projectPackageName = readProjectPackageName(options);
|
|
331
335
|
plugins.push(new license_webpack_plugin_1.LicenseWebpackPlugin({
|
|
332
336
|
stats: {
|
|
333
337
|
warnings: false,
|
|
@@ -335,6 +339,9 @@ function applyNxDependentConfig(options, config, { useNormalizedEntry } = {}, rs
|
|
|
335
339
|
},
|
|
336
340
|
perChunkOutput: false,
|
|
337
341
|
outputFilename: `3rdpartylicenses.txt`,
|
|
342
|
+
// Loader-prefixed `data:` modules (the Module Federation runtime) resolve
|
|
343
|
+
// to the package.json in the cwd, which is the project root.
|
|
344
|
+
excludedPackageTest: (packageName) => !!projectPackageName && packageName === projectPackageName,
|
|
338
345
|
}));
|
|
339
346
|
}
|
|
340
347
|
if (Array.isArray(options.assets) && options.assets.length > 0) {
|
|
@@ -416,6 +423,18 @@ function applyNxDependentConfig(options, config, { useNormalizedEntry } = {}, rs
|
|
|
416
423
|
cache,
|
|
417
424
|
}).cache
|
|
418
425
|
: cache;
|
|
426
|
+
const projectRoot = path.join(options.root, options.projectRoot);
|
|
427
|
+
const browserslistTargets = (0, get_browserslist_targets_1.getBrowserslistTargets)(config.target, projectRoot);
|
|
428
|
+
if (browserslistTargets) {
|
|
429
|
+
// For `web`, rspack writes its runtime code with arrow functions and other modern syntax.
|
|
430
|
+
config.output = {
|
|
431
|
+
...config.output,
|
|
432
|
+
environment: {
|
|
433
|
+
...(0, get_browserslist_targets_1.getUnsupportedEnvironmentFeatures)(rspackCore, projectRoot, browserslistTargets.queries),
|
|
434
|
+
...config.output?.environment,
|
|
435
|
+
},
|
|
436
|
+
};
|
|
437
|
+
}
|
|
419
438
|
config.module = {
|
|
420
439
|
...config.module,
|
|
421
440
|
rules: [
|
|
@@ -450,6 +469,9 @@ function applyNxDependentConfig(options, config, { useNormalizedEntry } = {}, rs
|
|
|
450
469
|
exclude: /node_modules/,
|
|
451
470
|
type: 'javascript/auto',
|
|
452
471
|
options: {
|
|
472
|
+
...(browserslistTargets
|
|
473
|
+
? { env: { targets: browserslistTargets.swc } }
|
|
474
|
+
: {}),
|
|
453
475
|
jsc: {
|
|
454
476
|
parser: {
|
|
455
477
|
syntax: 'typescript',
|
|
@@ -478,3 +500,10 @@ function applyNxDependentConfig(options, config, { useNormalizedEntry } = {}, rs
|
|
|
478
500
|
config.plugins ??= [];
|
|
479
501
|
config.plugins.push(...plugins);
|
|
480
502
|
}
|
|
503
|
+
function readProjectPackageName(options) {
|
|
504
|
+
const packageJsonPath = path.join(options.root, options.projectRoot, 'package.json');
|
|
505
|
+
if (!(0, fs_1.existsSync)(packageJsonPath)) {
|
|
506
|
+
return undefined;
|
|
507
|
+
}
|
|
508
|
+
return (0, devkit_1.readJsonFile)(packageJsonPath).name;
|
|
509
|
+
}
|
|
@@ -4,6 +4,7 @@ exports.applyWebConfig = applyWebConfig;
|
|
|
4
4
|
const internal_1 = require("@nx/js/internal");
|
|
5
5
|
const path_1 = require("path");
|
|
6
6
|
const write_index_html_plugin_1 = require("../write-index-html-plugin");
|
|
7
|
+
const get_browserslist_targets_1 = require("./get-browserslist-targets");
|
|
7
8
|
const hash_format_1 = require("./hash-format");
|
|
8
9
|
const instantiate_script_plugins_1 = require("./instantiate-script-plugins");
|
|
9
10
|
const stylesheet_loaders_1 = require("./loaders/stylesheet-loaders");
|
|
@@ -64,10 +65,12 @@ function applyWebConfig(options, config = {}, { useNormalizedEntry, compiler, }
|
|
|
64
65
|
}));
|
|
65
66
|
}
|
|
66
67
|
}
|
|
68
|
+
const browserslistQueries = (0, get_browserslist_targets_1.getBrowserslistTargets)(config.target, (0, path_1.join)(options.root, options.projectRoot))?.queries;
|
|
67
69
|
const minimizer = [];
|
|
68
70
|
if (isProd && stylesOptimization) {
|
|
69
71
|
minimizer.push(new LightningCssMinimizerRspackPlugin({
|
|
70
72
|
test: /\.(?:css|scss|sass|less)$/,
|
|
73
|
+
minimizerOptions: { targets: browserslistQueries },
|
|
71
74
|
}));
|
|
72
75
|
}
|
|
73
76
|
if (!options.ssr) {
|
|
@@ -103,13 +106,13 @@ function applyWebConfig(options, config = {}, { useNormalizedEntry, compiler, }
|
|
|
103
106
|
{
|
|
104
107
|
test: /\.module\.css$/,
|
|
105
108
|
exclude: globalStylePaths,
|
|
106
|
-
use: (0, stylesheet_loaders_1.getCommonLoadersForCssModules)(options, includePaths, cssExtractLoader),
|
|
109
|
+
use: (0, stylesheet_loaders_1.getCommonLoadersForCssModules)(options, includePaths, cssExtractLoader, browserslistQueries),
|
|
107
110
|
},
|
|
108
111
|
{
|
|
109
112
|
test: /\.module\.(scss|sass)$/,
|
|
110
113
|
exclude: globalStylePaths,
|
|
111
114
|
use: [
|
|
112
|
-
...(0, stylesheet_loaders_1.getCommonLoadersForCssModules)(options, includePaths, cssExtractLoader),
|
|
115
|
+
...(0, stylesheet_loaders_1.getCommonLoadersForCssModules)(options, includePaths, cssExtractLoader, browserslistQueries),
|
|
113
116
|
{
|
|
114
117
|
loader: require.resolve('sass-loader'),
|
|
115
118
|
options: {
|
|
@@ -129,7 +132,7 @@ function applyWebConfig(options, config = {}, { useNormalizedEntry, compiler, }
|
|
|
129
132
|
test: /\.module\.less$/,
|
|
130
133
|
exclude: globalStylePaths,
|
|
131
134
|
use: [
|
|
132
|
-
...(0, stylesheet_loaders_1.getCommonLoadersForCssModules)(options, includePaths, cssExtractLoader),
|
|
135
|
+
...(0, stylesheet_loaders_1.getCommonLoadersForCssModules)(options, includePaths, cssExtractLoader, browserslistQueries),
|
|
133
136
|
{
|
|
134
137
|
loader: (0, path_1.join)(__dirname, 'loaders/deprecated-less-loader.js'),
|
|
135
138
|
options: {
|
|
@@ -146,13 +149,13 @@ function applyWebConfig(options, config = {}, { useNormalizedEntry, compiler, }
|
|
|
146
149
|
{
|
|
147
150
|
test: /\.css$/,
|
|
148
151
|
exclude: globalStylePaths,
|
|
149
|
-
use: (0, stylesheet_loaders_1.getCommonLoadersForGlobalCss)(options, includePaths, cssExtractLoader),
|
|
152
|
+
use: (0, stylesheet_loaders_1.getCommonLoadersForGlobalCss)(options, includePaths, cssExtractLoader, browserslistQueries),
|
|
150
153
|
},
|
|
151
154
|
{
|
|
152
155
|
test: /\.scss$|\.sass$/,
|
|
153
156
|
exclude: globalStylePaths,
|
|
154
157
|
use: [
|
|
155
|
-
...(0, stylesheet_loaders_1.getCommonLoadersForGlobalCss)(options, includePaths, cssExtractLoader),
|
|
158
|
+
...(0, stylesheet_loaders_1.getCommonLoadersForGlobalCss)(options, includePaths, cssExtractLoader, browserslistQueries),
|
|
156
159
|
{
|
|
157
160
|
loader: require.resolve('sass-loader'),
|
|
158
161
|
options: {
|
|
@@ -174,7 +177,7 @@ function applyWebConfig(options, config = {}, { useNormalizedEntry, compiler, }
|
|
|
174
177
|
test: /\.less$/,
|
|
175
178
|
exclude: globalStylePaths,
|
|
176
179
|
use: [
|
|
177
|
-
...(0, stylesheet_loaders_1.getCommonLoadersForGlobalCss)(options, includePaths, cssExtractLoader),
|
|
180
|
+
...(0, stylesheet_loaders_1.getCommonLoadersForGlobalCss)(options, includePaths, cssExtractLoader, browserslistQueries),
|
|
178
181
|
{
|
|
179
182
|
loader: (0, path_1.join)(__dirname, 'loaders/deprecated-less-loader.js'),
|
|
180
183
|
options: {
|
|
@@ -193,13 +196,13 @@ function applyWebConfig(options, config = {}, { useNormalizedEntry, compiler, }
|
|
|
193
196
|
{
|
|
194
197
|
test: /\.css$/,
|
|
195
198
|
include: globalStylePaths,
|
|
196
|
-
use: (0, stylesheet_loaders_1.getCommonLoadersForGlobalStyle)(options, includePaths, cssExtractLoader),
|
|
199
|
+
use: (0, stylesheet_loaders_1.getCommonLoadersForGlobalStyle)(options, includePaths, cssExtractLoader, browserslistQueries),
|
|
197
200
|
},
|
|
198
201
|
{
|
|
199
202
|
test: /\.scss$|\.sass$/,
|
|
200
203
|
include: globalStylePaths,
|
|
201
204
|
use: [
|
|
202
|
-
...(0, stylesheet_loaders_1.getCommonLoadersForGlobalStyle)(options, includePaths, cssExtractLoader),
|
|
205
|
+
...(0, stylesheet_loaders_1.getCommonLoadersForGlobalStyle)(options, includePaths, cssExtractLoader, browserslistQueries),
|
|
203
206
|
{
|
|
204
207
|
loader: require.resolve('sass-loader'),
|
|
205
208
|
options: {
|
|
@@ -221,7 +224,7 @@ function applyWebConfig(options, config = {}, { useNormalizedEntry, compiler, }
|
|
|
221
224
|
test: /\.less$/,
|
|
222
225
|
include: globalStylePaths,
|
|
223
226
|
use: [
|
|
224
|
-
...(0, stylesheet_loaders_1.getCommonLoadersForGlobalStyle)(options, includePaths, cssExtractLoader),
|
|
227
|
+
...(0, stylesheet_loaders_1.getCommonLoadersForGlobalStyle)(options, includePaths, cssExtractLoader, browserslistQueries),
|
|
225
228
|
{
|
|
226
229
|
loader: (0, path_1.join)(__dirname, 'loaders/deprecated-less-loader.js'),
|
|
227
230
|
options: {
|
|
@@ -273,7 +276,7 @@ function applyWebConfig(options, config = {}, { useNormalizedEntry, compiler, }
|
|
|
273
276
|
}
|
|
274
277
|
});
|
|
275
278
|
config.optimization = !isProd
|
|
276
|
-
? {}
|
|
279
|
+
? (config.optimization ?? {})
|
|
277
280
|
: {
|
|
278
281
|
...(config.optimization ?? {}),
|
|
279
282
|
minimizer: [...(config.optimization?.minimizer ?? []), ...minimizer],
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Configuration } from '@rspack/core';
|
|
2
|
+
export interface BrowserslistTargets {
|
|
3
|
+
queries: string[];
|
|
4
|
+
swc: Record<string, string>;
|
|
5
|
+
}
|
|
6
|
+
export declare function getBrowserslistTargets(target: Configuration['target'], projectRoot: string): BrowserslistTargets | undefined;
|
|
7
|
+
export declare function getUnsupportedEnvironmentFeatures(rspackCore: typeof import('@rspack/core'), projectRoot: string, browserslistQueries: string[]): Record<string, false>;
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getBrowserslistTargets = getBrowserslistTargets;
|
|
4
|
+
exports.getUnsupportedEnvironmentFeatures = getUnsupportedEnvironmentFeatures;
|
|
5
|
+
const browserslist = require("browserslist");
|
|
6
|
+
const semver_1 = require("semver");
|
|
7
|
+
// Rspack 2 renames browsers like this before it passes its own targets to swc,
|
|
8
|
+
// and drops the ones swc rejects.
|
|
9
|
+
const SWC_BROWSER_NAMES = {
|
|
10
|
+
and_chr: 'chrome',
|
|
11
|
+
and_ff: 'firefox',
|
|
12
|
+
ie_mob: 'ie',
|
|
13
|
+
ios_saf: 'ios',
|
|
14
|
+
op_mob: 'opera',
|
|
15
|
+
and_qq: null,
|
|
16
|
+
and_uc: null,
|
|
17
|
+
baidu: null,
|
|
18
|
+
bb: null,
|
|
19
|
+
kaios: null,
|
|
20
|
+
};
|
|
21
|
+
function getBrowserslistTargets(target, projectRoot) {
|
|
22
|
+
const browsers = getBrowsers(target, projectRoot)?.map((entry) => {
|
|
23
|
+
const [name, versions] = entry.split(' ');
|
|
24
|
+
return { entry, name, lowestVersion: versions.split('-')[0] };
|
|
25
|
+
});
|
|
26
|
+
if (!browsers) {
|
|
27
|
+
return undefined;
|
|
28
|
+
}
|
|
29
|
+
return {
|
|
30
|
+
// Lightning CSS rejects exact versions newer than its data, so pass numeric versions as `>=`.
|
|
31
|
+
queries: browsers.map(({ entry, name, lowestVersion }) => isVersion(lowestVersion) ? `${name} >= ${lowestVersion}` : entry),
|
|
32
|
+
swc: getSwcTargets(browsers),
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
function getBrowsers(target, projectRoot) {
|
|
36
|
+
// `web` and `webworker` carry no browser versions, so use the project's config.
|
|
37
|
+
if (target === 'web' || target === 'webworker') {
|
|
38
|
+
return loadBrowserslist(undefined, projectRoot);
|
|
39
|
+
}
|
|
40
|
+
// Autoprefixer never sees these browsers, and rspack 1 passes them to neither swc nor
|
|
41
|
+
// Lightning CSS.
|
|
42
|
+
const lists = (Array.isArray(target) ? target : [target])
|
|
43
|
+
.map((entry) => typeof entry === 'string' ? entry.match(/^browserslist(?::(.+))?$/) : null)
|
|
44
|
+
.filter(Boolean)
|
|
45
|
+
.map((match) => loadBrowserslist(match[1]?.trim(), projectRoot))
|
|
46
|
+
.filter(Boolean);
|
|
47
|
+
return lists.length ? lists.flat() : undefined;
|
|
48
|
+
}
|
|
49
|
+
// Reads `browserslist:<rest>` like rspack: a config path with an optional env, then
|
|
50
|
+
// a query, then an env. Resolve in JS so `extends` packages are found from the project.
|
|
51
|
+
function loadBrowserslist(rest, projectRoot) {
|
|
52
|
+
const [, configPath, env] = (rest ?? '').match(/^(?:((?:[A-Z]:)?[/\\].*?))?(?::(.+?))?$/) ?? [];
|
|
53
|
+
if (configPath) {
|
|
54
|
+
return browserslist(undefined, {
|
|
55
|
+
config: configPath,
|
|
56
|
+
env,
|
|
57
|
+
path: projectRoot,
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
if (rest) {
|
|
61
|
+
try {
|
|
62
|
+
return browserslist(rest, { path: projectRoot });
|
|
63
|
+
}
|
|
64
|
+
catch (error) {
|
|
65
|
+
if (!error?.browserslist) {
|
|
66
|
+
throw error;
|
|
67
|
+
}
|
|
68
|
+
return browserslist(undefined, { env: rest, path: projectRoot });
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
const config = browserslist.loadConfig({ path: projectRoot });
|
|
72
|
+
return config ? browserslist(config, { path: projectRoot }) : undefined;
|
|
73
|
+
}
|
|
74
|
+
// swc in rspack 1.7.0 and earlier lowers everything for queries newer than its
|
|
75
|
+
// data, but compares minimum versions directly.
|
|
76
|
+
function getSwcTargets(browsers) {
|
|
77
|
+
const targets = {};
|
|
78
|
+
for (const { name, lowestVersion } of browsers) {
|
|
79
|
+
const swcName = name in SWC_BROWSER_NAMES ? SWC_BROWSER_NAMES[name] : name;
|
|
80
|
+
// Safari Technology Preview supports every feature.
|
|
81
|
+
const version = lowestVersion === 'TP'
|
|
82
|
+
? (0, semver_1.coerce)('999')
|
|
83
|
+
: isVersion(lowestVersion)
|
|
84
|
+
? (0, semver_1.coerce)(lowestVersion)
|
|
85
|
+
: null;
|
|
86
|
+
if (swcName &&
|
|
87
|
+
version &&
|
|
88
|
+
(!targets[swcName] || (0, semver_1.lt)(version, targets[swcName]))) {
|
|
89
|
+
targets[swcName] = version;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return Object.fromEntries(Object.entries(targets).map(([name, version]) => [name, version.version]));
|
|
93
|
+
}
|
|
94
|
+
function isVersion(version) {
|
|
95
|
+
return /^\d+(\.\d+)*$/.test(version);
|
|
96
|
+
}
|
|
97
|
+
function getUnsupportedEnvironmentFeatures(rspackCore, projectRoot, browserslistQueries) {
|
|
98
|
+
const { config } = rspackCore;
|
|
99
|
+
const options = config.getNormalizedRspackOptions({
|
|
100
|
+
context: projectRoot,
|
|
101
|
+
// Rspack throws when its data has none of these versions. Adding the latest
|
|
102
|
+
// Chrome avoids that without turning off a feature the others support.
|
|
103
|
+
target: [
|
|
104
|
+
'web',
|
|
105
|
+
`browserslist:${[...browserslistQueries, 'last 1 chrome version'].join(', ')}`,
|
|
106
|
+
],
|
|
107
|
+
});
|
|
108
|
+
config.applyRspackOptionsDefaults(options);
|
|
109
|
+
return Object.fromEntries(Object.entries(options.output.environment).filter(([, supported]) => supported === false));
|
|
110
|
+
}
|
|
@@ -30,6 +30,6 @@ function getTerserEcmaVersion(projectRoot) {
|
|
|
30
30
|
return 2020;
|
|
31
31
|
}
|
|
32
32
|
const env = browserslist.loadConfig({ path: pathToBrowserslistFile });
|
|
33
|
-
const browsers = browserslist(env);
|
|
33
|
+
const browsers = browserslist(env, { path: projectRoot });
|
|
34
34
|
return browsers.some((b) => ES5_BROWSERS.includes(b)) ? 5 : 2020;
|
|
35
35
|
}
|
|
@@ -2,7 +2,7 @@ interface PostcssOptions {
|
|
|
2
2
|
(loader: any): any;
|
|
3
3
|
config?: string;
|
|
4
4
|
}
|
|
5
|
-
export declare function getCommonLoadersForCssModules(options: any, includePaths: string[], cssExtractLoader: string): ({
|
|
5
|
+
export declare function getCommonLoadersForCssModules(options: any, includePaths: string[], cssExtractLoader: string, browserslistQueries?: string[]): ({
|
|
6
6
|
loader: string;
|
|
7
7
|
options?: undefined;
|
|
8
8
|
} | {
|
|
@@ -27,7 +27,7 @@ export declare function getCommonLoadersForCssModules(options: any, includePaths
|
|
|
27
27
|
postcssOptions: PostcssOptions;
|
|
28
28
|
};
|
|
29
29
|
})[];
|
|
30
|
-
export declare function getCommonLoadersForGlobalCss(options: any, includePaths: string[], cssExtractLoader: string): ({
|
|
30
|
+
export declare function getCommonLoadersForGlobalCss(options: any, includePaths: string[], cssExtractLoader: string, browserslistQueries?: string[]): ({
|
|
31
31
|
options?: undefined;
|
|
32
32
|
loader: string;
|
|
33
33
|
} | {
|
|
@@ -45,7 +45,7 @@ export declare function getCommonLoadersForGlobalCss(options: any, includePaths:
|
|
|
45
45
|
postcssOptions: PostcssOptions;
|
|
46
46
|
};
|
|
47
47
|
})[];
|
|
48
|
-
export declare function getCommonLoadersForGlobalStyle(options: any, includePaths: string[], cssExtractLoader: string): ({
|
|
48
|
+
export declare function getCommonLoadersForGlobalStyle(options: any, includePaths: string[], cssExtractLoader: string, browserslistQueries?: string[]): ({
|
|
49
49
|
loader: string;
|
|
50
50
|
options: {
|
|
51
51
|
implementation?: undefined;
|
|
@@ -10,7 +10,7 @@ const postcssImports = require("postcss-import");
|
|
|
10
10
|
const get_css_module_local_ident_1 = require("../get-css-module-local-ident");
|
|
11
11
|
const hash_format_1 = require("../hash-format");
|
|
12
12
|
const postcss_cli_resources_1 = require("../plugins/postcss-cli-resources");
|
|
13
|
-
function getCommonLoadersForCssModules(options, includePaths, cssExtractLoader) {
|
|
13
|
+
function getCommonLoadersForCssModules(options, includePaths, cssExtractLoader, browserslistQueries) {
|
|
14
14
|
// load component css as raw strings
|
|
15
15
|
return [
|
|
16
16
|
{
|
|
@@ -40,12 +40,13 @@ function getCommonLoadersForCssModules(options, includePaths, cssExtractLoader)
|
|
|
40
40
|
postcssOptions: postcssOptionsCreator(options, {
|
|
41
41
|
includePaths,
|
|
42
42
|
forCssModules: true,
|
|
43
|
+
browserslistQueries,
|
|
43
44
|
}),
|
|
44
45
|
},
|
|
45
46
|
},
|
|
46
47
|
];
|
|
47
48
|
}
|
|
48
|
-
function getCommonLoadersForGlobalCss(options, includePaths, cssExtractLoader) {
|
|
49
|
+
function getCommonLoadersForGlobalCss(options, includePaths, cssExtractLoader, browserslistQueries) {
|
|
49
50
|
return [
|
|
50
51
|
{
|
|
51
52
|
loader: options.extractCss
|
|
@@ -59,12 +60,13 @@ function getCommonLoadersForGlobalCss(options, includePaths, cssExtractLoader) {
|
|
|
59
60
|
implementation: require('postcss'),
|
|
60
61
|
postcssOptions: postcssOptionsCreator(options, {
|
|
61
62
|
includePaths,
|
|
63
|
+
browserslistQueries,
|
|
62
64
|
}),
|
|
63
65
|
},
|
|
64
66
|
},
|
|
65
67
|
];
|
|
66
68
|
}
|
|
67
|
-
function getCommonLoadersForGlobalStyle(options, includePaths, cssExtractLoader) {
|
|
69
|
+
function getCommonLoadersForGlobalStyle(options, includePaths, cssExtractLoader, browserslistQueries) {
|
|
68
70
|
return [
|
|
69
71
|
{
|
|
70
72
|
loader: options.extractCss
|
|
@@ -79,12 +81,13 @@ function getCommonLoadersForGlobalStyle(options, includePaths, cssExtractLoader)
|
|
|
79
81
|
implementation: require('postcss'),
|
|
80
82
|
postcssOptions: postcssOptionsCreator(options, {
|
|
81
83
|
includePaths,
|
|
84
|
+
browserslistQueries,
|
|
82
85
|
}),
|
|
83
86
|
},
|
|
84
87
|
},
|
|
85
88
|
];
|
|
86
89
|
}
|
|
87
|
-
function postcssOptionsCreator(options, { includePaths, forCssModules = false, }) {
|
|
90
|
+
function postcssOptionsCreator(options, { includePaths, forCssModules = false, browserslistQueries, }) {
|
|
88
91
|
const hashFormat = (0, hash_format_1.getOutputHashFormat)(options.outputHashing);
|
|
89
92
|
// PostCSS options depend on the rspack loader, but we need to set the `config` path as a string due to this check:
|
|
90
93
|
// https://github.com/webpack-contrib/postcss-loader/blob/0d342b1/src/utils.js#L36
|
|
@@ -110,8 +113,11 @@ function postcssOptionsCreator(options, { includePaths, forCssModules = false, }
|
|
|
110
113
|
publicPath: options.publicPath,
|
|
111
114
|
rebaseRootRelative: options.rebaseRootRelative,
|
|
112
115
|
}),
|
|
113
|
-
autoprefixer(),
|
|
114
116
|
]),
|
|
117
|
+
// Without the build's browsers, autoprefixer reads browserslist next to each file.
|
|
118
|
+
...(forCssModules && !browserslistQueries
|
|
119
|
+
? []
|
|
120
|
+
: [autoprefixer({ overrideBrowserslist: browserslistQueries })]),
|
|
115
121
|
],
|
|
116
122
|
});
|
|
117
123
|
// If a path to postcssConfig is passed in, set it for app and all libs, otherwise
|
|
@@ -148,7 +148,7 @@ export interface NxAppRspackPluginOptions {
|
|
|
148
148
|
*/
|
|
149
149
|
progress?: boolean;
|
|
150
150
|
/**
|
|
151
|
-
* Add an additional chunk for the rspack runtime. Defaults to `true` when `target
|
|
151
|
+
* Add an additional chunk for the rspack runtime. Defaults to `true` when `target` runs in a browser or `ssr` is set.
|
|
152
152
|
*/
|
|
153
153
|
runtimeChunk?: boolean;
|
|
154
154
|
/**
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nx/rspack",
|
|
3
3
|
"description": "The Nx Plugin for Rspack contains executors and generators that support building applications using Rspack.",
|
|
4
|
-
"version": "24.0.
|
|
4
|
+
"version": "24.0.2",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"files": [
|
|
7
7
|
"dist",
|
|
@@ -159,9 +159,9 @@
|
|
|
159
159
|
}
|
|
160
160
|
},
|
|
161
161
|
"dependencies": {
|
|
162
|
-
"@nx/devkit": "24.0.
|
|
163
|
-
"@nx/js": "24.0.
|
|
164
|
-
"@nx/web": "24.0.
|
|
162
|
+
"@nx/devkit": "24.0.2",
|
|
163
|
+
"@nx/js": "24.0.2",
|
|
164
|
+
"@nx/web": "24.0.2",
|
|
165
165
|
"@phenomnomnominal/tsquery": "~6.2.0",
|
|
166
166
|
"autoprefixer": "^10.4.9",
|
|
167
167
|
"browserslist": "^4.26.0",
|
|
@@ -186,8 +186,8 @@
|
|
|
186
186
|
"webpack-node-externals": "^3.0.0"
|
|
187
187
|
},
|
|
188
188
|
"devDependencies": {
|
|
189
|
-
"nx": "24.0.
|
|
190
|
-
"@nx/nest": "24.0.
|
|
189
|
+
"nx": "24.0.2",
|
|
190
|
+
"@nx/nest": "24.0.2",
|
|
191
191
|
"@rspack/cli": "^2.0.4"
|
|
192
192
|
},
|
|
193
193
|
"peerDependencies": {
|