@nx/webpack 17.0.5 → 17.0.6
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 +4 -9
- package/generators.json +2 -2
- package/index.d.ts +1 -3
- package/index.js +2 -7
- package/migrations.json +0 -6
- package/package.json +5 -6
- package/src/executors/dev-server/dev-server.impl.js +17 -31
- package/src/executors/dev-server/lib/get-dev-server-config.d.ts +3 -2
- package/src/executors/dev-server/lib/get-dev-server-config.js +26 -18
- package/src/executors/dev-server/schema.d.ts +8 -8
- package/src/executors/webpack/lib/get-webpack-config.d.ts +5 -0
- package/src/executors/webpack/lib/get-webpack-config.js +16 -0
- package/src/executors/webpack/lib/normalize-options.d.ts +2 -1
- package/src/executors/webpack/lib/normalize-options.js +53 -9
- package/src/executors/webpack/schema.d.ts +7 -10
- package/src/executors/webpack/schema.json +50 -30
- package/src/executors/webpack/webpack.impl.js +16 -36
- package/src/generators/configuration/configuration.d.ts +2 -3
- package/src/generators/configuration/configuration.js +23 -95
- package/src/generators/configuration/schema.d.ts +0 -1
- package/src/generators/configuration/schema.json +1 -1
- package/src/generators/init/init.d.ts +0 -1
- package/src/generators/init/init.js +23 -48
- package/src/generators/init/schema.d.ts +2 -4
- package/src/generators/init/schema.json +13 -18
- package/src/plugins/generate-package-json-plugin.d.ts +4 -6
- package/src/plugins/generate-package-json-plugin.js +14 -11
- package/src/utils/config.d.ts +6 -11
- package/src/utils/config.js +13 -48
- package/src/utils/get-client-environment.js +1 -4
- package/src/utils/module-federation/dependencies.js +3 -15
- package/src/utils/module-federation/get-remotes-for-host.d.ts +1 -2
- package/src/utils/module-federation/get-remotes-for-host.js +7 -11
- 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 +9 -14
- package/src/utils/versions.d.ts +1 -1
- package/src/utils/versions.js +2 -2
- package/src/utils/webpack/custom-webpack.d.ts +2 -0
- package/src/utils/webpack/{resolve-user-defined-webpack-config.js → custom-webpack.js} +8 -14
- package/src/utils/webpack/deprecated-stylus-loader.js +2 -2
- package/src/utils/webpack/interpolate-env-variables-to-index.js +1 -4
- package/src/utils/webpack/plugins/postcss-cli-resources.js +2 -2
- package/src/utils/with-nx.d.ts +58 -4
- package/src/utils/with-nx.js +362 -22
- package/src/utils/with-web.d.ts +2 -2
- package/src/utils/with-web.js +488 -9
- package/plugin.d.ts +0 -1
- package/plugin.js +0 -5
- package/src/migrations/update-17-2-1/webpack-config-setup.d.ts +0 -2
- package/src/migrations/update-17-2-1/webpack-config-setup.js +0 -31
- package/src/plugins/nx-typescript-webpack-plugin/nx-tsconfig-paths-webpack-plugin.d.ts +0 -8
- package/src/plugins/nx-typescript-webpack-plugin/nx-tsconfig-paths-webpack-plugin.js +0 -31
- package/src/plugins/nx-webpack-plugin/lib/apply-base-config.d.ts +0 -5
- package/src/plugins/nx-webpack-plugin/lib/apply-base-config.js +0 -318
- package/src/plugins/nx-webpack-plugin/lib/apply-web-config.d.ts +0 -5
- package/src/plugins/nx-webpack-plugin/lib/apply-web-config.js +0 -372
- package/src/plugins/nx-webpack-plugin/lib/compiler-loaders.d.ts +0 -53
- package/src/plugins/nx-webpack-plugin/lib/compiler-loaders.js +0 -78
- package/src/plugins/nx-webpack-plugin/lib/get-terser-ecma-version.d.ts +0 -1
- package/src/plugins/nx-webpack-plugin/lib/get-terser-ecma-version.js +0 -35
- package/src/plugins/nx-webpack-plugin/lib/instantiate-script-plugins.d.ts +0 -3
- package/src/plugins/nx-webpack-plugin/lib/instantiate-script-plugins.js +0 -42
- package/src/plugins/nx-webpack-plugin/lib/normalize-options.d.ts +0 -4
- package/src/plugins/nx-webpack-plugin/lib/normalize-options.js +0 -148
- package/src/plugins/nx-webpack-plugin/lib/stylesheet-loaders.d.ts +0 -73
- package/src/plugins/nx-webpack-plugin/lib/stylesheet-loaders.js +0 -117
- package/src/plugins/nx-webpack-plugin/nx-webpack-plugin-options.d.ts +0 -216
- package/src/plugins/nx-webpack-plugin/nx-webpack-plugin-options.js +0 -2
- package/src/plugins/nx-webpack-plugin/nx-webpack-plugin.d.ts +0 -17
- package/src/plugins/nx-webpack-plugin/nx-webpack-plugin.js +0 -48
- package/src/plugins/plugin.d.ts +0 -9
- package/src/plugins/plugin.js +0 -132
- package/src/utils/ensure-dependencies.d.ts +0 -6
- package/src/utils/ensure-dependencies.js +0 -27
- package/src/utils/has-plugin.d.ts +0 -2
- package/src/utils/has-plugin.js +0 -11
- package/src/utils/webpack/read-webpack-options.d.ts +0 -10
- package/src/utils/webpack/read-webpack-options.js +0 -41
- package/src/utils/webpack/resolve-user-defined-webpack-config.d.ts +0 -3
package/src/utils/with-web.js
CHANGED
|
@@ -1,26 +1,505 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.withWeb = void 0;
|
|
4
|
-
const
|
|
4
|
+
const webpack = require("webpack");
|
|
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");
|
|
5
20
|
const processed = new Set();
|
|
6
21
|
/**
|
|
7
22
|
* @param {WithWebOptions} pluginOptions
|
|
8
23
|
* @returns {NxWebpackPlugin}
|
|
9
24
|
*/
|
|
10
25
|
function withWeb(pluginOptions = {}) {
|
|
11
|
-
return function configure(config, { options, context }) {
|
|
26
|
+
return function configure(config, { options: executorOptions, context }) {
|
|
12
27
|
if (processed.has(config))
|
|
13
28
|
return config;
|
|
14
|
-
|
|
15
|
-
...
|
|
29
|
+
const mergedOptions = {
|
|
30
|
+
...executorOptions,
|
|
16
31
|
...pluginOptions,
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
32
|
+
};
|
|
33
|
+
const plugins = [];
|
|
34
|
+
const stylesOptimization = typeof mergedOptions.optimization === 'object'
|
|
35
|
+
? mergedOptions.optimization.styles
|
|
36
|
+
: mergedOptions.optimization;
|
|
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
|
+
};
|
|
22
369
|
processed.add(config);
|
|
23
370
|
return config;
|
|
24
371
|
};
|
|
25
372
|
}
|
|
26
373
|
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
|
+
}
|
package/plugin.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { createNodes } from './src/plugins/plugin';
|
package/plugin.js
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createNodes = void 0;
|
|
4
|
-
var plugin_1 = require("./src/plugins/plugin");
|
|
5
|
-
Object.defineProperty(exports, "createNodes", { enumerable: true, get: function () { return plugin_1.createNodes; } });
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const devkit_1 = require("@nx/devkit");
|
|
4
|
-
const executor_options_utils_1 = require("@nx/devkit/src/generators/executor-options-utils");
|
|
5
|
-
async function default_1(tree) {
|
|
6
|
-
const update = (options, projectName, targetName, configurationName) => {
|
|
7
|
-
// Only handle webpack config for default configuration
|
|
8
|
-
if (configurationName)
|
|
9
|
-
return;
|
|
10
|
-
const projectConfiguration = (0, devkit_1.readProjectConfiguration)(tree, projectName);
|
|
11
|
-
if (!options.webpackConfig && options.isolatedConfig !== false) {
|
|
12
|
-
options.webpackConfig = `${projectConfiguration.root}/webpack.config.js`;
|
|
13
|
-
tree.write(options.webpackConfig, `
|
|
14
|
-
const { composePlugins, withNx } = require('@nx/webpack');
|
|
15
|
-
|
|
16
|
-
// Nx plugins for webpack.
|
|
17
|
-
module.exports = composePlugins(withNx(), (config) => {
|
|
18
|
-
// Note: This was added by an Nx migration. Webpack builds are required to have a corresponding Webpack config file.
|
|
19
|
-
// See: https://nx.dev/recipes/webpack/webpack-config-setup
|
|
20
|
-
return config;
|
|
21
|
-
});
|
|
22
|
-
`);
|
|
23
|
-
projectConfiguration.targets[targetName].options = options;
|
|
24
|
-
(0, devkit_1.updateProjectConfiguration)(tree, projectName, projectConfiguration);
|
|
25
|
-
}
|
|
26
|
-
};
|
|
27
|
-
(0, executor_options_utils_1.forEachExecutorOptions)(tree, '@nx/webpack:webpack', update);
|
|
28
|
-
(0, executor_options_utils_1.forEachExecutorOptions)(tree, '@nrwl/webpack:webpack', update);
|
|
29
|
-
await (0, devkit_1.formatFiles)(tree);
|
|
30
|
-
}
|
|
31
|
-
exports.default = default_1;
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.NxTsconfigPathsWebpackPlugin = void 0;
|
|
4
|
-
const path = require("path");
|
|
5
|
-
const tsconfig_paths_webpack_plugin_1 = require("tsconfig-paths-webpack-plugin");
|
|
6
|
-
const devkit_1 = require("@nx/devkit");
|
|
7
|
-
class NxTsconfigPathsWebpackPlugin {
|
|
8
|
-
constructor(options) {
|
|
9
|
-
this.options = options;
|
|
10
|
-
if (!this.options.tsConfig)
|
|
11
|
-
throw new Error(`Missing "tsConfig" option. Set this option in your Nx webpack plugin.`);
|
|
12
|
-
}
|
|
13
|
-
apply(compiler) {
|
|
14
|
-
const extensions = new Set([
|
|
15
|
-
...['.ts', '.tsx', '.mjs', '.js', '.jsx'],
|
|
16
|
-
...(compiler.options?.resolve?.extensions ?? []),
|
|
17
|
-
]);
|
|
18
|
-
compiler.options.resolve = {
|
|
19
|
-
...compiler.options.resolve,
|
|
20
|
-
plugins: compiler.options.resolve?.plugins ?? [],
|
|
21
|
-
};
|
|
22
|
-
compiler.options.resolve.plugins.push(new tsconfig_paths_webpack_plugin_1.TsconfigPathsPlugin({
|
|
23
|
-
configFile: !path.isAbsolute(this.options.tsConfig)
|
|
24
|
-
? path.join(devkit_1.workspaceRoot, this.options.tsConfig)
|
|
25
|
-
: this.options.tsConfig,
|
|
26
|
-
extensions: Array.from(extensions),
|
|
27
|
-
mainFields: ['module', 'main'],
|
|
28
|
-
}));
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
exports.NxTsconfigPathsWebpackPlugin = NxTsconfigPathsWebpackPlugin;
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import { Configuration, WebpackOptionsNormalized } from 'webpack';
|
|
2
|
-
import { NormalizedNxWebpackPluginOptions } from '../nx-webpack-plugin-options';
|
|
3
|
-
export declare function applyBaseConfig(options: NormalizedNxWebpackPluginOptions, config?: Partial<WebpackOptionsNormalized | Configuration>, { useNormalizedEntry, }?: {
|
|
4
|
-
useNormalizedEntry?: boolean;
|
|
5
|
-
}): void;
|