@nx/webpack 17.0.3 → 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 +1 -1
- 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
package/src/utils/with-web.js
CHANGED
|
@@ -1,505 +1,26 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.withWeb = void 0;
|
|
4
|
-
const
|
|
5
|
-
const webpack_1 = require("webpack");
|
|
6
|
-
const webpack_subresource_integrity_1 = require("webpack-subresource-integrity");
|
|
7
|
-
const path = require("path");
|
|
8
|
-
const path_1 = require("path");
|
|
9
|
-
const hash_format_1 = require("./hash-format");
|
|
10
|
-
const postcss_cli_resources_1 = require("./webpack/plugins/postcss-cli-resources");
|
|
11
|
-
const normalize_entry_1 = require("./webpack/normalize-entry");
|
|
12
|
-
const get_client_environment_1 = require("./get-client-environment");
|
|
13
|
-
const scripts_webpack_plugin_1 = require("./webpack/plugins/scripts-webpack-plugin");
|
|
14
|
-
const get_css_module_local_ident_1 = require("./get-css-module-local-ident");
|
|
15
|
-
const write_index_html_plugin_1 = require("../plugins/write-index-html-plugin");
|
|
16
|
-
const CssMinimizerPlugin = require("css-minimizer-webpack-plugin");
|
|
17
|
-
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
|
|
18
|
-
const autoprefixer = require("autoprefixer");
|
|
19
|
-
const postcssImports = require("postcss-import");
|
|
4
|
+
const apply_web_config_1 = require("../plugins/nx-webpack-plugin/lib/apply-web-config");
|
|
20
5
|
const processed = new Set();
|
|
21
6
|
/**
|
|
22
7
|
* @param {WithWebOptions} pluginOptions
|
|
23
8
|
* @returns {NxWebpackPlugin}
|
|
24
9
|
*/
|
|
25
10
|
function withWeb(pluginOptions = {}) {
|
|
26
|
-
return function configure(config, { options
|
|
11
|
+
return function configure(config, { options, context }) {
|
|
27
12
|
if (processed.has(config))
|
|
28
13
|
return config;
|
|
29
|
-
|
|
30
|
-
...
|
|
14
|
+
(0, apply_web_config_1.applyWebConfig)({
|
|
15
|
+
...options,
|
|
31
16
|
...pluginOptions,
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
if (Array.isArray(mergedOptions.scripts)) {
|
|
38
|
-
plugins.push(...createScriptsPlugin(mergedOptions));
|
|
39
|
-
}
|
|
40
|
-
if (mergedOptions.index && mergedOptions.generateIndexHtml) {
|
|
41
|
-
plugins.push(new write_index_html_plugin_1.WriteIndexHtmlPlugin({
|
|
42
|
-
crossOrigin: mergedOptions.crossOrigin,
|
|
43
|
-
sri: mergedOptions.subresourceIntegrity,
|
|
44
|
-
outputPath: (0, path_1.basename)(mergedOptions.index),
|
|
45
|
-
indexPath: (0, path_1.join)(context.root, mergedOptions.index),
|
|
46
|
-
baseHref: mergedOptions.baseHref,
|
|
47
|
-
deployUrl: mergedOptions.deployUrl,
|
|
48
|
-
scripts: mergedOptions.scripts,
|
|
49
|
-
styles: mergedOptions.styles,
|
|
50
|
-
}));
|
|
51
|
-
}
|
|
52
|
-
if (mergedOptions.subresourceIntegrity) {
|
|
53
|
-
plugins.push(new webpack_subresource_integrity_1.SubresourceIntegrityPlugin());
|
|
54
|
-
}
|
|
55
|
-
const minimizer = [
|
|
56
|
-
new webpack_1.ids.HashedModuleIdsPlugin(),
|
|
57
|
-
];
|
|
58
|
-
if (stylesOptimization) {
|
|
59
|
-
minimizer.push(new CssMinimizerPlugin({
|
|
60
|
-
test: /\.(?:css|scss|sass|less|styl)$/,
|
|
61
|
-
}));
|
|
62
|
-
}
|
|
63
|
-
if (!pluginOptions.ssr) {
|
|
64
|
-
plugins.push(new webpack.DefinePlugin((0, get_client_environment_1.getClientEnvironment)(process.env.NODE_ENV).stringified));
|
|
65
|
-
}
|
|
66
|
-
const entry = {};
|
|
67
|
-
const globalStylePaths = [];
|
|
68
|
-
// Determine hashing format.
|
|
69
|
-
const hashFormat = (0, hash_format_1.getOutputHashFormat)(mergedOptions.outputHashing);
|
|
70
|
-
const includePaths = [];
|
|
71
|
-
if (mergedOptions?.stylePreprocessorOptions?.includePaths?.length > 0) {
|
|
72
|
-
mergedOptions.stylePreprocessorOptions.includePaths.forEach((includePath) => includePaths.push(path.resolve(mergedOptions.root, includePath)));
|
|
73
|
-
}
|
|
74
|
-
let lessPathOptions = {};
|
|
75
|
-
if (includePaths.length > 0) {
|
|
76
|
-
lessPathOptions = {
|
|
77
|
-
paths: includePaths,
|
|
78
|
-
};
|
|
79
|
-
}
|
|
80
|
-
// Process global styles.
|
|
81
|
-
if (mergedOptions.styles.length > 0) {
|
|
82
|
-
(0, normalize_entry_1.normalizeExtraEntryPoints)(mergedOptions.styles, 'styles').forEach((style) => {
|
|
83
|
-
const resolvedPath = path.resolve(mergedOptions.root, style.input);
|
|
84
|
-
// Add style entry points.
|
|
85
|
-
if (entry[style.bundleName]) {
|
|
86
|
-
entry[style.bundleName].push(resolvedPath);
|
|
87
|
-
}
|
|
88
|
-
else {
|
|
89
|
-
entry[style.bundleName] = [resolvedPath];
|
|
90
|
-
}
|
|
91
|
-
// Add global css paths.
|
|
92
|
-
globalStylePaths.push(resolvedPath);
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
-
const cssModuleRules = [
|
|
96
|
-
{
|
|
97
|
-
test: /\.module\.css$/,
|
|
98
|
-
exclude: globalStylePaths,
|
|
99
|
-
use: getCommonLoadersForCssModules(mergedOptions, includePaths),
|
|
100
|
-
},
|
|
101
|
-
{
|
|
102
|
-
test: /\.module\.(scss|sass)$/,
|
|
103
|
-
exclude: globalStylePaths,
|
|
104
|
-
use: [
|
|
105
|
-
...getCommonLoadersForCssModules(mergedOptions, includePaths),
|
|
106
|
-
{
|
|
107
|
-
loader: require.resolve('sass-loader'),
|
|
108
|
-
options: {
|
|
109
|
-
implementation: require('sass'),
|
|
110
|
-
sassOptions: {
|
|
111
|
-
fiber: false,
|
|
112
|
-
precision: 8,
|
|
113
|
-
includePaths,
|
|
114
|
-
},
|
|
115
|
-
},
|
|
116
|
-
},
|
|
117
|
-
],
|
|
118
|
-
},
|
|
119
|
-
{
|
|
120
|
-
test: /\.module\.less$/,
|
|
121
|
-
exclude: globalStylePaths,
|
|
122
|
-
use: [
|
|
123
|
-
...getCommonLoadersForCssModules(mergedOptions, includePaths),
|
|
124
|
-
{
|
|
125
|
-
loader: require.resolve('less-loader'),
|
|
126
|
-
options: {
|
|
127
|
-
lessOptions: {
|
|
128
|
-
paths: includePaths,
|
|
129
|
-
},
|
|
130
|
-
},
|
|
131
|
-
},
|
|
132
|
-
],
|
|
133
|
-
},
|
|
134
|
-
{
|
|
135
|
-
test: /\.module\.styl$/,
|
|
136
|
-
exclude: globalStylePaths,
|
|
137
|
-
use: [
|
|
138
|
-
...getCommonLoadersForCssModules(mergedOptions, includePaths),
|
|
139
|
-
{
|
|
140
|
-
loader: (0, path_1.join)(__dirname, 'webpack/deprecated-stylus-loader.js'),
|
|
141
|
-
options: {
|
|
142
|
-
stylusOptions: {
|
|
143
|
-
include: includePaths,
|
|
144
|
-
},
|
|
145
|
-
},
|
|
146
|
-
},
|
|
147
|
-
],
|
|
148
|
-
},
|
|
149
|
-
];
|
|
150
|
-
const globalCssRules = [
|
|
151
|
-
{
|
|
152
|
-
test: /\.css$/,
|
|
153
|
-
exclude: globalStylePaths,
|
|
154
|
-
use: getCommonLoadersForGlobalCss(mergedOptions, includePaths),
|
|
155
|
-
},
|
|
156
|
-
{
|
|
157
|
-
test: /\.scss$|\.sass$/,
|
|
158
|
-
exclude: globalStylePaths,
|
|
159
|
-
use: [
|
|
160
|
-
...getCommonLoadersForGlobalCss(mergedOptions, includePaths),
|
|
161
|
-
{
|
|
162
|
-
loader: require.resolve('sass-loader'),
|
|
163
|
-
options: {
|
|
164
|
-
implementation: require('sass'),
|
|
165
|
-
sourceMap: !!mergedOptions.sourceMap,
|
|
166
|
-
sassOptions: {
|
|
167
|
-
fiber: false,
|
|
168
|
-
// bootstrap-sass requires a minimum precision of 8
|
|
169
|
-
precision: 8,
|
|
170
|
-
includePaths,
|
|
171
|
-
},
|
|
172
|
-
},
|
|
173
|
-
},
|
|
174
|
-
],
|
|
175
|
-
},
|
|
176
|
-
{
|
|
177
|
-
test: /\.less$/,
|
|
178
|
-
exclude: globalStylePaths,
|
|
179
|
-
use: [
|
|
180
|
-
...getCommonLoadersForGlobalCss(mergedOptions, includePaths),
|
|
181
|
-
{
|
|
182
|
-
loader: require.resolve('less-loader'),
|
|
183
|
-
options: {
|
|
184
|
-
sourceMap: !!mergedOptions.sourceMap,
|
|
185
|
-
lessOptions: {
|
|
186
|
-
javascriptEnabled: true,
|
|
187
|
-
...lessPathOptions,
|
|
188
|
-
},
|
|
189
|
-
},
|
|
190
|
-
},
|
|
191
|
-
],
|
|
192
|
-
},
|
|
193
|
-
{
|
|
194
|
-
test: /\.styl$/,
|
|
195
|
-
exclude: globalStylePaths,
|
|
196
|
-
use: [
|
|
197
|
-
...getCommonLoadersForGlobalCss(mergedOptions, includePaths),
|
|
198
|
-
{
|
|
199
|
-
loader: (0, path_1.join)(__dirname, 'webpack/deprecated-stylus-loader.js'),
|
|
200
|
-
options: {
|
|
201
|
-
sourceMap: !!mergedOptions.sourceMap,
|
|
202
|
-
stylusOptions: {
|
|
203
|
-
include: includePaths,
|
|
204
|
-
},
|
|
205
|
-
},
|
|
206
|
-
},
|
|
207
|
-
],
|
|
208
|
-
},
|
|
209
|
-
];
|
|
210
|
-
const globalStyleRules = [
|
|
211
|
-
{
|
|
212
|
-
test: /\.css$/,
|
|
213
|
-
include: globalStylePaths,
|
|
214
|
-
use: getCommonLoadersForGlobalStyle(mergedOptions, includePaths),
|
|
215
|
-
},
|
|
216
|
-
{
|
|
217
|
-
test: /\.scss$|\.sass$/,
|
|
218
|
-
include: globalStylePaths,
|
|
219
|
-
use: [
|
|
220
|
-
...getCommonLoadersForGlobalStyle(mergedOptions, includePaths),
|
|
221
|
-
{
|
|
222
|
-
loader: require.resolve('sass-loader'),
|
|
223
|
-
options: {
|
|
224
|
-
implementation: require('sass'),
|
|
225
|
-
sourceMap: !!mergedOptions.sourceMap,
|
|
226
|
-
sassOptions: {
|
|
227
|
-
fiber: false,
|
|
228
|
-
// bootstrap-sass requires a minimum precision of 8
|
|
229
|
-
precision: 8,
|
|
230
|
-
includePaths,
|
|
231
|
-
},
|
|
232
|
-
},
|
|
233
|
-
},
|
|
234
|
-
],
|
|
235
|
-
},
|
|
236
|
-
{
|
|
237
|
-
test: /\.less$/,
|
|
238
|
-
include: globalStylePaths,
|
|
239
|
-
use: [
|
|
240
|
-
...getCommonLoadersForGlobalStyle(mergedOptions, includePaths),
|
|
241
|
-
{
|
|
242
|
-
loader: require.resolve('less-loader'),
|
|
243
|
-
options: {
|
|
244
|
-
sourceMap: !!mergedOptions.sourceMap,
|
|
245
|
-
lessOptions: {
|
|
246
|
-
javascriptEnabled: true,
|
|
247
|
-
...lessPathOptions,
|
|
248
|
-
},
|
|
249
|
-
},
|
|
250
|
-
},
|
|
251
|
-
],
|
|
252
|
-
},
|
|
253
|
-
{
|
|
254
|
-
test: /\.styl$/,
|
|
255
|
-
include: globalStylePaths,
|
|
256
|
-
use: [
|
|
257
|
-
...getCommonLoadersForGlobalStyle(mergedOptions, includePaths),
|
|
258
|
-
{
|
|
259
|
-
loader: require.resolve('stylus-loader'),
|
|
260
|
-
options: {
|
|
261
|
-
sourceMap: !!mergedOptions.sourceMap,
|
|
262
|
-
stylusOptions: {
|
|
263
|
-
include: includePaths,
|
|
264
|
-
},
|
|
265
|
-
},
|
|
266
|
-
},
|
|
267
|
-
],
|
|
268
|
-
},
|
|
269
|
-
];
|
|
270
|
-
const rules = [
|
|
271
|
-
{
|
|
272
|
-
test: /\.css$|\.scss$|\.sass$|\.less$|\.styl$/,
|
|
273
|
-
oneOf: [...cssModuleRules, ...globalCssRules, ...globalStyleRules],
|
|
274
|
-
},
|
|
275
|
-
];
|
|
276
|
-
plugins.push(
|
|
277
|
-
// extract global css from js files into own css file
|
|
278
|
-
new MiniCssExtractPlugin({
|
|
279
|
-
filename: `[name]${hashFormat.extract}.css`,
|
|
280
|
-
}));
|
|
281
|
-
config.output = {
|
|
282
|
-
...config.output,
|
|
283
|
-
crossOriginLoading: mergedOptions.subresourceIntegrity
|
|
284
|
-
? 'anonymous'
|
|
285
|
-
: false,
|
|
286
|
-
};
|
|
287
|
-
// In case users customize their webpack config with unsupported entry.
|
|
288
|
-
if (typeof config.entry === 'function')
|
|
289
|
-
throw new Error('Entry function is not supported. Use an object.');
|
|
290
|
-
if (typeof config.entry === 'string')
|
|
291
|
-
throw new Error('Entry string is not supported. Use an object.');
|
|
292
|
-
if (Array.isArray(config.entry))
|
|
293
|
-
throw new Error('Entry array is not supported. Use an object.');
|
|
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: {
|
|
302
|
-
maxAsyncRequests: Infinity,
|
|
303
|
-
cacheGroups: {
|
|
304
|
-
default: !!mergedOptions.commonChunk && {
|
|
305
|
-
chunks: 'async',
|
|
306
|
-
minChunks: 2,
|
|
307
|
-
priority: 10,
|
|
308
|
-
},
|
|
309
|
-
common: !!mergedOptions.commonChunk && {
|
|
310
|
-
name: 'common',
|
|
311
|
-
chunks: 'async',
|
|
312
|
-
minChunks: 2,
|
|
313
|
-
enforce: true,
|
|
314
|
-
priority: 5,
|
|
315
|
-
},
|
|
316
|
-
vendors: false,
|
|
317
|
-
vendor: !!mergedOptions.vendorChunk && {
|
|
318
|
-
name: 'vendor',
|
|
319
|
-
chunks: (chunk) => chunk.name === 'main',
|
|
320
|
-
enforce: true,
|
|
321
|
-
test: /[\\/]node_modules[\\/]/,
|
|
322
|
-
},
|
|
323
|
-
},
|
|
324
|
-
},
|
|
325
|
-
};
|
|
326
|
-
config.plugins.push(...plugins);
|
|
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: 10000, // 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: 10000, // 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
|
-
};
|
|
17
|
+
projectName: context.projectName,
|
|
18
|
+
targetName: context.targetName,
|
|
19
|
+
configurationName: context.configurationName,
|
|
20
|
+
projectGraph: context.projectGraph,
|
|
21
|
+
}, config);
|
|
369
22
|
processed.add(config);
|
|
370
23
|
return config;
|
|
371
24
|
};
|
|
372
25
|
}
|
|
373
26
|
exports.withWeb = withWeb;
|
|
374
|
-
function createScriptsPlugin(options) {
|
|
375
|
-
// process global scripts
|
|
376
|
-
const globalScriptsByBundleName = (0, normalize_entry_1.normalizeExtraEntryPoints)(options.scripts || [], 'scripts').reduce((prev, curr) => {
|
|
377
|
-
const bundleName = curr.bundleName;
|
|
378
|
-
const resolvedPath = path.resolve(options.root, curr.input);
|
|
379
|
-
const existingEntry = prev.find((el) => el.bundleName === bundleName);
|
|
380
|
-
if (existingEntry) {
|
|
381
|
-
existingEntry.paths.push(resolvedPath);
|
|
382
|
-
}
|
|
383
|
-
else {
|
|
384
|
-
prev.push({
|
|
385
|
-
inject: curr.inject,
|
|
386
|
-
bundleName,
|
|
387
|
-
paths: [resolvedPath],
|
|
388
|
-
});
|
|
389
|
-
}
|
|
390
|
-
return prev;
|
|
391
|
-
}, []);
|
|
392
|
-
const hashFormat = (0, hash_format_1.getOutputHashFormat)(options.outputHashing);
|
|
393
|
-
const plugins = [];
|
|
394
|
-
// Add a new asset for each entry.
|
|
395
|
-
globalScriptsByBundleName.forEach((script) => {
|
|
396
|
-
const hash = script.inject ? hashFormat.script : '';
|
|
397
|
-
const bundleName = script.bundleName;
|
|
398
|
-
plugins.push(new scripts_webpack_plugin_1.ScriptsWebpackPlugin({
|
|
399
|
-
name: bundleName,
|
|
400
|
-
sourceMap: !!options.sourceMap,
|
|
401
|
-
filename: `${(0, path_1.basename)(bundleName)}${hash}.js`,
|
|
402
|
-
scripts: script.paths,
|
|
403
|
-
basePath: options.sourceRoot,
|
|
404
|
-
}));
|
|
405
|
-
});
|
|
406
|
-
return plugins;
|
|
407
|
-
}
|
|
408
|
-
function getCommonLoadersForCssModules(options, includePaths) {
|
|
409
|
-
// load component css as raw strings
|
|
410
|
-
return [
|
|
411
|
-
{
|
|
412
|
-
loader: options.extractCss
|
|
413
|
-
? MiniCssExtractPlugin.loader
|
|
414
|
-
: require.resolve('style-loader'),
|
|
415
|
-
},
|
|
416
|
-
{
|
|
417
|
-
loader: require.resolve('css-loader'),
|
|
418
|
-
options: {
|
|
419
|
-
modules: {
|
|
420
|
-
mode: 'local',
|
|
421
|
-
getLocalIdent: get_css_module_local_ident_1.getCSSModuleLocalIdent,
|
|
422
|
-
},
|
|
423
|
-
importLoaders: 1,
|
|
424
|
-
},
|
|
425
|
-
},
|
|
426
|
-
{
|
|
427
|
-
loader: require.resolve('postcss-loader'),
|
|
428
|
-
options: {
|
|
429
|
-
implementation: require('postcss'),
|
|
430
|
-
postcssOptions: postcssOptionsCreator(options, {
|
|
431
|
-
includePaths,
|
|
432
|
-
forCssModules: true,
|
|
433
|
-
}),
|
|
434
|
-
},
|
|
435
|
-
},
|
|
436
|
-
];
|
|
437
|
-
}
|
|
438
|
-
function getCommonLoadersForGlobalCss(options, includePaths) {
|
|
439
|
-
return [
|
|
440
|
-
{
|
|
441
|
-
loader: options.extractCss
|
|
442
|
-
? MiniCssExtractPlugin.loader
|
|
443
|
-
: require.resolve('style-loader'),
|
|
444
|
-
},
|
|
445
|
-
{ loader: require.resolve('css-loader'), options: { url: false } },
|
|
446
|
-
{
|
|
447
|
-
loader: require.resolve('postcss-loader'),
|
|
448
|
-
options: {
|
|
449
|
-
implementation: require('postcss'),
|
|
450
|
-
postcssOptions: postcssOptionsCreator(options, { includePaths }),
|
|
451
|
-
},
|
|
452
|
-
},
|
|
453
|
-
];
|
|
454
|
-
}
|
|
455
|
-
function getCommonLoadersForGlobalStyle(options, includePaths) {
|
|
456
|
-
return [
|
|
457
|
-
{
|
|
458
|
-
loader: MiniCssExtractPlugin.loader,
|
|
459
|
-
options: { esModule: true },
|
|
460
|
-
},
|
|
461
|
-
{ loader: require.resolve('css-loader'), options: { url: false } },
|
|
462
|
-
{
|
|
463
|
-
loader: require.resolve('postcss-loader'),
|
|
464
|
-
options: {
|
|
465
|
-
implementation: require('postcss'),
|
|
466
|
-
postcssOptions: postcssOptionsCreator(options, { includePaths }),
|
|
467
|
-
},
|
|
468
|
-
},
|
|
469
|
-
];
|
|
470
|
-
}
|
|
471
|
-
function postcssOptionsCreator(options, { includePaths, forCssModules = false, }) {
|
|
472
|
-
const hashFormat = (0, hash_format_1.getOutputHashFormat)(options.outputHashing);
|
|
473
|
-
// PostCSS options depend on the webpack loader, but we need to set the `config` path as a string due to this check:
|
|
474
|
-
// https://github.com/webpack-contrib/postcss-loader/blob/0d342b1/src/utils.js#L36
|
|
475
|
-
const postcssOptions = (loader) => ({
|
|
476
|
-
map: options.sourceMap &&
|
|
477
|
-
options.sourceMap !== 'hidden' && {
|
|
478
|
-
inline: true,
|
|
479
|
-
annotation: false,
|
|
480
|
-
},
|
|
481
|
-
plugins: [
|
|
482
|
-
postcssImports({
|
|
483
|
-
addModulesDirectories: includePaths,
|
|
484
|
-
resolve: (url) => (url.startsWith('~') ? url.slice(1) : url),
|
|
485
|
-
}),
|
|
486
|
-
...(forCssModules
|
|
487
|
-
? []
|
|
488
|
-
: [
|
|
489
|
-
(0, postcss_cli_resources_1.PostcssCliResources)({
|
|
490
|
-
baseHref: options.baseHref,
|
|
491
|
-
deployUrl: options.deployUrl,
|
|
492
|
-
loader,
|
|
493
|
-
filename: `[name]${hashFormat.file}.[ext]`,
|
|
494
|
-
}),
|
|
495
|
-
autoprefixer(),
|
|
496
|
-
]),
|
|
497
|
-
],
|
|
498
|
-
});
|
|
499
|
-
// If a path to postcssConfig is passed in, set it for app and all libs, otherwise
|
|
500
|
-
// use automatic detection.
|
|
501
|
-
if (typeof options.postcssConfig === 'string') {
|
|
502
|
-
postcssOptions.config = path.join(options.root, options.postcssConfig);
|
|
503
|
-
}
|
|
504
|
-
return postcssOptions;
|
|
505
|
-
}
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import type { Configuration } from 'webpack';
|
|
2
|
-
import { ExecutorContext } from '@nx/devkit';
|
|
3
|
-
import { NormalizedWebpackExecutorOptions } from '../schema';
|
|
4
|
-
/** @deprecated Use withNx, withWeb, or withReact */
|
|
5
|
-
export declare function getWebpackConfig(context: ExecutorContext, options: NormalizedWebpackExecutorOptions): Configuration;
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getWebpackConfig = void 0;
|
|
4
|
-
const with_nx_1 = require("../../../utils/with-nx");
|
|
5
|
-
const with_web_1 = require("../../../utils/with-web");
|
|
6
|
-
const config_1 = require("../../../utils/config");
|
|
7
|
-
/** @deprecated Use withNx, withWeb, or withReact */
|
|
8
|
-
// TODO(jack): Remove in Nx 16
|
|
9
|
-
function getWebpackConfig(context, options) {
|
|
10
|
-
const config = {};
|
|
11
|
-
const configure = options.target === 'web'
|
|
12
|
-
? (0, config_1.composePluginsSync)((0, with_nx_1.withNx)(), (0, with_web_1.withWeb)())
|
|
13
|
-
: (0, with_nx_1.withNx)();
|
|
14
|
-
return configure(config, { options, context });
|
|
15
|
-
}
|
|
16
|
-
exports.getWebpackConfig = getWebpackConfig;
|