@nx/webpack 16.0.0-beta.1

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.
Files changed (143) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/LICENSE +22 -0
  3. package/README.md +63 -0
  4. package/executors.json +36 -0
  5. package/generators.json +33 -0
  6. package/index.d.ts +12 -0
  7. package/index.js +14 -0
  8. package/index.js.map +1 -0
  9. package/migrations.json +35 -0
  10. package/package.json +79 -0
  11. package/src/executors/dev-server/compat.d.ts +2 -0
  12. package/src/executors/dev-server/compat.js +6 -0
  13. package/src/executors/dev-server/compat.js.map +1 -0
  14. package/src/executors/dev-server/dev-server.impl.d.ts +7 -0
  15. package/src/executors/dev-server/dev-server.impl.js +69 -0
  16. package/src/executors/dev-server/dev-server.impl.js.map +1 -0
  17. package/src/executors/dev-server/lib/get-dev-server-config.d.ts +5 -0
  18. package/src/executors/dev-server/lib/get-dev-server-config.js +89 -0
  19. package/src/executors/dev-server/lib/get-dev-server-config.js.map +1 -0
  20. package/src/executors/dev-server/lib/serve-path.d.ts +3 -0
  21. package/src/executors/dev-server/lib/serve-path.js +46 -0
  22. package/src/executors/dev-server/lib/serve-path.js.map +1 -0
  23. package/src/executors/dev-server/schema.d.ts +17 -0
  24. package/src/executors/dev-server/schema.json +76 -0
  25. package/src/executors/ssr-dev-server/compat.d.ts +2 -0
  26. package/src/executors/ssr-dev-server/compat.js +6 -0
  27. package/src/executors/ssr-dev-server/compat.js.map +1 -0
  28. package/src/executors/ssr-dev-server/lib/wait-until-server-is-listening.d.ts +1 -0
  29. package/src/executors/ssr-dev-server/lib/wait-until-server-is-listening.js +40 -0
  30. package/src/executors/ssr-dev-server/lib/wait-until-server-is-listening.js.map +1 -0
  31. package/src/executors/ssr-dev-server/schema.d.ts +11 -0
  32. package/src/executors/ssr-dev-server/schema.json +37 -0
  33. package/src/executors/ssr-dev-server/ssr-dev-server.impl.d.ts +8 -0
  34. package/src/executors/ssr-dev-server/ssr-dev-server.impl.js +59 -0
  35. package/src/executors/ssr-dev-server/ssr-dev-server.impl.js.map +1 -0
  36. package/src/executors/webpack/compat.d.ts +2 -0
  37. package/src/executors/webpack/compat.js +6 -0
  38. package/src/executors/webpack/compat.js.map +1 -0
  39. package/src/executors/webpack/lib/get-webpack-config.d.ts +5 -0
  40. package/src/executors/webpack/lib/get-webpack-config.js +17 -0
  41. package/src/executors/webpack/lib/get-webpack-config.js.map +1 -0
  42. package/src/executors/webpack/lib/normalize-options.d.ts +4 -0
  43. package/src/executors/webpack/lib/normalize-options.js +71 -0
  44. package/src/executors/webpack/lib/normalize-options.js.map +1 -0
  45. package/src/executors/webpack/lib/run-webpack.d.ts +3 -0
  46. package/src/executors/webpack/lib/run-webpack.js +38 -0
  47. package/src/executors/webpack/lib/run-webpack.js.map +1 -0
  48. package/src/executors/webpack/schema.d.ts +105 -0
  49. package/src/executors/webpack/schema.json +414 -0
  50. package/src/executors/webpack/webpack.impl.d.ts +14 -0
  51. package/src/executors/webpack/webpack.impl.js +107 -0
  52. package/src/executors/webpack/webpack.impl.js.map +1 -0
  53. package/src/generators/init/init.d.ts +5 -0
  54. package/src/generators/init/init.js +41 -0
  55. package/src/generators/init/init.js.map +1 -0
  56. package/src/generators/init/schema.d.ts +5 -0
  57. package/src/generators/init/schema.json +28 -0
  58. package/src/generators/webpack-project/schema.d.ts +13 -0
  59. package/src/generators/webpack-project/schema.json +77 -0
  60. package/src/generators/webpack-project/webpack-project.d.ts +5 -0
  61. package/src/generators/webpack-project/webpack-project.js +111 -0
  62. package/src/generators/webpack-project/webpack-project.js.map +1 -0
  63. package/src/migrations/update-15-0-0/add-babel-inputs.d.ts +2 -0
  64. package/src/migrations/update-15-0-0/add-babel-inputs.js +13 -0
  65. package/src/migrations/update-15-0-0/add-babel-inputs.js.map +1 -0
  66. package/src/migrations/update-15-4-5/remove-es2015-polyfills-option.d.ts +2 -0
  67. package/src/migrations/update-15-4-5/remove-es2015-polyfills-option.js +25 -0
  68. package/src/migrations/update-15-4-5/remove-es2015-polyfills-option.js.map +1 -0
  69. package/src/migrations/update-15-6-3/webpack-config-setup.d.ts +2 -0
  70. package/src/migrations/update-15-6-3/webpack-config-setup.js +105 -0
  71. package/src/migrations/update-15-6-3/webpack-config-setup.js.map +1 -0
  72. package/src/migrations/update-15-7-2/add-babelUpwardRootMode-flag.d.ts +2 -0
  73. package/src/migrations/update-15-7-2/add-babelUpwardRootMode-flag.js +21 -0
  74. package/src/migrations/update-15-7-2/add-babelUpwardRootMode-flag.js.map +1 -0
  75. package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.d.ts +2 -0
  76. package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.js +13 -0
  77. package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.js.map +1 -0
  78. package/src/plugins/generate-package-json-plugin.d.ts +12 -0
  79. package/src/plugins/generate-package-json-plugin.js +49 -0
  80. package/src/plugins/generate-package-json-plugin.js.map +1 -0
  81. package/src/plugins/stats-json-plugin.d.ts +4 -0
  82. package/src/plugins/stats-json-plugin.js +14 -0
  83. package/src/plugins/stats-json-plugin.js.map +1 -0
  84. package/src/plugins/webpack-nx-build-coordination-plugin.d.ts +9 -0
  85. package/src/plugins/webpack-nx-build-coordination-plugin.js +84 -0
  86. package/src/plugins/webpack-nx-build-coordination-plugin.js.map +1 -0
  87. package/src/plugins/write-index-html-plugin.d.ts +22 -0
  88. package/src/plugins/write-index-html-plugin.js +251 -0
  89. package/src/plugins/write-index-html-plugin.js.map +1 -0
  90. package/src/utils/config.d.ts +17 -0
  91. package/src/utils/config.js +35 -0
  92. package/src/utils/config.js.map +1 -0
  93. package/src/utils/create-copy-plugin.d.ts +3 -0
  94. package/src/utils/create-copy-plugin.js +28 -0
  95. package/src/utils/create-copy-plugin.js.map +1 -0
  96. package/src/utils/fs.d.ts +6 -0
  97. package/src/utils/fs.js +59 -0
  98. package/src/utils/fs.js.map +1 -0
  99. package/src/utils/get-client-environment.d.ts +5 -0
  100. package/src/utils/get-client-environment.js +30 -0
  101. package/src/utils/get-client-environment.js.map +1 -0
  102. package/src/utils/get-css-module-local-ident.d.ts +1 -0
  103. package/src/utils/get-css-module-local-ident.js +19 -0
  104. package/src/utils/get-css-module-local-ident.js.map +1 -0
  105. package/src/utils/hash-format.d.ts +7 -0
  106. package/src/utils/hash-format.js +24 -0
  107. package/src/utils/hash-format.js.map +1 -0
  108. package/src/utils/models.d.ts +23 -0
  109. package/src/utils/models.js +3 -0
  110. package/src/utils/models.js.map +1 -0
  111. package/src/utils/run-webpack.d.ts +5 -0
  112. package/src/utils/run-webpack.js +30 -0
  113. package/src/utils/run-webpack.js.map +1 -0
  114. package/src/utils/versions.d.ts +8 -0
  115. package/src/utils/versions.js +13 -0
  116. package/src/utils/versions.js.map +1 -0
  117. package/src/utils/web-babel-loader.d.ts +0 -0
  118. package/src/utils/web-babel-loader.js +29 -0
  119. package/src/utils/web-babel-loader.js.map +1 -0
  120. package/src/utils/webpack/custom-webpack.d.ts +3 -0
  121. package/src/utils/webpack/custom-webpack.js +42 -0
  122. package/src/utils/webpack/custom-webpack.js.map +1 -0
  123. package/src/utils/webpack/interpolate-env-variables-to-index.d.ts +1 -0
  124. package/src/utils/webpack/interpolate-env-variables-to-index.js +31 -0
  125. package/src/utils/webpack/interpolate-env-variables-to-index.js.map +1 -0
  126. package/src/utils/webpack/normalize-entry.d.ts +2 -0
  127. package/src/utils/webpack/normalize-entry.js +30 -0
  128. package/src/utils/webpack/normalize-entry.js.map +1 -0
  129. package/src/utils/webpack/package-chunk-sort.d.ts +5 -0
  130. package/src/utils/webpack/package-chunk-sort.js +30 -0
  131. package/src/utils/webpack/package-chunk-sort.js.map +1 -0
  132. package/src/utils/webpack/plugins/postcss-cli-resources.d.ts +13 -0
  133. package/src/utils/webpack/plugins/postcss-cli-resources.js +170 -0
  134. package/src/utils/webpack/plugins/postcss-cli-resources.js.map +1 -0
  135. package/src/utils/webpack/plugins/scripts-webpack-plugin.d.ts +17 -0
  136. package/src/utils/webpack/plugins/scripts-webpack-plugin.js +121 -0
  137. package/src/utils/webpack/plugins/scripts-webpack-plugin.js.map +1 -0
  138. package/src/utils/with-nx.d.ts +61 -0
  139. package/src/utils/with-nx.js +285 -0
  140. package/src/utils/with-nx.js.map +1 -0
  141. package/src/utils/with-web.d.ts +21 -0
  142. package/src/utils/with-web.js +468 -0
  143. package/src/utils/with-web.js.map +1 -0
@@ -0,0 +1,414 @@
1
+ {
2
+ "version": 2,
3
+ "outputCapture": "direct-nodejs",
4
+ "title": "Webpack builder",
5
+ "description": "Build a project using webpack.",
6
+ "cli": "nx",
7
+ "type": "object",
8
+ "properties": {
9
+ "crossOrigin": {
10
+ "type": "string",
11
+ "description": "The `crossorigin` attribute to use for generated javascript script tags. One of 'none' | 'anonymous' | 'use-credentials'."
12
+ },
13
+ "main": {
14
+ "type": "string",
15
+ "description": "The name of the main entry-point file.",
16
+ "x-completion-type": "file",
17
+ "x-completion-glob": "**/*@(.js|.ts|.tsx)",
18
+ "x-priority": "important"
19
+ },
20
+ "tsConfig": {
21
+ "type": "string",
22
+ "description": "The name of the Typescript configuration file.",
23
+ "x-completion-type": "file",
24
+ "x-completion-glob": "tsconfig.*.json",
25
+ "x-priority": "important"
26
+ },
27
+ "compiler": {
28
+ "type": "string",
29
+ "description": "The compiler to use.",
30
+ "enum": ["babel", "swc", "tsc"],
31
+ "default": "babel"
32
+ },
33
+ "outputPath": {
34
+ "type": "string",
35
+ "description": "The output path of the generated files.",
36
+ "x-completion-type": "directory",
37
+ "x-priority": "important"
38
+ },
39
+ "target": {
40
+ "type": "string",
41
+ "alias": "platform",
42
+ "description": "Target platform for the build, same as the Webpack target option.",
43
+ "enum": ["node", "web"],
44
+ "default": "web"
45
+ },
46
+ "deleteOutputPath": {
47
+ "type": "boolean",
48
+ "description": "Delete the output path before building.",
49
+ "default": true
50
+ },
51
+ "watch": {
52
+ "type": "boolean",
53
+ "description": "Enable re-building when files change.",
54
+ "default": false
55
+ },
56
+ "baseHref": {
57
+ "type": "string",
58
+ "description": "Base url for the application being built."
59
+ },
60
+ "deployUrl": {
61
+ "type": "string",
62
+ "description": "URL where the application will be deployed."
63
+ },
64
+ "vendorChunk": {
65
+ "type": "boolean",
66
+ "description": "Use a separate bundle containing only vendor libraries.",
67
+ "default": true
68
+ },
69
+ "commonChunk": {
70
+ "type": "boolean",
71
+ "description": "Use a separate bundle containing code used across multiple bundles.",
72
+ "default": true
73
+ },
74
+ "runtimeChunk": {
75
+ "type": "boolean",
76
+ "description": "Use a separate bundle containing the runtime.",
77
+ "default": true
78
+ },
79
+ "sourceMap": {
80
+ "description": "Output sourcemaps. Use 'hidden' for use with error reporting tools without generating sourcemap comment.",
81
+ "default": true,
82
+ "oneOf": [
83
+ {
84
+ "type": "boolean"
85
+ },
86
+ {
87
+ "type": "string"
88
+ }
89
+ ]
90
+ },
91
+ "progress": {
92
+ "type": "boolean",
93
+ "description": "Log progress to the console while building.",
94
+ "default": false
95
+ },
96
+ "assets": {
97
+ "type": "array",
98
+ "description": "List of static application assets.",
99
+ "default": [],
100
+ "items": {
101
+ "$ref": "#/definitions/assetPattern"
102
+ }
103
+ },
104
+ "index": {
105
+ "type": "string",
106
+ "description": "HTML File which will be contain the application.",
107
+ "x-completion-type": "file",
108
+ "x-completion-glob": "**/*@(.html|.htm)"
109
+ },
110
+ "scripts": {
111
+ "type": "array",
112
+ "description": "External Scripts which will be included before the main application entry.",
113
+ "items": {
114
+ "$ref": "#/definitions/extraEntryPoint"
115
+ },
116
+ "default": []
117
+ },
118
+ "styles": {
119
+ "type": "array",
120
+ "description": "External Styles which will be included with the application",
121
+ "items": {
122
+ "$ref": "#/definitions/extraEntryPoint"
123
+ },
124
+ "default": []
125
+ },
126
+ "namedChunks": {
127
+ "type": "boolean",
128
+ "description": "Names the produced bundles according to their entry file.",
129
+ "default": true
130
+ },
131
+ "outputHashing": {
132
+ "type": "string",
133
+ "description": "Define the output filename cache-busting hashing mode.",
134
+ "default": "none",
135
+ "enum": ["none", "all", "media", "bundles"]
136
+ },
137
+ "stylePreprocessorOptions": {
138
+ "description": "Options to pass to style preprocessors.",
139
+ "type": "object",
140
+ "properties": {
141
+ "includePaths": {
142
+ "description": "Paths to include. Paths will be resolved to project root.",
143
+ "type": "array",
144
+ "items": {
145
+ "type": "string"
146
+ },
147
+ "default": []
148
+ }
149
+ },
150
+ "additionalProperties": false
151
+ },
152
+ "optimization": {
153
+ "description": "Enables optimization of the build output.",
154
+ "oneOf": [
155
+ {
156
+ "type": "object",
157
+ "properties": {
158
+ "scripts": {
159
+ "type": "boolean",
160
+ "description": "Enables optimization of the scripts output.",
161
+ "default": true
162
+ },
163
+ "styles": {
164
+ "type": "boolean",
165
+ "description": "Enables optimization of the styles output.",
166
+ "default": true
167
+ }
168
+ },
169
+ "additionalProperties": false
170
+ },
171
+ {
172
+ "type": "boolean"
173
+ }
174
+ ]
175
+ },
176
+ "generatePackageJson": {
177
+ "type": "boolean",
178
+ "description": "Generates a `package.json` and pruned lock file with the project's `node_module` dependencies populated for installing in a container. If a `package.json` exists in the project's directory, it will be reused with dependencies populated.",
179
+ "default": false
180
+ },
181
+ "transformers": {
182
+ "type": "array",
183
+ "description": "List of TypeScript Compiler Transfomers Plugins.",
184
+ "default": [],
185
+ "aliases": ["tsPlugins"],
186
+ "items": {
187
+ "$ref": "#/definitions/transformerPattern"
188
+ }
189
+ },
190
+ "additionalEntryPoints": {
191
+ "type": "array",
192
+ "items": {
193
+ "type": "object",
194
+ "properties": {
195
+ "entryName": {
196
+ "type": "string",
197
+ "description": "Name of the additional entry file."
198
+ },
199
+ "entryPath": {
200
+ "type": "string",
201
+ "description": "Path to the additional entry file.",
202
+ "x-completion-type": "file",
203
+ "x-completion-glob": "**/*@(.js|.ts)"
204
+ }
205
+ }
206
+ }
207
+ },
208
+ "outputFileName": {
209
+ "type": "string",
210
+ "description": "Name of the main output file.",
211
+ "default": "main.js"
212
+ },
213
+ "externalDependencies": {
214
+ "oneOf": [
215
+ {
216
+ "type": "string",
217
+ "enum": ["none", "all"]
218
+ },
219
+ {
220
+ "type": "array",
221
+ "items": {
222
+ "type": "string"
223
+ }
224
+ }
225
+ ],
226
+ "description": "Dependencies to keep external to the bundle. (`all` (default), `none`, or an array of module names)",
227
+ "default": "all"
228
+ },
229
+ "extractCss": {
230
+ "type": "boolean",
231
+ "description": "Extract CSS into a `.css` file.",
232
+ "default": true
233
+ },
234
+ "subresourceIntegrity": {
235
+ "type": "boolean",
236
+ "description": "Enables the use of subresource integrity validation.",
237
+ "default": false
238
+ },
239
+ "polyfills": {
240
+ "type": "string",
241
+ "description": "Polyfills to load before application",
242
+ "x-completion-type": "file",
243
+ "x-completion-glob": "**/*@(.js|.ts|.tsx)"
244
+ },
245
+ "verbose": {
246
+ "type": "boolean",
247
+ "description": "Emits verbose output",
248
+ "default": false
249
+ },
250
+ "statsJson": {
251
+ "type": "boolean",
252
+ "description": "Generates a 'stats.json' file which can be analyzed using tools such as: 'webpack-bundle-analyzer' or `<https://webpack.github.io/analyse>`.",
253
+ "default": false
254
+ },
255
+ "isolatedConfig": {
256
+ "type": "boolean",
257
+ "description": "Do not apply Nx webpack plugins automatically. Plugins need to be applied in the project's webpack.config.js file (e.g. withNx, withReact, etc.).",
258
+ "default": false
259
+ },
260
+ "extractLicenses": {
261
+ "type": "boolean",
262
+ "description": "Extract all licenses in a separate file, in the case of production builds only.",
263
+ "default": false
264
+ },
265
+ "memoryLimit": {
266
+ "type": "number",
267
+ "description": "Memory limit for type checking service process in `MB`.",
268
+ "default": 2048
269
+ },
270
+ "fileReplacements": {
271
+ "description": "Replace files with other files in the build.",
272
+ "type": "array",
273
+ "items": {
274
+ "type": "object",
275
+ "properties": {
276
+ "replace": {
277
+ "type": "string",
278
+ "description": "The file to be replaced.",
279
+ "x-completion-type": "file"
280
+ },
281
+ "with": {
282
+ "type": "string",
283
+ "description": "The file to replace with.",
284
+ "x-completion-type": "file"
285
+ }
286
+ },
287
+ "additionalProperties": false,
288
+ "required": ["replace", "with"]
289
+ },
290
+ "default": []
291
+ },
292
+ "buildLibsFromSource": {
293
+ "type": "boolean",
294
+ "description": "Read buildable libraries from source instead of building them separately.",
295
+ "default": true
296
+ },
297
+ "generateIndexHtml": {
298
+ "type": "boolean",
299
+ "description": "Generates `index.html` file to the output path. This can be turned off if using a webpack plugin to generate HTML such as `html-webpack-plugin`.",
300
+ "default": true
301
+ },
302
+ "postcssConfig": {
303
+ "type": "string",
304
+ "description": "Set a path to PostCSS config that applies to the app and all libs. Defaults to `undefined`, which auto-detects postcss.config.js files in each `app`/`lib` directory."
305
+ },
306
+ "webpackConfig": {
307
+ "type": "string",
308
+ "description": "Path to a function which takes a webpack config, some context and returns the resulting webpack config. See https://nx.dev/guides/customize-webpack",
309
+ "x-completion-type": "file",
310
+ "x-completion-glob": "webpack?(*)@(.js|.ts)",
311
+ "x-priority": "important"
312
+ },
313
+ "babelUpwardRootMode": {
314
+ "type": "boolean",
315
+ "description": "Whether to set rootmode to upward. See https://babeljs.io/docs/en/options#rootmode",
316
+ "default": false
317
+ },
318
+ "babelConfig": {
319
+ "type": "string",
320
+ "description": "Path to the babel configuration file of your project. If not provided, Nx will default to the .babelrc file at the root of your project. See https://babeljs.io/docs/en/config-files",
321
+ "x-completion-type": "file"
322
+ }
323
+ },
324
+ "required": ["tsConfig", "main"],
325
+ "definitions": {
326
+ "assetPattern": {
327
+ "oneOf": [
328
+ {
329
+ "type": "object",
330
+ "properties": {
331
+ "glob": {
332
+ "type": "string",
333
+ "description": "The pattern to match."
334
+ },
335
+ "input": {
336
+ "type": "string",
337
+ "description": "The input directory path in which to apply 'glob'. Defaults to the project root."
338
+ },
339
+ "ignore": {
340
+ "description": "An array of globs to ignore.",
341
+ "type": "array",
342
+ "items": {
343
+ "type": "string"
344
+ }
345
+ },
346
+ "output": {
347
+ "type": "string",
348
+ "description": "Absolute path within the output."
349
+ }
350
+ },
351
+ "additionalProperties": false,
352
+ "required": ["glob", "input", "output"]
353
+ },
354
+ {
355
+ "type": "string"
356
+ }
357
+ ]
358
+ },
359
+ "extraEntryPoint": {
360
+ "oneOf": [
361
+ {
362
+ "type": "object",
363
+ "properties": {
364
+ "input": {
365
+ "type": "string",
366
+ "description": "The file to include.",
367
+ "x-completion-type": "file",
368
+ "x-completion-glob": "**/*@(.css|.scss|.less|.sass|.styl|.stylus)"
369
+ },
370
+ "bundleName": {
371
+ "type": "string",
372
+ "description": "The bundle name for this extra entry point."
373
+ },
374
+ "inject": {
375
+ "type": "boolean",
376
+ "description": "If the bundle will be referenced in the HTML file.",
377
+ "default": true
378
+ }
379
+ },
380
+ "additionalProperties": false,
381
+ "required": ["input"]
382
+ },
383
+ {
384
+ "type": "string",
385
+ "description": "The file to include.",
386
+ "x-completion-type": "file",
387
+ "x-completion-glob": "**/*@(.css|.scss|.less|.sass|.styl|.stylus)"
388
+ }
389
+ ]
390
+ },
391
+ "transformerPattern": {
392
+ "oneOf": [
393
+ {
394
+ "type": "string"
395
+ },
396
+ {
397
+ "type": "object",
398
+ "properties": {
399
+ "name": {
400
+ "type": "string"
401
+ },
402
+ "options": {
403
+ "type": "object",
404
+ "additionalProperties": true
405
+ }
406
+ },
407
+ "additionalProperties": false,
408
+ "required": ["name"]
409
+ }
410
+ ]
411
+ }
412
+ },
413
+ "examplesFile": "../../../docs/webpack-build-executor-examples.md"
414
+ }
@@ -0,0 +1,14 @@
1
+ import 'dotenv/config';
2
+ import { ExecutorContext } from '@nx/devkit';
3
+ import type { WebpackExecutorOptions } from './schema';
4
+ export type WebpackExecutorEvent = {
5
+ success: false;
6
+ outfile?: string;
7
+ options?: WebpackExecutorOptions;
8
+ } | {
9
+ success: true;
10
+ outfile: string;
11
+ options?: WebpackExecutorOptions;
12
+ };
13
+ export declare function webpackExecutor(_options: WebpackExecutorOptions, context: ExecutorContext): AsyncGenerator<WebpackExecutorEvent, WebpackExecutorEvent, undefined>;
14
+ export default webpackExecutor;
@@ -0,0 +1,107 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.webpackExecutor = void 0;
4
+ const tslib_1 = require("tslib");
5
+ require("dotenv/config");
6
+ const devkit_1 = require("@nx/devkit");
7
+ const rxjs_for_await_1 = require("@nx/devkit/src/utils/rxjs-for-await");
8
+ const rxjs_1 = require("rxjs");
9
+ const operators_1 = require("rxjs/operators");
10
+ const path_1 = require("path");
11
+ const buildable_libs_utils_1 = require("@nx/js/src/utils/buildable-libs-utils");
12
+ const get_webpack_config_1 = require("./lib/get-webpack-config");
13
+ const run_webpack_1 = require("./lib/run-webpack");
14
+ const fs_1 = require("../../utils/fs");
15
+ const custom_webpack_1 = require("../../utils/webpack/custom-webpack");
16
+ const normalize_options_1 = require("./lib/normalize-options");
17
+ function getWebpackConfigs(options, context) {
18
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
19
+ if (options.isolatedConfig && !options.webpackConfig) {
20
+ throw new Error(`Using "isolatedConfig" without a "webpackConfig" is not supported.`);
21
+ }
22
+ let customWebpack = null;
23
+ if (options.webpackConfig) {
24
+ customWebpack = (0, custom_webpack_1.resolveCustomWebpackConfig)(options.webpackConfig, options.tsConfig);
25
+ if (typeof customWebpack.then === 'function') {
26
+ customWebpack = yield customWebpack;
27
+ }
28
+ }
29
+ const config = options.isolatedConfig
30
+ ? {}
31
+ : (0, get_webpack_config_1.getWebpackConfig)(context, options);
32
+ if (customWebpack) {
33
+ return yield customWebpack(config, {
34
+ options,
35
+ context,
36
+ configuration: context.configurationName, // backwards compat
37
+ });
38
+ }
39
+ else {
40
+ // If the user has no webpackConfig specified then we always have to apply
41
+ return config;
42
+ }
43
+ });
44
+ }
45
+ function webpackExecutor(_options, context) {
46
+ var _a;
47
+ return tslib_1.__asyncGenerator(this, arguments, function* webpackExecutor_1() {
48
+ const metadata = context.projectsConfigurations.projects[context.projectName];
49
+ const sourceRoot = metadata.sourceRoot;
50
+ const options = (0, normalize_options_1.normalizeOptions)(_options, context.root, metadata.root, sourceRoot);
51
+ const isScriptOptimizeOn = typeof options.optimization === 'boolean'
52
+ ? options.optimization
53
+ : options.optimization && options.optimization.scripts
54
+ ? options.optimization.scripts
55
+ : false;
56
+ (_a = process.env).NODE_ENV || (_a.NODE_ENV = isScriptOptimizeOn
57
+ ? 'production'
58
+ : 'development');
59
+ if (options.compiler === 'swc') {
60
+ try {
61
+ require.resolve('swc-loader');
62
+ require.resolve('@swc/core');
63
+ }
64
+ catch (_b) {
65
+ devkit_1.logger.error(`Missing SWC dependencies: @swc/core, swc-loader. Make sure you install them first.`);
66
+ return yield tslib_1.__await({
67
+ success: false,
68
+ outfile: (0, path_1.resolve)(context.root, options.outputPath, options.outputFileName),
69
+ options,
70
+ });
71
+ }
72
+ }
73
+ if (!options.buildLibsFromSource && context.targetName) {
74
+ const { dependencies } = (0, buildable_libs_utils_1.calculateProjectDependencies)(context.projectGraph, context.root, context.projectName, context.targetName, context.configurationName);
75
+ options.tsConfig = (0, buildable_libs_utils_1.createTmpTsConfig)(options.tsConfig, context.root, metadata.root, dependencies);
76
+ }
77
+ // Delete output path before bundling
78
+ if (options.deleteOutputPath) {
79
+ (0, fs_1.deleteOutputDir)(context.root, options.outputPath);
80
+ }
81
+ const configs = yield tslib_1.__await(getWebpackConfigs(options, context));
82
+ return yield tslib_1.__await(yield tslib_1.__await(yield* tslib_1.__asyncDelegator(tslib_1.__asyncValues((0, rxjs_for_await_1.eachValueFrom)((0, rxjs_1.of)(configs).pipe((0, operators_1.mergeMap)((config) => (Array.isArray(config) ? (0, rxjs_1.from)(config) : (0, rxjs_1.of)(config))),
83
+ // Run build sequentially and bail when first one fails.
84
+ (0, operators_1.mergeScan)((acc, config) => {
85
+ if (!acc.hasErrors()) {
86
+ return (0, run_webpack_1.runWebpack)(config).pipe((0, operators_1.tap)((stats) => {
87
+ console.info(stats.toString(config.stats));
88
+ }));
89
+ }
90
+ else {
91
+ return (0, rxjs_1.of)();
92
+ }
93
+ }, { hasErrors: () => false }, 1),
94
+ // Collect build results as an array.
95
+ (0, operators_1.bufferCount)(Array.isArray(configs) ? configs.length : 1), (0, operators_1.switchMap)((results) => tslib_1.__awaiter(this, void 0, void 0, function* () {
96
+ const success = results.every((result) => Boolean(result) && !result.hasErrors());
97
+ return {
98
+ success,
99
+ outfile: (0, path_1.resolve)(context.root, options.outputPath, options.outputFileName),
100
+ options,
101
+ };
102
+ }))))))));
103
+ });
104
+ }
105
+ exports.webpackExecutor = webpackExecutor;
106
+ exports.default = webpackExecutor;
107
+ //# sourceMappingURL=webpack.impl.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"webpack.impl.js","sourceRoot":"","sources":["../../../../../../packages/webpack/src/executors/webpack/webpack.impl.ts"],"names":[],"mappings":";;;;AAAA,yBAAuB;AACvB,uCAAqD;AACrD,wEAAoE;AAEpE,+BAAgC;AAChC,8CAMwB;AACxB,+BAA+B;AAC/B,gFAG+C;AAE/C,iEAA4D;AAC5D,mDAA+C;AAC/C,uCAAiD;AACjD,uEAAgF;AAKhF,+DAA2D;AAE3D,SAAe,iBAAiB,CAC9B,OAAyC,EACzC,OAAwB;;QAExB,IAAI,OAAO,CAAC,cAAc,IAAI,CAAC,OAAO,CAAC,aAAa,EAAE;YACpD,MAAM,IAAI,KAAK,CACb,oEAAoE,CACrE,CAAC;SACH;QAED,IAAI,aAAa,GAAG,IAAI,CAAC;QAEzB,IAAI,OAAO,CAAC,aAAa,EAAE;YACzB,aAAa,GAAG,IAAA,2CAA0B,EACxC,OAAO,CAAC,aAAa,EACrB,OAAO,CAAC,QAAQ,CACjB,CAAC;YAEF,IAAI,OAAO,aAAa,CAAC,IAAI,KAAK,UAAU,EAAE;gBAC5C,aAAa,GAAG,MAAM,aAAa,CAAC;aACrC;SACF;QAED,MAAM,MAAM,GAAG,OAAO,CAAC,cAAc;YACnC,CAAC,CAAC,EAAE;YACJ,CAAC,CAAC,IAAA,qCAAgB,EAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QAEvC,IAAI,aAAa,EAAE;YAC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,EAAE,EAAE;oBACZ,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;gBAC7C,CAAC,CAAC,CACH,CAAC;aACH;iBAAM;gBACL,OAAO,IAAA,SAAE,GAAE,CAAC;aACb;QACH,CAAC,EACD,EAAE,SAAS,EAAE,GAAG,EAAE,CAAC,KAAK,EAAW,EACnC,CAAC,CACF;QACD,qCAAqC;QACrC,IAAA,uBAAW,EAAC,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,EACxD,IAAA,qBAAS,EAAC,CAAO,OAAO,EAAE,EAAE;YAC1B,MAAM,OAAO,GAAG,OAAO,CAAC,KAAK,CAC3B,CAAC,MAAM,EAAE,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,SAAS,EAAE,CACnD,CAAC;YACF,OAAO;gBACL,OAAO;gBACP,OAAO,EAAE,IAAA,cAAO,EACd,OAAO,CAAC,IAAI,EACZ,OAAO,CAAC,UAAU,EAClB,OAAO,CAAC,cAAc,CACvB;gBACD,OAAO;aACR,CAAC;QACJ,CAAC,CAAA,CAAC,CACH,CACF,CAAA,CAAA,CAAA,EAAC;;CACH;AAvGD,0CAuGC;AAED,kBAAe,eAAe,CAAC"}
@@ -0,0 +1,5 @@
1
+ import { Tree } from '@nx/devkit';
2
+ import { Schema } from './schema';
3
+ export declare function webpackInitGenerator(tree: Tree, schema: Schema): Promise<import("@nx/devkit").GeneratorCallback>;
4
+ export default webpackInitGenerator;
5
+ export declare const webpackInitSchematic: (generatorOptions: Schema) => (tree: any, context: any) => Promise<any>;
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.webpackInitSchematic = exports.webpackInitGenerator = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const devkit_1 = require("@nx/devkit");
6
+ const versions_1 = require("@nx/js/src/utils/versions");
7
+ const versions_2 = require("../../utils/versions");
8
+ const add_babel_inputs_1 = require("@nx/js/src/utils/add-babel-inputs");
9
+ function webpackInitGenerator(tree, schema) {
10
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
11
+ if (schema.compiler === 'babel') {
12
+ (0, add_babel_inputs_1.addBabelInputs)(tree);
13
+ }
14
+ const devDependencies = {
15
+ '@nrwl/webpack': versions_2.nxVersion,
16
+ };
17
+ if (schema.compiler === 'swc') {
18
+ devDependencies['@swc/helpers'] = versions_2.swcHelpersVersion;
19
+ devDependencies['@swc/core'] = versions_1.swcCoreVersion;
20
+ devDependencies['swc-loader'] = versions_2.swcLoaderVersion;
21
+ }
22
+ if (schema.compiler === 'tsc') {
23
+ devDependencies['tslib'] = versions_2.tsLibVersion;
24
+ }
25
+ if (schema.uiFramework === 'react') {
26
+ devDependencies['@pmmmwh/react-refresh-webpack-plugin'] =
27
+ versions_2.reactRefreshWebpackPluginVersion;
28
+ devDependencies['@svgr/webpack'] = versions_2.svgrWebpackVersion;
29
+ devDependencies['react-refresh'] = versions_2.reactRefreshVersion;
30
+ devDependencies['url-loader'] = versions_2.urlLoaderVersion;
31
+ }
32
+ if (!schema.skipFormat) {
33
+ yield (0, devkit_1.formatFiles)(tree);
34
+ }
35
+ return (0, devkit_1.addDependenciesToPackageJson)(tree, {}, devDependencies);
36
+ });
37
+ }
38
+ exports.webpackInitGenerator = webpackInitGenerator;
39
+ exports.default = webpackInitGenerator;
40
+ exports.webpackInitSchematic = (0, devkit_1.convertNxGenerator)(webpackInitGenerator);
41
+ //# sourceMappingURL=init.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"init.js","sourceRoot":"","sources":["../../../../../../packages/webpack/src/generators/init/init.ts"],"names":[],"mappings":";;;;AAAA,uCAKoB;AACpB,wDAA2D;AAG3D,mDAS8B;AAC9B,wEAAmE;AAEnE,SAAsB,oBAAoB,CAAC,IAAU,EAAE,MAAc;;QACnE,IAAI,MAAM,CAAC,QAAQ,KAAK,OAAO,EAAE;YAC/B,IAAA,iCAAc,EAAC,IAAI,CAAC,CAAC;SACtB;QACD,MAAM,eAAe,GAAG;YACtB,eAAe,EAAE,oBAAS;SAC3B,CAAC;QAEF,IAAI,MAAM,CAAC,QAAQ,KAAK,KAAK,EAAE;YAC7B,eAAe,CAAC,cAAc,CAAC,GAAG,4BAAiB,CAAC;YACpD,eAAe,CAAC,WAAW,CAAC,GAAG,yBAAc,CAAC;YAC9C,eAAe,CAAC,YAAY,CAAC,GAAG,2BAAgB,CAAC;SAClD;QAED,IAAI,MAAM,CAAC,QAAQ,KAAK,KAAK,EAAE;YAC7B,eAAe,CAAC,OAAO,CAAC,GAAG,uBAAY,CAAC;SACzC;QAED,IAAI,MAAM,CAAC,WAAW,KAAK,OAAO,EAAE;YAClC,eAAe,CAAC,sCAAsC,CAAC;gBACrD,2CAAgC,CAAC;YACnC,eAAe,CAAC,eAAe,CAAC,GAAG,6BAAkB,CAAC;YACtD,eAAe,CAAC,eAAe,CAAC,GAAG,8BAAmB,CAAC;YACvD,eAAe,CAAC,YAAY,CAAC,GAAG,2BAAgB,CAAC;SAClD;QAED,IAAI,CAAC,MAAM,CAAC,UAAU,EAAE;YACtB,MAAM,IAAA,oBAAW,EAAC,IAAI,CAAC,CAAC;SACzB;QAED,OAAO,IAAA,qCAA4B,EAAC,IAAI,EAAE,EAAE,EAAE,eAAe,CAAC,CAAC;IACjE,CAAC;CAAA;AA/BD,oDA+BC;AAED,kBAAe,oBAAoB,CAAC;AAEvB,QAAA,oBAAoB,GAAG,IAAA,2BAAkB,EAAC,oBAAoB,CAAC,CAAC"}
@@ -0,0 +1,5 @@
1
+ export interface Schema {
2
+ compiler?: 'babel' | 'swc' | 'tsc';
3
+ uiFramework?: 'react' | 'none';
4
+ skipFormat?: boolean;
5
+ }
@@ -0,0 +1,28 @@
1
+ {
2
+ "$schema": "http://json-schema.org/schema",
3
+ "$id": "NxWebpackInit",
4
+ "cli": "nx",
5
+ "title": "Init Webpack Plugin",
6
+ "description": "Initialize the Webpack Plugin.",
7
+ "type": "object",
8
+ "properties": {
9
+ "uiFramework": {
10
+ "type": "string",
11
+ "description": "UI Framework to use for Webpack.",
12
+ "enum": ["react", "none"],
13
+ "x-prompt": "What UI framework plugin should Webpack use?"
14
+ },
15
+ "compiler": {
16
+ "type": "string",
17
+ "enum": ["babel", "swc", "tsc"],
18
+ "description": "The compiler to initialize for.",
19
+ "default": "babel"
20
+ },
21
+ "skipFormat": {
22
+ "description": "Skip formatting files.",
23
+ "type": "boolean",
24
+ "default": false
25
+ }
26
+ },
27
+ "required": []
28
+ }
@@ -0,0 +1,13 @@
1
+ export interface WebpackProjectGeneratorSchema {
2
+ project: string;
3
+ main?: string;
4
+ tsConfig?: string;
5
+ compiler?: 'babel' | 'swc' | 'tsc';
6
+ devServer?: boolean;
7
+ skipFormat?: boolean;
8
+ skipPackageJson?: boolean;
9
+ skipValidation?: boolean;
10
+ target?: 'node' | 'web';
11
+ webpackConfig?: string;
12
+ babelConfig?: string;
13
+ }