@nx/rspack 20.1.0-beta.1 → 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/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": "20.1.0-beta.
|
|
4
|
+
"version": "20.1.0-beta.2",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -24,24 +24,31 @@
|
|
|
24
24
|
"generators": "./generators.json",
|
|
25
25
|
"executors": "./executors.json",
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@nx/js": "20.1.0-beta.
|
|
28
|
-
"@nx/devkit": "20.1.0-beta.
|
|
29
|
-
"@nx/web": "20.1.0-beta.
|
|
27
|
+
"@nx/js": "20.1.0-beta.2",
|
|
28
|
+
"@nx/devkit": "20.1.0-beta.2",
|
|
29
|
+
"@nx/web": "20.1.0-beta.2",
|
|
30
30
|
"@phenomnomnominal/tsquery": "~5.0.1",
|
|
31
|
+
"@rspack/core": "^1.0.4",
|
|
32
|
+
"@rspack/dev-server": "^1.0.4",
|
|
33
|
+
"@rspack/plugin-react-refresh": "^1.0.0",
|
|
34
|
+
"autoprefixer": "^10.4.9",
|
|
35
|
+
"chalk": "~4.1.0",
|
|
36
|
+
"css-loader": "^6.4.0",
|
|
31
37
|
"enquirer": "~2.3.6",
|
|
32
38
|
"express": "^4.19.2",
|
|
33
39
|
"http-proxy-middleware": "^3.0.3",
|
|
34
40
|
"less-loader": "11.1.0",
|
|
35
41
|
"license-webpack-plugin": "^4.0.2",
|
|
42
|
+
"loader-utils": "^2.0.3",
|
|
43
|
+
"sass": "^1.42.1",
|
|
36
44
|
"sass-loader": "^12.2.0",
|
|
37
|
-
"
|
|
45
|
+
"style-loader": "^3.3.0",
|
|
46
|
+
"postcss-import": "~14.1.0",
|
|
38
47
|
"postcss-loader": "^8.1.1",
|
|
39
|
-
"
|
|
40
|
-
"@rspack/dev-server": "^1.0.4",
|
|
41
|
-
"@rspack/plugin-react-refresh": "^1.0.0",
|
|
42
|
-
"chalk": "~4.1.0",
|
|
48
|
+
"postcss": "^8.4.38",
|
|
43
49
|
"tsconfig-paths": "^4.1.2",
|
|
44
|
-
"tslib": "^2.3.0"
|
|
50
|
+
"tslib": "^2.3.0",
|
|
51
|
+
"webpack-subresource-integrity": "^5.1.0"
|
|
45
52
|
},
|
|
46
53
|
"peerDependencies": {
|
|
47
54
|
"@module-federation/enhanced": "~0.6.0",
|
|
@@ -6,8 +6,10 @@ export interface RspackExecutorSchema {
|
|
|
6
6
|
index?: string;
|
|
7
7
|
tsConfig?: string;
|
|
8
8
|
typeCheck?: boolean;
|
|
9
|
+
skipTypeChecking?: boolean;
|
|
9
10
|
outputPath?: string;
|
|
10
11
|
outputFileName?: string;
|
|
12
|
+
index?: string;
|
|
11
13
|
indexHtml?: string;
|
|
12
14
|
mode?: Mode;
|
|
13
15
|
watch?: boolean;
|
|
@@ -23,6 +25,13 @@ export interface RspackExecutorSchema {
|
|
|
23
25
|
generatePackageJson?: boolean;
|
|
24
26
|
}
|
|
25
27
|
|
|
28
|
+
export interface AssetGlobPattern {
|
|
29
|
+
glob: string;
|
|
30
|
+
input: string;
|
|
31
|
+
output: string;
|
|
32
|
+
ignore?: string[];
|
|
33
|
+
}
|
|
34
|
+
|
|
26
35
|
export interface FileReplacement {
|
|
27
36
|
replace: string;
|
|
28
37
|
with: string;
|
|
@@ -32,3 +41,11 @@ export interface OptimizationOptions {
|
|
|
32
41
|
scripts: boolean;
|
|
33
42
|
styles: boolean;
|
|
34
43
|
}
|
|
44
|
+
|
|
45
|
+
export interface NormalizedRspackExecutorSchema extends RspackExecutorSchema {
|
|
46
|
+
outputFileName: string;
|
|
47
|
+
assets: AssetGlobPattern[];
|
|
48
|
+
root: string;
|
|
49
|
+
projectRoot: string;
|
|
50
|
+
sourceRoot: string;
|
|
51
|
+
}
|
|
@@ -26,15 +26,13 @@
|
|
|
26
26
|
"type": "string",
|
|
27
27
|
"description": "The tsconfig file to build the project."
|
|
28
28
|
},
|
|
29
|
-
"
|
|
29
|
+
"skipTypeChecking": {
|
|
30
|
+
"alias": "typeCheck",
|
|
30
31
|
"type": "boolean",
|
|
31
|
-
"description": "Skip the type checking."
|
|
32
|
-
},
|
|
33
|
-
"indexHtml": {
|
|
34
|
-
"type": "string",
|
|
35
|
-
"description": "The path to the index.html file."
|
|
32
|
+
"description": "Skip the type checking. Default is `false`."
|
|
36
33
|
},
|
|
37
34
|
"index": {
|
|
35
|
+
"alias": "indexHtml",
|
|
38
36
|
"type": "string",
|
|
39
37
|
"description": "HTML File which will be contain the application.",
|
|
40
38
|
"x-completion-type": "file",
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { type Configuration } from '@rspack/core';
|
|
2
|
+
import { NormalizedNxAppRspackPluginOptions } from './models';
|
|
3
|
+
export declare function applyWebConfig(options: NormalizedNxAppRspackPluginOptions, config?: Configuration, { useNormalizedEntry, }?: {
|
|
4
|
+
useNormalizedEntry?: boolean;
|
|
5
|
+
}): void;
|
|
@@ -0,0 +1,383 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.applyWebConfig = applyWebConfig;
|
|
4
|
+
const core_1 = require("@rspack/core");
|
|
5
|
+
const instantiate_script_plugins_1 = require("./instantiate-script-plugins");
|
|
6
|
+
const path_1 = require("path");
|
|
7
|
+
const webpack_subresource_integrity_1 = require("webpack-subresource-integrity");
|
|
8
|
+
const hash_format_1 = require("./hash-format");
|
|
9
|
+
const normalize_entry_1 = require("./normalize-entry");
|
|
10
|
+
const stylesheet_loaders_1 = require("./loaders/stylesheet-loaders");
|
|
11
|
+
function applyWebConfig(options, config = {}, { useNormalizedEntry, } = {}) {
|
|
12
|
+
if (global.NX_GRAPH_CREATION)
|
|
13
|
+
return;
|
|
14
|
+
// Defaults that was applied from executor schema previously.
|
|
15
|
+
options.runtimeChunk ??= true; // need this for HMR and other things to work
|
|
16
|
+
options.extractCss ??= true;
|
|
17
|
+
options.generateIndexHtml ??= true;
|
|
18
|
+
options.index = options.index
|
|
19
|
+
? (0, path_1.join)(options.root, options.index)
|
|
20
|
+
: (0, path_1.join)(options.root, options.projectGraph.nodes[options.projectName].data.sourceRoot, 'index.html');
|
|
21
|
+
options.styles ??= [];
|
|
22
|
+
options.scripts ??= [];
|
|
23
|
+
const isProd = process.env.NODE_ENV === 'production' || options.mode === 'production';
|
|
24
|
+
const plugins = [
|
|
25
|
+
new core_1.EnvironmentPlugin({
|
|
26
|
+
NODE_ENV: isProd ? 'production' : 'development',
|
|
27
|
+
}),
|
|
28
|
+
];
|
|
29
|
+
const stylesOptimization = typeof options.optimization === 'object'
|
|
30
|
+
? options.optimization.styles
|
|
31
|
+
: options.optimization;
|
|
32
|
+
if (Array.isArray(options.scripts)) {
|
|
33
|
+
plugins.push(...(0, instantiate_script_plugins_1.instantiateScriptPlugins)(options));
|
|
34
|
+
}
|
|
35
|
+
if (options.index && options.generateIndexHtml) {
|
|
36
|
+
plugins.push(new core_1.HtmlRspackPlugin({
|
|
37
|
+
template: options.index,
|
|
38
|
+
sri: options.subresourceIntegrity ? 'sha256' : undefined,
|
|
39
|
+
...(options.baseHref ? { base: { href: options.baseHref } } : {}),
|
|
40
|
+
}));
|
|
41
|
+
}
|
|
42
|
+
if (options.subresourceIntegrity) {
|
|
43
|
+
plugins.push(new webpack_subresource_integrity_1.SubresourceIntegrityPlugin());
|
|
44
|
+
}
|
|
45
|
+
const minimizer = [];
|
|
46
|
+
if (stylesOptimization) {
|
|
47
|
+
minimizer.push(new core_1.LightningCssMinimizerRspackPlugin({
|
|
48
|
+
test: /\.(?:css|scss|sass|less|styl)$/,
|
|
49
|
+
}));
|
|
50
|
+
}
|
|
51
|
+
if (!options.ssr) {
|
|
52
|
+
plugins.push(new core_1.DefinePlugin(getClientEnvironment(process.env.NODE_ENV).stringified));
|
|
53
|
+
}
|
|
54
|
+
const entries = {};
|
|
55
|
+
const globalStylePaths = [];
|
|
56
|
+
// Determine hashing format.
|
|
57
|
+
const hashFormat = (0, hash_format_1.getOutputHashFormat)(options.outputHashing);
|
|
58
|
+
const includePaths = [];
|
|
59
|
+
if (options?.stylePreprocessorOptions?.includePaths?.length > 0) {
|
|
60
|
+
options.stylePreprocessorOptions.includePaths.forEach((includePath) => includePaths.push((0, path_1.resolve)(options.root, includePath)));
|
|
61
|
+
}
|
|
62
|
+
let lessPathOptions = {};
|
|
63
|
+
if (includePaths.length > 0) {
|
|
64
|
+
lessPathOptions = {
|
|
65
|
+
paths: includePaths,
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
// Process global styles.
|
|
69
|
+
if (options.styles.length > 0) {
|
|
70
|
+
(0, normalize_entry_1.normalizeExtraEntryPoints)(options.styles, 'styles').forEach((style) => {
|
|
71
|
+
const resolvedPath = style.input.startsWith('.')
|
|
72
|
+
? style.input
|
|
73
|
+
: (0, path_1.resolve)(options.root, style.input);
|
|
74
|
+
// Add style entry points.
|
|
75
|
+
if (entries[style.bundleName]) {
|
|
76
|
+
entries[style.bundleName].import.push(resolvedPath);
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
entries[style.bundleName] = { import: [resolvedPath] };
|
|
80
|
+
}
|
|
81
|
+
// Add global css paths.
|
|
82
|
+
globalStylePaths.push(resolvedPath);
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
const cssModuleRules = [
|
|
86
|
+
{
|
|
87
|
+
test: /\.module\.css$/,
|
|
88
|
+
exclude: globalStylePaths,
|
|
89
|
+
use: (0, stylesheet_loaders_1.getCommonLoadersForCssModules)(options, includePaths),
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
test: /\.module\.(scss|sass)$/,
|
|
93
|
+
exclude: globalStylePaths,
|
|
94
|
+
use: [
|
|
95
|
+
...(0, stylesheet_loaders_1.getCommonLoadersForCssModules)(options, includePaths),
|
|
96
|
+
{
|
|
97
|
+
loader: require.resolve('sass-loader'),
|
|
98
|
+
options: {
|
|
99
|
+
implementation: require('sass'),
|
|
100
|
+
sassOptions: {
|
|
101
|
+
fiber: false,
|
|
102
|
+
precision: 8,
|
|
103
|
+
includePaths,
|
|
104
|
+
},
|
|
105
|
+
},
|
|
106
|
+
},
|
|
107
|
+
],
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
test: /\.module\.less$/,
|
|
111
|
+
exclude: globalStylePaths,
|
|
112
|
+
use: [
|
|
113
|
+
...(0, stylesheet_loaders_1.getCommonLoadersForCssModules)(options, includePaths),
|
|
114
|
+
{
|
|
115
|
+
loader: require.resolve('less-loader'),
|
|
116
|
+
options: {
|
|
117
|
+
lessOptions: {
|
|
118
|
+
paths: includePaths,
|
|
119
|
+
},
|
|
120
|
+
},
|
|
121
|
+
},
|
|
122
|
+
],
|
|
123
|
+
},
|
|
124
|
+
{
|
|
125
|
+
test: /\.module\.styl$/,
|
|
126
|
+
exclude: globalStylePaths,
|
|
127
|
+
use: [
|
|
128
|
+
...(0, stylesheet_loaders_1.getCommonLoadersForCssModules)(options, includePaths),
|
|
129
|
+
{
|
|
130
|
+
loader: (0, path_1.join)(__dirname, '../../../utils/webpack/deprecated-stylus-loader.js'),
|
|
131
|
+
options: {
|
|
132
|
+
stylusOptions: {
|
|
133
|
+
include: includePaths,
|
|
134
|
+
},
|
|
135
|
+
},
|
|
136
|
+
},
|
|
137
|
+
],
|
|
138
|
+
},
|
|
139
|
+
];
|
|
140
|
+
const globalCssRules = [
|
|
141
|
+
{
|
|
142
|
+
test: /\.css$/,
|
|
143
|
+
exclude: globalStylePaths,
|
|
144
|
+
use: (0, stylesheet_loaders_1.getCommonLoadersForGlobalCss)(options, includePaths),
|
|
145
|
+
},
|
|
146
|
+
{
|
|
147
|
+
test: /\.scss$|\.sass$/,
|
|
148
|
+
exclude: globalStylePaths,
|
|
149
|
+
use: [
|
|
150
|
+
...(0, stylesheet_loaders_1.getCommonLoadersForGlobalCss)(options, includePaths),
|
|
151
|
+
{
|
|
152
|
+
loader: require.resolve('sass-loader'),
|
|
153
|
+
options: {
|
|
154
|
+
implementation: require('sass'),
|
|
155
|
+
sourceMap: !!options.sourceMap,
|
|
156
|
+
sassOptions: {
|
|
157
|
+
fiber: false,
|
|
158
|
+
// bootstrap-sass requires a minimum precision of 8
|
|
159
|
+
precision: 8,
|
|
160
|
+
includePaths,
|
|
161
|
+
},
|
|
162
|
+
},
|
|
163
|
+
},
|
|
164
|
+
],
|
|
165
|
+
},
|
|
166
|
+
{
|
|
167
|
+
test: /\.less$/,
|
|
168
|
+
exclude: globalStylePaths,
|
|
169
|
+
use: [
|
|
170
|
+
...(0, stylesheet_loaders_1.getCommonLoadersForGlobalCss)(options, includePaths),
|
|
171
|
+
{
|
|
172
|
+
loader: require.resolve('less-loader'),
|
|
173
|
+
options: {
|
|
174
|
+
sourceMap: !!options.sourceMap,
|
|
175
|
+
lessOptions: {
|
|
176
|
+
javascriptEnabled: true,
|
|
177
|
+
...lessPathOptions,
|
|
178
|
+
},
|
|
179
|
+
},
|
|
180
|
+
},
|
|
181
|
+
],
|
|
182
|
+
},
|
|
183
|
+
{
|
|
184
|
+
test: /\.styl$/,
|
|
185
|
+
exclude: globalStylePaths,
|
|
186
|
+
use: [
|
|
187
|
+
...(0, stylesheet_loaders_1.getCommonLoadersForGlobalCss)(options, includePaths),
|
|
188
|
+
{
|
|
189
|
+
loader: (0, path_1.join)(__dirname, '../../../utils/webpack/deprecated-stylus-loader.js'),
|
|
190
|
+
options: {
|
|
191
|
+
sourceMap: !!options.sourceMap,
|
|
192
|
+
stylusOptions: {
|
|
193
|
+
include: includePaths,
|
|
194
|
+
},
|
|
195
|
+
},
|
|
196
|
+
},
|
|
197
|
+
],
|
|
198
|
+
},
|
|
199
|
+
];
|
|
200
|
+
const globalStyleRules = [
|
|
201
|
+
{
|
|
202
|
+
test: /\.css$/,
|
|
203
|
+
include: globalStylePaths,
|
|
204
|
+
use: (0, stylesheet_loaders_1.getCommonLoadersForGlobalStyle)(options, includePaths),
|
|
205
|
+
},
|
|
206
|
+
{
|
|
207
|
+
test: /\.scss$|\.sass$/,
|
|
208
|
+
include: globalStylePaths,
|
|
209
|
+
use: [
|
|
210
|
+
...(0, stylesheet_loaders_1.getCommonLoadersForGlobalStyle)(options, includePaths),
|
|
211
|
+
{
|
|
212
|
+
loader: require.resolve('sass-loader'),
|
|
213
|
+
options: {
|
|
214
|
+
implementation: require('sass'),
|
|
215
|
+
sourceMap: !!options.sourceMap,
|
|
216
|
+
sassOptions: {
|
|
217
|
+
fiber: false,
|
|
218
|
+
// bootstrap-sass requires a minimum precision of 8
|
|
219
|
+
precision: 8,
|
|
220
|
+
includePaths,
|
|
221
|
+
},
|
|
222
|
+
},
|
|
223
|
+
},
|
|
224
|
+
],
|
|
225
|
+
},
|
|
226
|
+
{
|
|
227
|
+
test: /\.less$/,
|
|
228
|
+
include: globalStylePaths,
|
|
229
|
+
use: [
|
|
230
|
+
...(0, stylesheet_loaders_1.getCommonLoadersForGlobalStyle)(options, includePaths),
|
|
231
|
+
{
|
|
232
|
+
loader: require.resolve('less-loader'),
|
|
233
|
+
options: {
|
|
234
|
+
sourceMap: !!options.sourceMap,
|
|
235
|
+
lessOptions: {
|
|
236
|
+
javascriptEnabled: true,
|
|
237
|
+
...lessPathOptions,
|
|
238
|
+
},
|
|
239
|
+
},
|
|
240
|
+
},
|
|
241
|
+
],
|
|
242
|
+
},
|
|
243
|
+
{
|
|
244
|
+
test: /\.styl$/,
|
|
245
|
+
include: globalStylePaths,
|
|
246
|
+
use: [
|
|
247
|
+
...(0, stylesheet_loaders_1.getCommonLoadersForGlobalStyle)(options, includePaths),
|
|
248
|
+
{
|
|
249
|
+
loader: (0, path_1.join)(__dirname, '../../../utils/webpack/deprecated-stylus-loader.js'),
|
|
250
|
+
options: {
|
|
251
|
+
sourceMap: !!options.sourceMap,
|
|
252
|
+
stylusOptions: {
|
|
253
|
+
include: includePaths,
|
|
254
|
+
},
|
|
255
|
+
},
|
|
256
|
+
},
|
|
257
|
+
],
|
|
258
|
+
},
|
|
259
|
+
];
|
|
260
|
+
const rules = [
|
|
261
|
+
{
|
|
262
|
+
test: /\.css$|\.scss$|\.sass$|\.less$|\.styl$/,
|
|
263
|
+
oneOf: [...cssModuleRules, ...globalCssRules, ...globalStyleRules],
|
|
264
|
+
},
|
|
265
|
+
];
|
|
266
|
+
if (options.extractCss) {
|
|
267
|
+
plugins.push(
|
|
268
|
+
// extract global css from js files into own css file
|
|
269
|
+
new core_1.CssExtractRspackPlugin({
|
|
270
|
+
filename: `[name]${hashFormat.extract}.css`,
|
|
271
|
+
}));
|
|
272
|
+
}
|
|
273
|
+
config.output = {
|
|
274
|
+
...(config.output ?? {}),
|
|
275
|
+
assetModuleFilename: '[name].[contenthash:20][ext]',
|
|
276
|
+
crossOriginLoading: options.subresourceIntegrity
|
|
277
|
+
? 'anonymous'
|
|
278
|
+
: false,
|
|
279
|
+
};
|
|
280
|
+
// In case users customize their webpack config with unsupported entry.
|
|
281
|
+
if (typeof config.entry === 'function')
|
|
282
|
+
throw new Error('Entry function is not supported. Use an object.');
|
|
283
|
+
if (typeof config.entry === 'string')
|
|
284
|
+
throw new Error('Entry string is not supported. Use an object.');
|
|
285
|
+
if (Array.isArray(config.entry))
|
|
286
|
+
throw new Error('Entry array is not supported. Use an object.');
|
|
287
|
+
Object.entries(entries).forEach(([entryName, entryData]) => {
|
|
288
|
+
if (useNormalizedEntry) {
|
|
289
|
+
config.entry[entryName] = { import: entryData.import };
|
|
290
|
+
}
|
|
291
|
+
else {
|
|
292
|
+
config.entry[entryName] = entryData.import;
|
|
293
|
+
}
|
|
294
|
+
});
|
|
295
|
+
config.optimization = {
|
|
296
|
+
...(config.optimization ?? {}),
|
|
297
|
+
minimizer: [...(config.optimization?.minimizer ?? []), ...minimizer],
|
|
298
|
+
emitOnErrors: false,
|
|
299
|
+
moduleIds: 'deterministic',
|
|
300
|
+
runtimeChunk: options.runtimeChunk ? { name: 'runtime' } : false,
|
|
301
|
+
splitChunks: {
|
|
302
|
+
defaultSizeTypes: config.optimization?.splitChunks !== false
|
|
303
|
+
? config.optimization?.splitChunks?.defaultSizeTypes
|
|
304
|
+
: ['...'],
|
|
305
|
+
maxAsyncRequests: Infinity,
|
|
306
|
+
cacheGroups: {
|
|
307
|
+
default: !!options.commonChunk && {
|
|
308
|
+
chunks: 'async',
|
|
309
|
+
minChunks: 2,
|
|
310
|
+
priority: 10,
|
|
311
|
+
},
|
|
312
|
+
common: !!options.commonChunk && {
|
|
313
|
+
name: 'common',
|
|
314
|
+
chunks: 'async',
|
|
315
|
+
minChunks: 2,
|
|
316
|
+
enforce: true,
|
|
317
|
+
priority: 5,
|
|
318
|
+
},
|
|
319
|
+
vendors: false,
|
|
320
|
+
vendor: !!options.vendorChunk && {
|
|
321
|
+
name: 'vendor',
|
|
322
|
+
chunks: (chunk) => chunk.name === 'main',
|
|
323
|
+
enforce: true,
|
|
324
|
+
test: /[\\/]node_modules[\\/]/,
|
|
325
|
+
},
|
|
326
|
+
},
|
|
327
|
+
},
|
|
328
|
+
};
|
|
329
|
+
config.resolve.mainFields = ['browser', 'module', 'main'];
|
|
330
|
+
config.module = {
|
|
331
|
+
...(config.module ?? {}),
|
|
332
|
+
rules: [
|
|
333
|
+
...(config.module.rules ?? []),
|
|
334
|
+
// Images: Inline small images, and emit a separate file otherwise.
|
|
335
|
+
{
|
|
336
|
+
test: /\.(avif|bmp|gif|ico|jpe?g|png|webp)$/,
|
|
337
|
+
type: 'asset',
|
|
338
|
+
parser: {
|
|
339
|
+
dataUrlCondition: {
|
|
340
|
+
maxSize: 10_000, // 10 kB
|
|
341
|
+
},
|
|
342
|
+
},
|
|
343
|
+
},
|
|
344
|
+
// SVG: same as image but we need to separate it so it can be swapped for SVGR in the React plugin.
|
|
345
|
+
{
|
|
346
|
+
test: /\.svg$/,
|
|
347
|
+
type: 'asset',
|
|
348
|
+
parser: {
|
|
349
|
+
dataUrlCondition: {
|
|
350
|
+
maxSize: 10_000, // 10 kB
|
|
351
|
+
},
|
|
352
|
+
},
|
|
353
|
+
},
|
|
354
|
+
// Fonts: Emit separate file and export the URL.
|
|
355
|
+
{
|
|
356
|
+
test: /\.(eot|otf|ttf|woff|woff2)$/,
|
|
357
|
+
type: 'asset/resource',
|
|
358
|
+
},
|
|
359
|
+
...rules,
|
|
360
|
+
],
|
|
361
|
+
};
|
|
362
|
+
config.plugins ??= [];
|
|
363
|
+
config.plugins.push(...plugins);
|
|
364
|
+
}
|
|
365
|
+
function getClientEnvironment(mode) {
|
|
366
|
+
// Grab NODE_ENV and NX_PUBLIC_* environment variables and prepare them to be
|
|
367
|
+
// injected into the application via DefinePlugin in webpack configuration.
|
|
368
|
+
const nxPublicKeyRegex = /^NX_PUBLIC_/i;
|
|
369
|
+
const raw = Object.keys(process.env)
|
|
370
|
+
.filter((key) => nxPublicKeyRegex.test(key))
|
|
371
|
+
.reduce((env, key) => {
|
|
372
|
+
env[key] = process.env[key];
|
|
373
|
+
return env;
|
|
374
|
+
}, {});
|
|
375
|
+
// Stringify all values so we can feed into webpack DefinePlugin
|
|
376
|
+
const stringified = {
|
|
377
|
+
'process.env': Object.keys(raw).reduce((env, key) => {
|
|
378
|
+
env[key] = JSON.stringify(raw[key]);
|
|
379
|
+
return env;
|
|
380
|
+
}, {}),
|
|
381
|
+
};
|
|
382
|
+
return { stringified };
|
|
383
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getCSSModuleLocalIdent(ctx: any, localIdentName: any, localName: any, options: any): any;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getCSSModuleLocalIdent = getCSSModuleLocalIdent;
|
|
4
|
+
const path_1 = require("path");
|
|
5
|
+
const loader_utils_1 = require("loader-utils");
|
|
6
|
+
function getCSSModuleLocalIdent(ctx, localIdentName, localName, options) {
|
|
7
|
+
// Use the filename or folder name, based on some uses the index.js / index.module.(css|scss|sass) project style
|
|
8
|
+
const fileNameOrFolder = ctx.resourcePath.match(/index\.module\.(css|scss|sass)$/)
|
|
9
|
+
? '[folder]'
|
|
10
|
+
: '[name]';
|
|
11
|
+
// Create a hash based on a the file location and class name. Will be unique across a project, and close to globally unique.
|
|
12
|
+
const hash = (0, loader_utils_1.getHashDigest)(path_1.posix.relative(ctx.rootContext, ctx.resourcePath) + localName, 'md5', 'base64', 5);
|
|
13
|
+
// Use loaderUtils to find the file or folder name
|
|
14
|
+
const className = (0, loader_utils_1.interpolateName)(ctx, `${fileNameOrFolder}_${localName}__${hash}`, options);
|
|
15
|
+
// Remove the .module that appears in every classname when based on the file and replace all "." with "_".
|
|
16
|
+
return className.replace('.module_', '_').replace(/\./g, '_');
|
|
17
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getOutputHashFormat = getOutputHashFormat;
|
|
4
|
+
function getOutputHashFormat(option, length = 20) {
|
|
5
|
+
const hashFormats = {
|
|
6
|
+
none: { chunk: '', extract: '', file: '', script: '' },
|
|
7
|
+
media: { chunk: '', extract: '', file: `.[hash:${length}]`, script: '' },
|
|
8
|
+
bundles: {
|
|
9
|
+
chunk: `.[chunkhash:${length}]`,
|
|
10
|
+
extract: `.[contenthash:${length}]`,
|
|
11
|
+
file: '',
|
|
12
|
+
script: `.[contenthash:${length}]`,
|
|
13
|
+
},
|
|
14
|
+
all: {
|
|
15
|
+
chunk: `.[chunkhash:${length}]`,
|
|
16
|
+
extract: `.[contenthash:${length}]`,
|
|
17
|
+
file: `.[contenthash:${length}]`,
|
|
18
|
+
script: `.[contenthash:${length}]`,
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
return hashFormats[option] || hashFormats['none'];
|
|
22
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.instantiateScriptPlugins = instantiateScriptPlugins;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const path = tslib_1.__importStar(require("path"));
|
|
6
|
+
const hash_format_1 = require("./hash-format");
|
|
7
|
+
const scripts_rspack_plugin_1 = require("./plugins/scripts-rspack-plugin");
|
|
8
|
+
const normalize_entry_1 = require("./normalize-entry");
|
|
9
|
+
function instantiateScriptPlugins(options) {
|
|
10
|
+
// process global scripts
|
|
11
|
+
const globalScriptsByBundleName = (0, normalize_entry_1.normalizeExtraEntryPoints)(options.scripts || [], 'scripts').reduce((prev, curr) => {
|
|
12
|
+
const bundleName = curr.bundleName;
|
|
13
|
+
const resolvedPath = path.resolve(options.root, curr.input);
|
|
14
|
+
const existingEntry = prev.find((el) => el.bundleName === bundleName);
|
|
15
|
+
if (existingEntry) {
|
|
16
|
+
existingEntry.paths.push(resolvedPath);
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
prev.push({
|
|
20
|
+
inject: curr.inject,
|
|
21
|
+
bundleName,
|
|
22
|
+
paths: [resolvedPath],
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
return prev;
|
|
26
|
+
}, []);
|
|
27
|
+
const hashFormat = (0, hash_format_1.getOutputHashFormat)(options.outputHashing);
|
|
28
|
+
const plugins = [];
|
|
29
|
+
// Add a new asset for each entry.
|
|
30
|
+
globalScriptsByBundleName.forEach((script) => {
|
|
31
|
+
const hash = script.inject ? hashFormat.script : '';
|
|
32
|
+
const bundleName = script.bundleName;
|
|
33
|
+
plugins.push(new scripts_rspack_plugin_1.ScriptsRspackPlugin({
|
|
34
|
+
name: bundleName,
|
|
35
|
+
sourceMap: !!options.sourceMap,
|
|
36
|
+
filename: `${path.basename(bundleName)}${hash}.js`,
|
|
37
|
+
scripts: script.paths,
|
|
38
|
+
basePath: options.sourceRoot,
|
|
39
|
+
}));
|
|
40
|
+
});
|
|
41
|
+
return plugins;
|
|
42
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { getCSSModuleLocalIdent } from '../get-css-module-local-ident';
|
|
2
|
+
interface PostcssOptions {
|
|
3
|
+
(loader: any): any;
|
|
4
|
+
config?: string;
|
|
5
|
+
}
|
|
6
|
+
export declare function getCommonLoadersForCssModules(options: any, includePaths: string[]): ({
|
|
7
|
+
loader: string;
|
|
8
|
+
options?: undefined;
|
|
9
|
+
} | {
|
|
10
|
+
loader: string;
|
|
11
|
+
options: {
|
|
12
|
+
modules: {
|
|
13
|
+
mode: string;
|
|
14
|
+
getLocalIdent: typeof getCSSModuleLocalIdent;
|
|
15
|
+
};
|
|
16
|
+
importLoaders: number;
|
|
17
|
+
implementation?: undefined;
|
|
18
|
+
postcssOptions?: undefined;
|
|
19
|
+
};
|
|
20
|
+
} | {
|
|
21
|
+
loader: string;
|
|
22
|
+
options: {
|
|
23
|
+
implementation: any;
|
|
24
|
+
postcssOptions: PostcssOptions;
|
|
25
|
+
modules?: undefined;
|
|
26
|
+
importLoaders?: undefined;
|
|
27
|
+
};
|
|
28
|
+
})[];
|
|
29
|
+
export declare function getCommonLoadersForGlobalCss(options: any, includePaths: string[]): ({
|
|
30
|
+
loader: string;
|
|
31
|
+
options?: undefined;
|
|
32
|
+
} | {
|
|
33
|
+
loader: string;
|
|
34
|
+
options: {
|
|
35
|
+
url: boolean;
|
|
36
|
+
implementation?: undefined;
|
|
37
|
+
postcssOptions?: undefined;
|
|
38
|
+
};
|
|
39
|
+
} | {
|
|
40
|
+
loader: string;
|
|
41
|
+
options: {
|
|
42
|
+
implementation: any;
|
|
43
|
+
postcssOptions: PostcssOptions;
|
|
44
|
+
url?: undefined;
|
|
45
|
+
};
|
|
46
|
+
})[];
|
|
47
|
+
export declare function getCommonLoadersForGlobalStyle(options: any, includePaths: string[]): ({
|
|
48
|
+
loader: string;
|
|
49
|
+
options: {
|
|
50
|
+
esModule: boolean;
|
|
51
|
+
url?: undefined;
|
|
52
|
+
implementation?: undefined;
|
|
53
|
+
postcssOptions?: undefined;
|
|
54
|
+
};
|
|
55
|
+
} | {
|
|
56
|
+
loader: string;
|
|
57
|
+
options: {
|
|
58
|
+
url: boolean;
|
|
59
|
+
esModule?: undefined;
|
|
60
|
+
implementation?: undefined;
|
|
61
|
+
postcssOptions?: undefined;
|
|
62
|
+
};
|
|
63
|
+
} | {
|
|
64
|
+
loader: string;
|
|
65
|
+
options: {
|
|
66
|
+
implementation: any;
|
|
67
|
+
postcssOptions: PostcssOptions;
|
|
68
|
+
esModule?: undefined;
|
|
69
|
+
url?: undefined;
|
|
70
|
+
};
|
|
71
|
+
})[];
|
|
72
|
+
export {};
|