@nx/webpack 17.0.2 → 17.0.4
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/LICENSE +1 -1
- package/README.md +9 -4
- package/generators.json +2 -2
- package/index.d.ts +3 -1
- package/index.js +7 -2
- package/migrations.json +6 -0
- package/package.json +6 -5
- package/plugin.d.ts +1 -0
- package/plugin.js +5 -0
- package/src/executors/dev-server/dev-server.impl.js +31 -17
- package/src/executors/dev-server/lib/get-dev-server-config.d.ts +2 -3
- package/src/executors/dev-server/lib/get-dev-server-config.js +18 -26
- package/src/executors/dev-server/schema.d.ts +8 -8
- package/src/executors/webpack/lib/normalize-options.d.ts +1 -2
- package/src/executors/webpack/lib/normalize-options.js +9 -53
- package/src/executors/webpack/schema.d.ts +10 -7
- package/src/executors/webpack/schema.json +30 -50
- package/src/executors/webpack/webpack.impl.js +36 -16
- package/src/generators/configuration/configuration.d.ts +3 -2
- package/src/generators/configuration/configuration.js +95 -23
- package/src/generators/configuration/schema.d.ts +1 -0
- package/src/generators/configuration/schema.json +1 -1
- package/src/generators/init/init.d.ts +1 -0
- package/src/generators/init/init.js +48 -23
- package/src/generators/init/schema.d.ts +4 -2
- package/src/generators/init/schema.json +18 -13
- package/src/migrations/update-17-2-1/webpack-config-setup.d.ts +2 -0
- package/src/migrations/update-17-2-1/webpack-config-setup.js +31 -0
- package/src/plugins/generate-package-json-plugin.d.ts +6 -4
- package/src/plugins/generate-package-json-plugin.js +11 -14
- package/src/plugins/nx-typescript-webpack-plugin/nx-tsconfig-paths-webpack-plugin.d.ts +8 -0
- package/src/plugins/nx-typescript-webpack-plugin/nx-tsconfig-paths-webpack-plugin.js +31 -0
- package/src/plugins/nx-webpack-plugin/lib/apply-base-config.d.ts +5 -0
- package/src/plugins/nx-webpack-plugin/lib/apply-base-config.js +318 -0
- package/src/plugins/nx-webpack-plugin/lib/apply-web-config.d.ts +5 -0
- package/src/plugins/nx-webpack-plugin/lib/apply-web-config.js +372 -0
- package/src/plugins/nx-webpack-plugin/lib/compiler-loaders.d.ts +53 -0
- package/src/plugins/nx-webpack-plugin/lib/compiler-loaders.js +78 -0
- package/src/plugins/nx-webpack-plugin/lib/get-terser-ecma-version.d.ts +1 -0
- package/src/plugins/nx-webpack-plugin/lib/get-terser-ecma-version.js +35 -0
- package/src/plugins/nx-webpack-plugin/lib/instantiate-script-plugins.d.ts +3 -0
- package/src/plugins/nx-webpack-plugin/lib/instantiate-script-plugins.js +42 -0
- package/src/plugins/nx-webpack-plugin/lib/normalize-options.d.ts +4 -0
- package/src/plugins/nx-webpack-plugin/lib/normalize-options.js +148 -0
- package/src/plugins/nx-webpack-plugin/lib/stylesheet-loaders.d.ts +73 -0
- package/src/plugins/nx-webpack-plugin/lib/stylesheet-loaders.js +117 -0
- package/src/plugins/nx-webpack-plugin/nx-webpack-plugin-options.d.ts +216 -0
- package/src/plugins/nx-webpack-plugin/nx-webpack-plugin-options.js +2 -0
- package/src/plugins/nx-webpack-plugin/nx-webpack-plugin.d.ts +17 -0
- package/src/plugins/nx-webpack-plugin/nx-webpack-plugin.js +48 -0
- package/src/plugins/plugin.d.ts +9 -0
- package/src/plugins/plugin.js +132 -0
- package/src/utils/config.d.ts +11 -6
- package/src/utils/config.js +48 -13
- package/src/utils/ensure-dependencies.d.ts +6 -0
- package/src/utils/ensure-dependencies.js +28 -0
- package/src/utils/get-client-environment.js +4 -1
- package/src/utils/has-plugin.d.ts +2 -0
- package/src/utils/has-plugin.js +11 -0
- package/src/utils/module-federation/dependencies.js +15 -3
- package/src/utils/module-federation/get-remotes-for-host.js +2 -2
- package/src/utils/module-federation/remotes.js +1 -1
- package/src/utils/module-federation/secondary-entry-points.js +1 -1
- package/src/utils/module-federation/typescript.js +14 -9
- package/src/utils/versions.d.ts +1 -0
- package/src/utils/versions.js +2 -1
- package/src/utils/webpack/deprecated-stylus-loader.js +2 -2
- package/src/utils/webpack/interpolate-env-variables-to-index.js +4 -1
- package/src/utils/webpack/plugins/postcss-cli-resources.js +2 -2
- package/src/utils/webpack/read-webpack-options.d.ts +10 -0
- package/src/utils/webpack/read-webpack-options.js +41 -0
- package/src/utils/webpack/resolve-user-defined-webpack-config.d.ts +3 -0
- package/src/utils/webpack/{custom-webpack.js → resolve-user-defined-webpack-config.js} +14 -8
- package/src/utils/with-nx.d.ts +4 -58
- package/src/utils/with-nx.js +22 -362
- package/src/utils/with-web.d.ts +2 -2
- package/src/utils/with-web.js +9 -488
- package/src/executors/webpack/lib/get-webpack-config.d.ts +0 -5
- package/src/executors/webpack/lib/get-webpack-config.js +0 -16
- package/src/utils/webpack/custom-webpack.d.ts +0 -2
|
@@ -0,0 +1,372 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.applyWebConfig = void 0;
|
|
4
|
+
const path = require("path");
|
|
5
|
+
const webpack_subresource_integrity_1 = require("webpack-subresource-integrity");
|
|
6
|
+
const webpack_1 = require("webpack");
|
|
7
|
+
const write_index_html_plugin_1 = require("../../write-index-html-plugin");
|
|
8
|
+
const hash_format_1 = require("../../../utils/hash-format");
|
|
9
|
+
const get_client_environment_1 = require("../../../utils/get-client-environment");
|
|
10
|
+
const normalize_entry_1 = require("../../../utils/webpack/normalize-entry");
|
|
11
|
+
const stylesheet_loaders_1 = require("./stylesheet-loaders");
|
|
12
|
+
const instantiate_script_plugins_1 = require("./instantiate-script-plugins");
|
|
13
|
+
const CssMinimizerPlugin = require("css-minimizer-webpack-plugin");
|
|
14
|
+
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
|
|
15
|
+
function applyWebConfig(options, config = {}, { useNormalizedEntry, } = {}) {
|
|
16
|
+
if (!process.env['NX_TASK_TARGET_PROJECT'])
|
|
17
|
+
return;
|
|
18
|
+
// Defaults that was applied from executor schema previously.
|
|
19
|
+
options.runtimeChunk ??= true; // need this for HMR and other things to work
|
|
20
|
+
options.extractCss ??= true;
|
|
21
|
+
options.generateIndexHtml ??= true;
|
|
22
|
+
options.styles ??= [];
|
|
23
|
+
options.scripts ??= [];
|
|
24
|
+
const plugins = [];
|
|
25
|
+
const stylesOptimization = typeof options.optimization === 'object'
|
|
26
|
+
? options.optimization.styles
|
|
27
|
+
: options.optimization;
|
|
28
|
+
if (Array.isArray(options.scripts)) {
|
|
29
|
+
plugins.push(...(0, instantiate_script_plugins_1.instantiateScriptPlugins)(options));
|
|
30
|
+
}
|
|
31
|
+
if (options.index && options.generateIndexHtml) {
|
|
32
|
+
plugins.push(new write_index_html_plugin_1.WriteIndexHtmlPlugin({
|
|
33
|
+
crossOrigin: options.crossOrigin,
|
|
34
|
+
sri: options.subresourceIntegrity,
|
|
35
|
+
outputPath: path.basename(options.index),
|
|
36
|
+
indexPath: path.join(options.root, options.index),
|
|
37
|
+
baseHref: options.baseHref,
|
|
38
|
+
deployUrl: options.deployUrl,
|
|
39
|
+
scripts: options.scripts,
|
|
40
|
+
styles: options.styles,
|
|
41
|
+
}));
|
|
42
|
+
}
|
|
43
|
+
if (options.subresourceIntegrity) {
|
|
44
|
+
plugins.push(new webpack_subresource_integrity_1.SubresourceIntegrityPlugin());
|
|
45
|
+
}
|
|
46
|
+
const minimizer = [new webpack_1.ids.HashedModuleIdsPlugin()];
|
|
47
|
+
if (stylesOptimization) {
|
|
48
|
+
minimizer.push(new CssMinimizerPlugin({
|
|
49
|
+
test: /\.(?:css|scss|sass|less|styl)$/,
|
|
50
|
+
}));
|
|
51
|
+
}
|
|
52
|
+
if (!options.ssr) {
|
|
53
|
+
plugins.push(new webpack_1.DefinePlugin((0, get_client_environment_1.getClientEnvironment)(process.env.NODE_ENV).stringified));
|
|
54
|
+
}
|
|
55
|
+
const entries = {};
|
|
56
|
+
const globalStylePaths = [];
|
|
57
|
+
// Determine hashing format.
|
|
58
|
+
const hashFormat = (0, hash_format_1.getOutputHashFormat)(options.outputHashing);
|
|
59
|
+
const includePaths = [];
|
|
60
|
+
if (options?.stylePreprocessorOptions?.includePaths?.length > 0) {
|
|
61
|
+
options.stylePreprocessorOptions.includePaths.forEach((includePath) => includePaths.push(path.resolve(options.root, includePath)));
|
|
62
|
+
}
|
|
63
|
+
let lessPathOptions = {};
|
|
64
|
+
if (includePaths.length > 0) {
|
|
65
|
+
lessPathOptions = {
|
|
66
|
+
paths: includePaths,
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
// Process global styles.
|
|
70
|
+
if (options.styles.length > 0) {
|
|
71
|
+
(0, normalize_entry_1.normalizeExtraEntryPoints)(options.styles, 'styles').forEach((style) => {
|
|
72
|
+
const resolvedPath = path.resolve(options.root, style.input);
|
|
73
|
+
// Add style entry points.
|
|
74
|
+
if (entries[style.bundleName]) {
|
|
75
|
+
entries[style.bundleName].import.push(resolvedPath);
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
entries[style.bundleName] = { import: [resolvedPath] };
|
|
79
|
+
}
|
|
80
|
+
// Add global css paths.
|
|
81
|
+
globalStylePaths.push(resolvedPath);
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
const cssModuleRules = [
|
|
85
|
+
{
|
|
86
|
+
test: /\.module\.css$/,
|
|
87
|
+
exclude: globalStylePaths,
|
|
88
|
+
use: (0, stylesheet_loaders_1.getCommonLoadersForCssModules)(options, includePaths),
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
test: /\.module\.(scss|sass)$/,
|
|
92
|
+
exclude: globalStylePaths,
|
|
93
|
+
use: [
|
|
94
|
+
...(0, stylesheet_loaders_1.getCommonLoadersForCssModules)(options, includePaths),
|
|
95
|
+
{
|
|
96
|
+
loader: require.resolve('sass-loader'),
|
|
97
|
+
options: {
|
|
98
|
+
implementation: require('sass'),
|
|
99
|
+
sassOptions: {
|
|
100
|
+
fiber: false,
|
|
101
|
+
precision: 8,
|
|
102
|
+
includePaths,
|
|
103
|
+
},
|
|
104
|
+
},
|
|
105
|
+
},
|
|
106
|
+
],
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
test: /\.module\.less$/,
|
|
110
|
+
exclude: globalStylePaths,
|
|
111
|
+
use: [
|
|
112
|
+
...(0, stylesheet_loaders_1.getCommonLoadersForCssModules)(options, includePaths),
|
|
113
|
+
{
|
|
114
|
+
loader: require.resolve('less-loader'),
|
|
115
|
+
options: {
|
|
116
|
+
lessOptions: {
|
|
117
|
+
paths: includePaths,
|
|
118
|
+
},
|
|
119
|
+
},
|
|
120
|
+
},
|
|
121
|
+
],
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
test: /\.module\.styl$/,
|
|
125
|
+
exclude: globalStylePaths,
|
|
126
|
+
use: [
|
|
127
|
+
...(0, stylesheet_loaders_1.getCommonLoadersForCssModules)(options, includePaths),
|
|
128
|
+
{
|
|
129
|
+
loader: path.join(__dirname, '../../../utils/webpack/deprecated-stylus-loader.js'),
|
|
130
|
+
options: {
|
|
131
|
+
stylusOptions: {
|
|
132
|
+
include: includePaths,
|
|
133
|
+
},
|
|
134
|
+
},
|
|
135
|
+
},
|
|
136
|
+
],
|
|
137
|
+
},
|
|
138
|
+
];
|
|
139
|
+
const globalCssRules = [
|
|
140
|
+
{
|
|
141
|
+
test: /\.css$/,
|
|
142
|
+
exclude: globalStylePaths,
|
|
143
|
+
use: (0, stylesheet_loaders_1.getCommonLoadersForGlobalCss)(options, includePaths),
|
|
144
|
+
},
|
|
145
|
+
{
|
|
146
|
+
test: /\.scss$|\.sass$/,
|
|
147
|
+
exclude: globalStylePaths,
|
|
148
|
+
use: [
|
|
149
|
+
...(0, stylesheet_loaders_1.getCommonLoadersForGlobalCss)(options, includePaths),
|
|
150
|
+
{
|
|
151
|
+
loader: require.resolve('sass-loader'),
|
|
152
|
+
options: {
|
|
153
|
+
implementation: require('sass'),
|
|
154
|
+
sourceMap: !!options.sourceMap,
|
|
155
|
+
sassOptions: {
|
|
156
|
+
fiber: false,
|
|
157
|
+
// bootstrap-sass requires a minimum precision of 8
|
|
158
|
+
precision: 8,
|
|
159
|
+
includePaths,
|
|
160
|
+
},
|
|
161
|
+
},
|
|
162
|
+
},
|
|
163
|
+
],
|
|
164
|
+
},
|
|
165
|
+
{
|
|
166
|
+
test: /\.less$/,
|
|
167
|
+
exclude: globalStylePaths,
|
|
168
|
+
use: [
|
|
169
|
+
...(0, stylesheet_loaders_1.getCommonLoadersForGlobalCss)(options, includePaths),
|
|
170
|
+
{
|
|
171
|
+
loader: require.resolve('less-loader'),
|
|
172
|
+
options: {
|
|
173
|
+
sourceMap: !!options.sourceMap,
|
|
174
|
+
lessOptions: {
|
|
175
|
+
javascriptEnabled: true,
|
|
176
|
+
...lessPathOptions,
|
|
177
|
+
},
|
|
178
|
+
},
|
|
179
|
+
},
|
|
180
|
+
],
|
|
181
|
+
},
|
|
182
|
+
{
|
|
183
|
+
test: /\.styl$/,
|
|
184
|
+
exclude: globalStylePaths,
|
|
185
|
+
use: [
|
|
186
|
+
...(0, stylesheet_loaders_1.getCommonLoadersForGlobalCss)(options, includePaths),
|
|
187
|
+
{
|
|
188
|
+
loader: path.join(__dirname, '../../../utils/webpack/deprecated-stylus-loader.js'),
|
|
189
|
+
options: {
|
|
190
|
+
sourceMap: !!options.sourceMap,
|
|
191
|
+
stylusOptions: {
|
|
192
|
+
include: includePaths,
|
|
193
|
+
},
|
|
194
|
+
},
|
|
195
|
+
},
|
|
196
|
+
],
|
|
197
|
+
},
|
|
198
|
+
];
|
|
199
|
+
const globalStyleRules = [
|
|
200
|
+
{
|
|
201
|
+
test: /\.css$/,
|
|
202
|
+
include: globalStylePaths,
|
|
203
|
+
use: (0, stylesheet_loaders_1.getCommonLoadersForGlobalStyle)(options, includePaths),
|
|
204
|
+
},
|
|
205
|
+
{
|
|
206
|
+
test: /\.scss$|\.sass$/,
|
|
207
|
+
include: globalStylePaths,
|
|
208
|
+
use: [
|
|
209
|
+
...(0, stylesheet_loaders_1.getCommonLoadersForGlobalStyle)(options, includePaths),
|
|
210
|
+
{
|
|
211
|
+
loader: require.resolve('sass-loader'),
|
|
212
|
+
options: {
|
|
213
|
+
implementation: require('sass'),
|
|
214
|
+
sourceMap: !!options.sourceMap,
|
|
215
|
+
sassOptions: {
|
|
216
|
+
fiber: false,
|
|
217
|
+
// bootstrap-sass requires a minimum precision of 8
|
|
218
|
+
precision: 8,
|
|
219
|
+
includePaths,
|
|
220
|
+
},
|
|
221
|
+
},
|
|
222
|
+
},
|
|
223
|
+
],
|
|
224
|
+
},
|
|
225
|
+
{
|
|
226
|
+
test: /\.less$/,
|
|
227
|
+
include: globalStylePaths,
|
|
228
|
+
use: [
|
|
229
|
+
...(0, stylesheet_loaders_1.getCommonLoadersForGlobalStyle)(options, includePaths),
|
|
230
|
+
{
|
|
231
|
+
loader: require.resolve('less-loader'),
|
|
232
|
+
options: {
|
|
233
|
+
sourceMap: !!options.sourceMap,
|
|
234
|
+
lessOptions: {
|
|
235
|
+
javascriptEnabled: true,
|
|
236
|
+
...lessPathOptions,
|
|
237
|
+
},
|
|
238
|
+
},
|
|
239
|
+
},
|
|
240
|
+
],
|
|
241
|
+
},
|
|
242
|
+
{
|
|
243
|
+
test: /\.styl$/,
|
|
244
|
+
include: globalStylePaths,
|
|
245
|
+
use: [
|
|
246
|
+
...(0, stylesheet_loaders_1.getCommonLoadersForGlobalStyle)(options, includePaths),
|
|
247
|
+
{
|
|
248
|
+
loader: path.join(__dirname, '../../../utils/webpack/deprecated-stylus-loader.js'),
|
|
249
|
+
options: {
|
|
250
|
+
sourceMap: !!options.sourceMap,
|
|
251
|
+
stylusOptions: {
|
|
252
|
+
include: includePaths,
|
|
253
|
+
},
|
|
254
|
+
},
|
|
255
|
+
},
|
|
256
|
+
],
|
|
257
|
+
},
|
|
258
|
+
];
|
|
259
|
+
const rules = [
|
|
260
|
+
{
|
|
261
|
+
test: /\.css$|\.scss$|\.sass$|\.less$|\.styl$/,
|
|
262
|
+
oneOf: [...cssModuleRules, ...globalCssRules, ...globalStyleRules],
|
|
263
|
+
},
|
|
264
|
+
];
|
|
265
|
+
if (options.extractCss) {
|
|
266
|
+
plugins.push(
|
|
267
|
+
// extract global css from js files into own css file
|
|
268
|
+
new MiniCssExtractPlugin({
|
|
269
|
+
filename: `[name]${hashFormat.extract}.css`,
|
|
270
|
+
}));
|
|
271
|
+
}
|
|
272
|
+
config.output = {
|
|
273
|
+
...config.output,
|
|
274
|
+
crossOriginLoading: options.subresourceIntegrity
|
|
275
|
+
? 'anonymous'
|
|
276
|
+
: false,
|
|
277
|
+
};
|
|
278
|
+
// In case users customize their webpack config with unsupported entry.
|
|
279
|
+
if (typeof config.entry === 'function')
|
|
280
|
+
throw new Error('Entry function is not supported. Use an object.');
|
|
281
|
+
if (typeof config.entry === 'string')
|
|
282
|
+
throw new Error('Entry string is not supported. Use an object.');
|
|
283
|
+
if (Array.isArray(config.entry))
|
|
284
|
+
throw new Error('Entry array is not supported. Use an object.');
|
|
285
|
+
Object.entries(entries).forEach(([entryName, entryData]) => {
|
|
286
|
+
if (useNormalizedEntry) {
|
|
287
|
+
config.entry[entryName] = { import: entryData.import };
|
|
288
|
+
}
|
|
289
|
+
else {
|
|
290
|
+
config.entry[entryName] = entryData.import;
|
|
291
|
+
}
|
|
292
|
+
});
|
|
293
|
+
config.optimization = {
|
|
294
|
+
...config.optimization,
|
|
295
|
+
minimizer: [...config.optimization.minimizer, ...minimizer],
|
|
296
|
+
emitOnErrors: false,
|
|
297
|
+
moduleIds: 'deterministic',
|
|
298
|
+
runtimeChunk: options.runtimeChunk ? { name: 'runtime' } : false,
|
|
299
|
+
splitChunks: {
|
|
300
|
+
defaultSizeTypes: config.optimization.splitChunks !== false
|
|
301
|
+
? config.optimization.splitChunks?.defaultSizeTypes
|
|
302
|
+
: ['...'],
|
|
303
|
+
maxAsyncRequests: Infinity,
|
|
304
|
+
cacheGroups: {
|
|
305
|
+
default: !!options.commonChunk && {
|
|
306
|
+
chunks: 'async',
|
|
307
|
+
minChunks: 2,
|
|
308
|
+
priority: 10,
|
|
309
|
+
},
|
|
310
|
+
common: !!options.commonChunk && {
|
|
311
|
+
name: 'common',
|
|
312
|
+
chunks: 'async',
|
|
313
|
+
minChunks: 2,
|
|
314
|
+
enforce: true,
|
|
315
|
+
priority: 5,
|
|
316
|
+
},
|
|
317
|
+
vendors: false,
|
|
318
|
+
vendor: !!options.vendorChunk && {
|
|
319
|
+
name: 'vendor',
|
|
320
|
+
chunks: (chunk) => chunk.name === 'main',
|
|
321
|
+
enforce: true,
|
|
322
|
+
test: /[\\/]node_modules[\\/]/,
|
|
323
|
+
},
|
|
324
|
+
},
|
|
325
|
+
},
|
|
326
|
+
};
|
|
327
|
+
config.resolve.mainFields = ['browser', 'module', 'main'];
|
|
328
|
+
config.module = {
|
|
329
|
+
...config.module,
|
|
330
|
+
rules: [
|
|
331
|
+
...(config.module.rules ?? []),
|
|
332
|
+
// Images: Inline small images, and emit a separate file otherwise.
|
|
333
|
+
{
|
|
334
|
+
test: /\.(avif|bmp|gif|ico|jpe?g|png|webp)$/,
|
|
335
|
+
type: 'asset',
|
|
336
|
+
parser: {
|
|
337
|
+
dataUrlCondition: {
|
|
338
|
+
maxSize: 10_000, // 10 kB
|
|
339
|
+
},
|
|
340
|
+
},
|
|
341
|
+
generator: {
|
|
342
|
+
filename: `[name]${hashFormat.file}[ext]`,
|
|
343
|
+
},
|
|
344
|
+
},
|
|
345
|
+
// SVG: same as image but we need to separate it so it can be swapped for SVGR in the React plugin.
|
|
346
|
+
{
|
|
347
|
+
test: /\.svg$/,
|
|
348
|
+
type: 'asset',
|
|
349
|
+
parser: {
|
|
350
|
+
dataUrlCondition: {
|
|
351
|
+
maxSize: 10_000, // 10 kB
|
|
352
|
+
},
|
|
353
|
+
},
|
|
354
|
+
generator: {
|
|
355
|
+
filename: `[name]${hashFormat.file}[ext]`,
|
|
356
|
+
},
|
|
357
|
+
},
|
|
358
|
+
// Fonts: Emit separate file and export the URL.
|
|
359
|
+
{
|
|
360
|
+
test: /\.(eot|otf|ttf|woff|woff2)$/,
|
|
361
|
+
type: 'asset/resource',
|
|
362
|
+
generator: {
|
|
363
|
+
filename: `[name]${hashFormat.file}[ext]`,
|
|
364
|
+
},
|
|
365
|
+
},
|
|
366
|
+
...rules,
|
|
367
|
+
],
|
|
368
|
+
};
|
|
369
|
+
config.plugins ??= [];
|
|
370
|
+
config.plugins.push(...plugins);
|
|
371
|
+
}
|
|
372
|
+
exports.applyWebConfig = applyWebConfig;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { NormalizedNxWebpackPluginOptions } from '../nx-webpack-plugin-options';
|
|
2
|
+
export declare function createLoaderFromCompiler(options: NormalizedNxWebpackPluginOptions): {
|
|
3
|
+
test: RegExp;
|
|
4
|
+
loader: string;
|
|
5
|
+
exclude: RegExp;
|
|
6
|
+
options: {
|
|
7
|
+
cwd: string;
|
|
8
|
+
emitDecoratorMetadata: boolean;
|
|
9
|
+
isModern: boolean;
|
|
10
|
+
isTest: boolean;
|
|
11
|
+
envName: string;
|
|
12
|
+
cacheDirectory: boolean;
|
|
13
|
+
cacheCompression: boolean;
|
|
14
|
+
};
|
|
15
|
+
} | {
|
|
16
|
+
test: RegExp;
|
|
17
|
+
loader: string;
|
|
18
|
+
exclude: RegExp;
|
|
19
|
+
options: {
|
|
20
|
+
jsc: {
|
|
21
|
+
parser: {
|
|
22
|
+
syntax: string;
|
|
23
|
+
decorators: boolean;
|
|
24
|
+
tsx: boolean;
|
|
25
|
+
};
|
|
26
|
+
transform: {
|
|
27
|
+
react: {
|
|
28
|
+
runtime: string;
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
loose: boolean;
|
|
32
|
+
};
|
|
33
|
+
configFile?: undefined;
|
|
34
|
+
transpileOnly?: undefined;
|
|
35
|
+
experimentalWatchApi?: undefined;
|
|
36
|
+
getCustomTransformers?: undefined;
|
|
37
|
+
};
|
|
38
|
+
} | {
|
|
39
|
+
test: RegExp;
|
|
40
|
+
loader: string;
|
|
41
|
+
exclude: RegExp;
|
|
42
|
+
options: {
|
|
43
|
+
configFile: string;
|
|
44
|
+
transpileOnly: boolean;
|
|
45
|
+
experimentalWatchApi: boolean;
|
|
46
|
+
getCustomTransformers: (program: any) => {
|
|
47
|
+
before: any;
|
|
48
|
+
after: any;
|
|
49
|
+
afterDeclarations: any;
|
|
50
|
+
};
|
|
51
|
+
jsc?: undefined;
|
|
52
|
+
};
|
|
53
|
+
};
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createLoaderFromCompiler = void 0;
|
|
4
|
+
const path = require("path");
|
|
5
|
+
const js_1 = require("@nx/js");
|
|
6
|
+
function createLoaderFromCompiler(options) {
|
|
7
|
+
switch (options.compiler) {
|
|
8
|
+
case 'swc':
|
|
9
|
+
return {
|
|
10
|
+
test: /\.([jt])sx?$/,
|
|
11
|
+
loader: require.resolve('swc-loader'),
|
|
12
|
+
exclude: /node_modules/,
|
|
13
|
+
options: {
|
|
14
|
+
jsc: {
|
|
15
|
+
parser: {
|
|
16
|
+
syntax: 'typescript',
|
|
17
|
+
decorators: true,
|
|
18
|
+
tsx: true,
|
|
19
|
+
},
|
|
20
|
+
transform: {
|
|
21
|
+
react: {
|
|
22
|
+
runtime: 'automatic',
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
loose: true,
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
case 'tsc':
|
|
30
|
+
const { loadTsTransformers } = require('@nx/js');
|
|
31
|
+
const { compilerPluginHooks, hasPlugin } = loadTsTransformers(options.transformers);
|
|
32
|
+
return {
|
|
33
|
+
test: /\.([jt])sx?$/,
|
|
34
|
+
loader: require.resolve(`ts-loader`),
|
|
35
|
+
exclude: /node_modules/,
|
|
36
|
+
options: {
|
|
37
|
+
configFile: options.tsConfig,
|
|
38
|
+
transpileOnly: !hasPlugin,
|
|
39
|
+
// https://github.com/TypeStrong/ts-loader/pull/685
|
|
40
|
+
experimentalWatchApi: true,
|
|
41
|
+
getCustomTransformers: (program) => ({
|
|
42
|
+
before: compilerPluginHooks.beforeHooks.map((hook) => hook(program)),
|
|
43
|
+
after: compilerPluginHooks.afterHooks.map((hook) => hook(program)),
|
|
44
|
+
afterDeclarations: compilerPluginHooks.afterDeclarationsHooks.map((hook) => hook(program)),
|
|
45
|
+
}),
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
case 'babel':
|
|
49
|
+
const tsConfig = (0, js_1.readTsConfig)(path.join(options.root, options.tsConfig));
|
|
50
|
+
const babelConfig = {
|
|
51
|
+
test: /\.([jt])sx?$/,
|
|
52
|
+
loader: path.join(__dirname, '../../../utils/web-babel-loader'),
|
|
53
|
+
exclude: /node_modules/,
|
|
54
|
+
options: {
|
|
55
|
+
cwd: path.join(options.root, options.sourceRoot),
|
|
56
|
+
emitDecoratorMetadata: tsConfig.options.emitDecoratorMetadata,
|
|
57
|
+
isModern: true,
|
|
58
|
+
isTest: process.env.NX_CYPRESS_COMPONENT_TEST === 'true',
|
|
59
|
+
envName: process.env.BABEL_ENV ?? process.env.NODE_ENV,
|
|
60
|
+
cacheDirectory: true,
|
|
61
|
+
cacheCompression: false,
|
|
62
|
+
},
|
|
63
|
+
};
|
|
64
|
+
if (options.babelUpwardRootMode) {
|
|
65
|
+
babelConfig.options['rootMode'] = 'upward';
|
|
66
|
+
babelConfig.options['babelrc'] = true;
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
babelConfig.options['configFile'] = options.babelConfig
|
|
70
|
+
? path.join(options.root, options.babelConfig)
|
|
71
|
+
: path.join(options.root, options.projectRoot, '.babelrc');
|
|
72
|
+
}
|
|
73
|
+
return babelConfig;
|
|
74
|
+
default:
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
exports.createLoaderFromCompiler = createLoaderFromCompiler;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getTerserEcmaVersion(projectRoot: string): 2020 | 5;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getTerserEcmaVersion = void 0;
|
|
4
|
+
const path = require("path");
|
|
5
|
+
const fs = require("fs");
|
|
6
|
+
const browserslist = require("browserslist");
|
|
7
|
+
const VALID_BROWSERSLIST_FILES = ['.browserslistrc', 'browserslist'];
|
|
8
|
+
const ES5_BROWSERS = [
|
|
9
|
+
'ie 10',
|
|
10
|
+
'ie 11',
|
|
11
|
+
'safari 11',
|
|
12
|
+
'safari 11.1',
|
|
13
|
+
'safari 12',
|
|
14
|
+
'safari 12.1',
|
|
15
|
+
'safari 13',
|
|
16
|
+
'ios_saf 13.0',
|
|
17
|
+
'ios_saf 13.3',
|
|
18
|
+
];
|
|
19
|
+
function getTerserEcmaVersion(projectRoot) {
|
|
20
|
+
let pathToBrowserslistFile = '';
|
|
21
|
+
for (const browserslistFile of VALID_BROWSERSLIST_FILES) {
|
|
22
|
+
const fullPathToFile = path.join(projectRoot, browserslistFile);
|
|
23
|
+
if (fs.existsSync(fullPathToFile)) {
|
|
24
|
+
pathToBrowserslistFile = fullPathToFile;
|
|
25
|
+
break;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
if (!pathToBrowserslistFile) {
|
|
29
|
+
return 2020;
|
|
30
|
+
}
|
|
31
|
+
const env = browserslist.loadConfig({ path: pathToBrowserslistFile });
|
|
32
|
+
const browsers = browserslist(env);
|
|
33
|
+
return browsers.some((b) => ES5_BROWSERS.includes(b)) ? 5 : 2020;
|
|
34
|
+
}
|
|
35
|
+
exports.getTerserEcmaVersion = getTerserEcmaVersion;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.instantiateScriptPlugins = void 0;
|
|
4
|
+
const path = require("path");
|
|
5
|
+
const hash_format_1 = require("../../../utils/hash-format");
|
|
6
|
+
const scripts_webpack_plugin_1 = require("../../../utils/webpack/plugins/scripts-webpack-plugin");
|
|
7
|
+
const normalize_entry_1 = require("../../../utils/webpack/normalize-entry");
|
|
8
|
+
function instantiateScriptPlugins(options) {
|
|
9
|
+
// process global scripts
|
|
10
|
+
const globalScriptsByBundleName = (0, normalize_entry_1.normalizeExtraEntryPoints)(options.scripts || [], 'scripts').reduce((prev, curr) => {
|
|
11
|
+
const bundleName = curr.bundleName;
|
|
12
|
+
const resolvedPath = path.resolve(options.root, curr.input);
|
|
13
|
+
const existingEntry = prev.find((el) => el.bundleName === bundleName);
|
|
14
|
+
if (existingEntry) {
|
|
15
|
+
existingEntry.paths.push(resolvedPath);
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
prev.push({
|
|
19
|
+
inject: curr.inject,
|
|
20
|
+
bundleName,
|
|
21
|
+
paths: [resolvedPath],
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
return prev;
|
|
25
|
+
}, []);
|
|
26
|
+
const hashFormat = (0, hash_format_1.getOutputHashFormat)(options.outputHashing);
|
|
27
|
+
const plugins = [];
|
|
28
|
+
// Add a new asset for each entry.
|
|
29
|
+
globalScriptsByBundleName.forEach((script) => {
|
|
30
|
+
const hash = script.inject ? hashFormat.script : '';
|
|
31
|
+
const bundleName = script.bundleName;
|
|
32
|
+
plugins.push(new scripts_webpack_plugin_1.ScriptsWebpackPlugin({
|
|
33
|
+
name: bundleName,
|
|
34
|
+
sourceMap: !!options.sourceMap,
|
|
35
|
+
filename: `${path.basename(bundleName)}${hash}.js`,
|
|
36
|
+
scripts: script.paths,
|
|
37
|
+
basePath: options.sourceRoot,
|
|
38
|
+
}));
|
|
39
|
+
});
|
|
40
|
+
return plugins;
|
|
41
|
+
}
|
|
42
|
+
exports.instantiateScriptPlugins = instantiateScriptPlugins;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { AssetGlobPattern, FileReplacement, NormalizedNxWebpackPluginOptions, NxWebpackPluginOptions } from '../nx-webpack-plugin-options';
|
|
2
|
+
export declare function normalizeOptions(options: NxWebpackPluginOptions): NormalizedNxWebpackPluginOptions;
|
|
3
|
+
export declare function normalizeAssets(assets: any[], root: string, sourceRoot: string, projectRoot: string, resolveRelativePathsToProjectRoot?: boolean): AssetGlobPattern[];
|
|
4
|
+
export declare function normalizeFileReplacements(root: string, fileReplacements: FileReplacement[]): FileReplacement[];
|