@nx/webpack 16.8.0-beta.3 → 16.8.0-beta.5
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 +5 -7
- package/src/executors/dev-server/dev-server.impl.js +36 -38
- package/src/executors/dev-server/lib/get-dev-server-config.js +1 -2
- package/src/executors/ssr-dev-server/ssr-dev-server.impl.js +27 -41
- package/src/executors/webpack/lib/normalize-options.js +22 -7
- package/src/executors/webpack/lib/run-webpack.js +1 -2
- package/src/executors/webpack/webpack.impl.js +79 -85
- package/src/generators/configuration/configuration.js +34 -24
- package/src/generators/init/init.js +26 -29
- package/src/migrations/update-15-0-0/add-babel-inputs.js +3 -6
- package/src/migrations/update-15-4-5/remove-es2015-polyfills-option.js +12 -16
- package/src/migrations/update-15-6-3/webpack-config-setup.js +55 -59
- package/src/migrations/update-15-7-2/add-babelUpwardRootMode-flag.js +10 -13
- package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.js +3 -6
- package/src/plugins/generate-package-json-plugin.js +3 -3
- package/src/plugins/webpack-nx-build-coordination-plugin.d.ts +3 -1
- package/src/plugins/webpack-nx-build-coordination-plugin.js +55 -53
- package/src/utils/config.js +6 -9
- package/src/utils/create-copy-plugin.js +1 -2
- package/src/utils/web-babel-loader.js +1 -13
- package/src/utils/webpack/normalize-entry.js +2 -3
- package/src/utils/webpack/plugins/postcss-cli-resources.js +13 -16
- package/src/utils/webpack/plugins/scripts-webpack-plugin.js +1 -2
- package/src/utils/with-nx.js +69 -22
- package/src/utils/with-web.js +34 -13
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.PostcssCliResources = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
4
|
const loader_utils_1 = require("loader-utils");
|
|
6
5
|
const path = require("path");
|
|
7
6
|
const url = require("node:url");
|
|
@@ -16,21 +15,19 @@ function wrapUrl(url) {
|
|
|
16
15
|
}
|
|
17
16
|
return `url(${wrappedUrl})`;
|
|
18
17
|
}
|
|
19
|
-
function resolve(file, base, resolver) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}
|
|
27
|
-
});
|
|
18
|
+
async function resolve(file, base, resolver) {
|
|
19
|
+
try {
|
|
20
|
+
return await resolver(`./${file}`, base);
|
|
21
|
+
}
|
|
22
|
+
catch {
|
|
23
|
+
return resolver(file, base);
|
|
24
|
+
}
|
|
28
25
|
}
|
|
29
26
|
module.exports.postcss = true;
|
|
30
27
|
function PostcssCliResources(options) {
|
|
31
28
|
const { deployUrl = '', baseHref = '', resourcesOutputPath = '', rebaseRootRelative = false, filename, loader, } = options;
|
|
32
29
|
const dedupeSlashes = (url) => url.replace(/\/\/+/g, '/');
|
|
33
|
-
const process = (inputUrl, context, resourceCache) =>
|
|
30
|
+
const process = async (inputUrl, context, resourceCache) => {
|
|
34
31
|
// If root-relative, absolute or protocol relative url, leave as is
|
|
35
32
|
if (/^((?:\w+:)?\/\/|data:|chrome:|#)/.test(inputUrl)) {
|
|
36
33
|
return inputUrl;
|
|
@@ -80,7 +77,7 @@ function PostcssCliResources(options) {
|
|
|
80
77
|
resolve(result);
|
|
81
78
|
});
|
|
82
79
|
});
|
|
83
|
-
const result =
|
|
80
|
+
const result = await resolve(pathname, context, resolver);
|
|
84
81
|
return new Promise((resolve, reject) => {
|
|
85
82
|
loader.fs.readFile(result, (err, content) => {
|
|
86
83
|
if (err) {
|
|
@@ -105,7 +102,7 @@ function PostcssCliResources(options) {
|
|
|
105
102
|
resolve(outputUrl);
|
|
106
103
|
});
|
|
107
104
|
});
|
|
108
|
-
}
|
|
105
|
+
};
|
|
109
106
|
return {
|
|
110
107
|
postcssPlugin: 'postcss-cli-resources',
|
|
111
108
|
Once(root) {
|
|
@@ -123,7 +120,7 @@ function PostcssCliResources(options) {
|
|
|
123
120
|
return;
|
|
124
121
|
}
|
|
125
122
|
const resourceCache = new Map();
|
|
126
|
-
return Promise.all(urlDeclarations.map((decl) =>
|
|
123
|
+
return Promise.all(urlDeclarations.map(async (decl) => {
|
|
127
124
|
const value = decl.value;
|
|
128
125
|
const urlRegex = /url\(\s*(?:"([^"]+)"|'([^']+)'|(.+?))\s*\)/g;
|
|
129
126
|
const segments = [];
|
|
@@ -138,7 +135,7 @@ function PostcssCliResources(options) {
|
|
|
138
135
|
const originalUrl = match[1] || match[2] || match[3];
|
|
139
136
|
let processedUrl;
|
|
140
137
|
try {
|
|
141
|
-
processedUrl =
|
|
138
|
+
processedUrl = await process(originalUrl, context, resourceCache);
|
|
142
139
|
}
|
|
143
140
|
catch (err) {
|
|
144
141
|
loader.emitError(decl.error(err.message, { word: originalUrl }));
|
|
@@ -162,7 +159,7 @@ function PostcssCliResources(options) {
|
|
|
162
159
|
if (modified) {
|
|
163
160
|
decl.value = segments.join('');
|
|
164
161
|
}
|
|
165
|
-
}))
|
|
162
|
+
}));
|
|
166
163
|
},
|
|
167
164
|
};
|
|
168
165
|
}
|
|
@@ -21,13 +21,12 @@ class ScriptsWebpackPlugin {
|
|
|
21
21
|
this.options = options;
|
|
22
22
|
}
|
|
23
23
|
shouldSkip(compilation, scripts) {
|
|
24
|
-
var _a;
|
|
25
24
|
if (this._lastBuildTime == undefined) {
|
|
26
25
|
this._lastBuildTime = Date.now();
|
|
27
26
|
return false;
|
|
28
27
|
}
|
|
29
28
|
for (let i = 0; i < scripts.length; i++) {
|
|
30
|
-
const scriptTime =
|
|
29
|
+
const scriptTime = compilation.fileTimestamps?.get(scripts[i]);
|
|
31
30
|
if (!scriptTime || scriptTime > this._lastBuildTime) {
|
|
32
31
|
this._lastBuildTime = Date.now();
|
|
33
32
|
return false;
|
package/src/utils/with-nx.js
CHANGED
|
@@ -57,11 +57,10 @@ const processed = new Set();
|
|
|
57
57
|
*/
|
|
58
58
|
function withNx(pluginOptions) {
|
|
59
59
|
return function configure(config, { options, context, }) {
|
|
60
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
61
60
|
if (processed.has(config))
|
|
62
61
|
return config;
|
|
63
62
|
const plugins = [];
|
|
64
|
-
if (!
|
|
63
|
+
if (!pluginOptions?.skipTypeChecking) {
|
|
65
64
|
plugins.push(new ForkTsCheckerWebpackPlugin({
|
|
66
65
|
typescript: {
|
|
67
66
|
configFile: options.tsConfig,
|
|
@@ -131,9 +130,14 @@ function withNx(pluginOptions) {
|
|
|
131
130
|
const chunkFilename = options.outputHashing
|
|
132
131
|
? `[name]${hashFormat.chunk}.js`
|
|
133
132
|
: '[name].js';
|
|
134
|
-
const updated =
|
|
133
|
+
const updated = {
|
|
134
|
+
...config,
|
|
135
|
+
context: context
|
|
135
136
|
? path.join(context.root, options.projectRoot)
|
|
136
|
-
: undefined,
|
|
137
|
+
: undefined,
|
|
138
|
+
target: options.target,
|
|
139
|
+
node: false,
|
|
140
|
+
mode:
|
|
137
141
|
// When the target is Node avoid any optimizations, such as replacing `process.env.NODE_ENV` with build time value.
|
|
138
142
|
options.target === 'node'
|
|
139
143
|
? 'none'
|
|
@@ -148,27 +152,55 @@ function withNx(pluginOptions) {
|
|
|
148
152
|
process.env.NODE_ENV === 'development' ||
|
|
149
153
|
process.env.NODE_ENV === 'production'
|
|
150
154
|
? process.env.NODE_ENV
|
|
151
|
-
: 'none',
|
|
155
|
+
: 'none',
|
|
156
|
+
devtool: options.sourceMap === 'hidden'
|
|
152
157
|
? 'hidden-source-map'
|
|
153
158
|
: options.sourceMap
|
|
154
159
|
? 'source-map'
|
|
155
|
-
: false,
|
|
156
|
-
|
|
160
|
+
: false,
|
|
161
|
+
entry,
|
|
162
|
+
output: {
|
|
163
|
+
...config.output,
|
|
164
|
+
libraryTarget: options.target === 'node' ? 'commonjs' : undefined,
|
|
165
|
+
path: options.outputPath,
|
|
166
|
+
filename,
|
|
167
|
+
chunkFilename,
|
|
168
|
+
hashFunction: 'xxhash64',
|
|
157
169
|
// Disabled for performance
|
|
158
|
-
pathinfo: false,
|
|
170
|
+
pathinfo: false,
|
|
159
171
|
// Use CJS for Node since it has the widest support.
|
|
160
|
-
scriptType: options.target === 'node' ? undefined : 'module'
|
|
172
|
+
scriptType: options.target === 'node' ? undefined : 'module',
|
|
173
|
+
},
|
|
174
|
+
watch: options.watch,
|
|
175
|
+
watchOptions: {
|
|
161
176
|
poll: options.poll,
|
|
162
|
-
},
|
|
163
|
-
|
|
177
|
+
},
|
|
178
|
+
profile: options.statsJson,
|
|
179
|
+
resolve: {
|
|
180
|
+
...config.resolve,
|
|
181
|
+
extensions: [...extensions, ...(config?.resolve?.extensions ?? [])],
|
|
182
|
+
alias: options.fileReplacements.reduce((aliases, replacement) => ({
|
|
183
|
+
...aliases,
|
|
184
|
+
[replacement.replace]: replacement.with,
|
|
185
|
+
}), {}),
|
|
186
|
+
plugins: [
|
|
187
|
+
...(config.resolve?.plugins ?? []),
|
|
164
188
|
new tsconfig_paths_webpack_plugin_1.TsconfigPathsPlugin({
|
|
165
189
|
configFile: options.tsConfig,
|
|
166
|
-
extensions: [...extensions, ...(
|
|
190
|
+
extensions: [...extensions, ...(config?.resolve?.extensions ?? [])],
|
|
167
191
|
mainFields,
|
|
168
192
|
}),
|
|
169
|
-
],
|
|
193
|
+
],
|
|
194
|
+
mainFields,
|
|
195
|
+
},
|
|
196
|
+
externals,
|
|
197
|
+
optimization: {
|
|
198
|
+
...config.optimization,
|
|
199
|
+
sideEffects: true,
|
|
200
|
+
minimize: typeof options.optimization === 'object'
|
|
170
201
|
? !!options.optimization.scripts
|
|
171
|
-
: !!options.optimization,
|
|
202
|
+
: !!options.optimization,
|
|
203
|
+
minimizer: [
|
|
172
204
|
options.compiler !== 'swc'
|
|
173
205
|
? new TerserPlugin({
|
|
174
206
|
parallel: true,
|
|
@@ -191,12 +223,24 @@ function withNx(pluginOptions) {
|
|
|
191
223
|
mangle: false,
|
|
192
224
|
},
|
|
193
225
|
}),
|
|
194
|
-
],
|
|
226
|
+
],
|
|
227
|
+
runtimeChunk: false,
|
|
228
|
+
concatenateModules: true,
|
|
229
|
+
},
|
|
230
|
+
performance: {
|
|
231
|
+
...config.performance,
|
|
232
|
+
hints: false,
|
|
233
|
+
},
|
|
234
|
+
experiments: { ...config.experiments, cacheUnaffected: true },
|
|
235
|
+
ignoreWarnings: [
|
|
195
236
|
(x) => IGNORED_WEBPACK_WARNINGS.some((r) => typeof x === 'string' ? r.test(x) : r.test(x.message)),
|
|
196
|
-
],
|
|
237
|
+
],
|
|
238
|
+
module: {
|
|
239
|
+
...config.module,
|
|
197
240
|
// Enabled for performance
|
|
198
|
-
unsafeCache: true,
|
|
199
|
-
|
|
241
|
+
unsafeCache: true,
|
|
242
|
+
rules: [
|
|
243
|
+
...(config?.module?.rules ?? []),
|
|
200
244
|
options.sourceMap && {
|
|
201
245
|
test: /\.js$/,
|
|
202
246
|
enforce: 'pre',
|
|
@@ -220,7 +264,10 @@ function withNx(pluginOptions) {
|
|
|
220
264
|
type: 'javascript/auto',
|
|
221
265
|
},
|
|
222
266
|
createLoaderFromCompiler(options),
|
|
223
|
-
].filter((r) => !!r)
|
|
267
|
+
].filter((r) => !!r),
|
|
268
|
+
},
|
|
269
|
+
plugins: (config.plugins ?? []).concat(plugins),
|
|
270
|
+
stats: {
|
|
224
271
|
hash: true,
|
|
225
272
|
timings: false,
|
|
226
273
|
cached: false,
|
|
@@ -239,14 +286,14 @@ function withNx(pluginOptions) {
|
|
|
239
286
|
errorDetails: !!options.verbose,
|
|
240
287
|
moduleTrace: !!options.verbose,
|
|
241
288
|
usedExports: !!options.verbose,
|
|
242
|
-
}
|
|
289
|
+
},
|
|
290
|
+
};
|
|
243
291
|
processed.add(updated);
|
|
244
292
|
return updated;
|
|
245
293
|
};
|
|
246
294
|
}
|
|
247
295
|
exports.withNx = withNx;
|
|
248
296
|
function createLoaderFromCompiler(options) {
|
|
249
|
-
var _a;
|
|
250
297
|
switch (options.compiler) {
|
|
251
298
|
case 'swc':
|
|
252
299
|
return {
|
|
@@ -299,7 +346,7 @@ function createLoaderFromCompiler(options) {
|
|
|
299
346
|
emitDecoratorMetadata: tsConfig.options.emitDecoratorMetadata,
|
|
300
347
|
isModern: true,
|
|
301
348
|
isTest: process.env.NX_CYPRESS_COMPONENT_TEST === 'true',
|
|
302
|
-
envName:
|
|
349
|
+
envName: process.env.BABEL_ENV ?? process.env.NODE_ENV,
|
|
303
350
|
cacheDirectory: true,
|
|
304
351
|
cacheCompression: false,
|
|
305
352
|
},
|
package/src/utils/with-web.js
CHANGED
|
@@ -24,10 +24,12 @@ const processed = new Set();
|
|
|
24
24
|
*/
|
|
25
25
|
function withWeb(pluginOptions = {}) {
|
|
26
26
|
return function configure(config, { options: executorOptions, context }) {
|
|
27
|
-
var _a, _b, _c;
|
|
28
27
|
if (processed.has(config))
|
|
29
28
|
return config;
|
|
30
|
-
const mergedOptions =
|
|
29
|
+
const mergedOptions = {
|
|
30
|
+
...executorOptions,
|
|
31
|
+
...pluginOptions,
|
|
32
|
+
};
|
|
31
33
|
const plugins = [];
|
|
32
34
|
const stylesOptimization = typeof mergedOptions.optimization === 'object'
|
|
33
35
|
? mergedOptions.optimization.styles
|
|
@@ -66,7 +68,7 @@ function withWeb(pluginOptions = {}) {
|
|
|
66
68
|
// Determine hashing format.
|
|
67
69
|
const hashFormat = (0, hash_format_1.getOutputHashFormat)(mergedOptions.outputHashing);
|
|
68
70
|
const includePaths = [];
|
|
69
|
-
if (
|
|
71
|
+
if (mergedOptions?.stylePreprocessorOptions?.includePaths?.length > 0) {
|
|
70
72
|
mergedOptions.stylePreprocessorOptions.includePaths.forEach((includePath) => includePaths.push(path.resolve(mergedOptions.root, includePath)));
|
|
71
73
|
}
|
|
72
74
|
let lessPathOptions = {};
|
|
@@ -180,7 +182,10 @@ function withWeb(pluginOptions = {}) {
|
|
|
180
182
|
loader: require.resolve('less-loader'),
|
|
181
183
|
options: {
|
|
182
184
|
sourceMap: !!mergedOptions.sourceMap,
|
|
183
|
-
lessOptions:
|
|
185
|
+
lessOptions: {
|
|
186
|
+
javascriptEnabled: true,
|
|
187
|
+
...lessPathOptions,
|
|
188
|
+
},
|
|
184
189
|
},
|
|
185
190
|
},
|
|
186
191
|
],
|
|
@@ -237,7 +242,10 @@ function withWeb(pluginOptions = {}) {
|
|
|
237
242
|
loader: require.resolve('less-loader'),
|
|
238
243
|
options: {
|
|
239
244
|
sourceMap: !!mergedOptions.sourceMap,
|
|
240
|
-
lessOptions:
|
|
245
|
+
lessOptions: {
|
|
246
|
+
javascriptEnabled: true,
|
|
247
|
+
...lessPathOptions,
|
|
248
|
+
},
|
|
241
249
|
},
|
|
242
250
|
},
|
|
243
251
|
],
|
|
@@ -270,9 +278,12 @@ function withWeb(pluginOptions = {}) {
|
|
|
270
278
|
new MiniCssExtractPlugin({
|
|
271
279
|
filename: `[name]${hashFormat.extract}.css`,
|
|
272
280
|
}));
|
|
273
|
-
config.output =
|
|
281
|
+
config.output = {
|
|
282
|
+
...config.output,
|
|
283
|
+
crossOriginLoading: mergedOptions.subresourceIntegrity
|
|
274
284
|
? 'anonymous'
|
|
275
|
-
: false
|
|
285
|
+
: false,
|
|
286
|
+
};
|
|
276
287
|
// In case users customize their webpack config with unsupported entry.
|
|
277
288
|
if (typeof config.entry === 'function')
|
|
278
289
|
throw new Error('Entry function is not supported. Use an object.');
|
|
@@ -280,8 +291,14 @@ function withWeb(pluginOptions = {}) {
|
|
|
280
291
|
throw new Error('Entry string is not supported. Use an object.');
|
|
281
292
|
if (Array.isArray(config.entry))
|
|
282
293
|
throw new Error('Entry array is not supported. Use an object.');
|
|
283
|
-
config.entry =
|
|
284
|
-
config.optimization =
|
|
294
|
+
config.entry = { ...config.entry, ...entry };
|
|
295
|
+
config.optimization = {
|
|
296
|
+
...config.optimization,
|
|
297
|
+
minimizer: [...config.optimization.minimizer, ...minimizer],
|
|
298
|
+
emitOnErrors: false,
|
|
299
|
+
moduleIds: 'deterministic',
|
|
300
|
+
runtimeChunk: mergedOptions.runtimeChunk ? 'single' : false,
|
|
301
|
+
splitChunks: {
|
|
285
302
|
maxAsyncRequests: Infinity,
|
|
286
303
|
cacheGroups: {
|
|
287
304
|
default: !!mergedOptions.commonChunk && {
|
|
@@ -304,11 +321,14 @@ function withWeb(pluginOptions = {}) {
|
|
|
304
321
|
test: /[\\/]node_modules[\\/]/,
|
|
305
322
|
},
|
|
306
323
|
},
|
|
307
|
-
}
|
|
324
|
+
},
|
|
325
|
+
};
|
|
308
326
|
config.plugins.push(...plugins);
|
|
309
327
|
config.resolve.mainFields = ['browser', 'module', 'main'];
|
|
310
|
-
config.module =
|
|
311
|
-
|
|
328
|
+
config.module = {
|
|
329
|
+
...config.module,
|
|
330
|
+
rules: [
|
|
331
|
+
...(config.module.rules ?? []),
|
|
312
332
|
// Images: Inline small images, and emit a separate file otherwise.
|
|
313
333
|
{
|
|
314
334
|
test: /\.(avif|bmp|gif|ico|jpe?g|png|webp)$/,
|
|
@@ -344,7 +364,8 @@ function withWeb(pluginOptions = {}) {
|
|
|
344
364
|
},
|
|
345
365
|
},
|
|
346
366
|
...rules,
|
|
347
|
-
]
|
|
367
|
+
],
|
|
368
|
+
};
|
|
348
369
|
processed.add(config);
|
|
349
370
|
return config;
|
|
350
371
|
};
|