@nx/webpack 0.0.0-pr-22179-271588f

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 (146) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +68 -0
  3. package/executors.json +19 -0
  4. package/generators.json +20 -0
  5. package/index.d.ts +18 -0
  6. package/index.js +24 -0
  7. package/migrations.json +60 -0
  8. package/package.json +74 -0
  9. package/plugin.d.ts +1 -0
  10. package/plugin.js +5 -0
  11. package/src/executors/dev-server/dev-server.impl.d.ts +7 -0
  12. package/src/executors/dev-server/dev-server.impl.js +79 -0
  13. package/src/executors/dev-server/lib/get-dev-server-config.d.ts +4 -0
  14. package/src/executors/dev-server/lib/get-dev-server-config.js +79 -0
  15. package/src/executors/dev-server/lib/serve-path.d.ts +3 -0
  16. package/src/executors/dev-server/lib/serve-path.js +45 -0
  17. package/src/executors/dev-server/schema.d.ts +17 -0
  18. package/src/executors/dev-server/schema.json +76 -0
  19. package/src/executors/ssr-dev-server/lib/wait-until-server-is-listening.d.ts +1 -0
  20. package/src/executors/ssr-dev-server/lib/wait-until-server-is-listening.js +39 -0
  21. package/src/executors/ssr-dev-server/schema.d.ts +11 -0
  22. package/src/executors/ssr-dev-server/schema.json +37 -0
  23. package/src/executors/ssr-dev-server/ssr-dev-server.impl.d.ts +8 -0
  24. package/src/executors/ssr-dev-server/ssr-dev-server.impl.js +39 -0
  25. package/src/executors/webpack/lib/normalize-options.d.ts +3 -0
  26. package/src/executors/webpack/lib/normalize-options.js +40 -0
  27. package/src/executors/webpack/lib/run-webpack.d.ts +3 -0
  28. package/src/executors/webpack/lib/run-webpack.js +36 -0
  29. package/src/executors/webpack/schema.d.ts +96 -0
  30. package/src/executors/webpack/schema.json +394 -0
  31. package/src/executors/webpack/webpack.impl.d.ts +13 -0
  32. package/src/executors/webpack/webpack.impl.js +125 -0
  33. package/src/generators/configuration/configuration.d.ts +5 -0
  34. package/src/generators/configuration/configuration.js +194 -0
  35. package/src/generators/configuration/schema.d.ts +14 -0
  36. package/src/generators/configuration/schema.json +77 -0
  37. package/src/generators/init/init.d.ts +5 -0
  38. package/src/generators/init/init.js +60 -0
  39. package/src/generators/init/schema.d.ts +7 -0
  40. package/src/generators/init/schema.json +33 -0
  41. package/src/migrations/update-15-0-0/add-babel-inputs.d.ts +2 -0
  42. package/src/migrations/update-15-0-0/add-babel-inputs.js +9 -0
  43. package/src/migrations/update-15-4-5/remove-es2015-polyfills-option.d.ts +2 -0
  44. package/src/migrations/update-15-4-5/remove-es2015-polyfills-option.js +20 -0
  45. package/src/migrations/update-15-6-3/webpack-config-setup.d.ts +2 -0
  46. package/src/migrations/update-15-6-3/webpack-config-setup.js +100 -0
  47. package/src/migrations/update-15-7-2/add-babelUpwardRootMode-flag.d.ts +2 -0
  48. package/src/migrations/update-15-7-2/add-babelUpwardRootMode-flag.js +17 -0
  49. package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.d.ts +2 -0
  50. package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.js +9 -0
  51. package/src/migrations/update-17-2-1/webpack-config-setup.d.ts +2 -0
  52. package/src/migrations/update-17-2-1/webpack-config-setup.js +31 -0
  53. package/src/plugins/generate-package-json-plugin.d.ts +14 -0
  54. package/src/plugins/generate-package-json-plugin.js +44 -0
  55. package/src/plugins/nx-typescript-webpack-plugin/nx-tsconfig-paths-webpack-plugin.d.ts +8 -0
  56. package/src/plugins/nx-typescript-webpack-plugin/nx-tsconfig-paths-webpack-plugin.js +31 -0
  57. package/src/plugins/nx-webpack-plugin/lib/apply-base-config.d.ts +5 -0
  58. package/src/plugins/nx-webpack-plugin/lib/apply-base-config.js +318 -0
  59. package/src/plugins/nx-webpack-plugin/lib/apply-web-config.d.ts +5 -0
  60. package/src/plugins/nx-webpack-plugin/lib/apply-web-config.js +372 -0
  61. package/src/plugins/nx-webpack-plugin/lib/compiler-loaders.d.ts +53 -0
  62. package/src/plugins/nx-webpack-plugin/lib/compiler-loaders.js +78 -0
  63. package/src/plugins/nx-webpack-plugin/lib/get-terser-ecma-version.d.ts +1 -0
  64. package/src/plugins/nx-webpack-plugin/lib/get-terser-ecma-version.js +35 -0
  65. package/src/plugins/nx-webpack-plugin/lib/instantiate-script-plugins.d.ts +3 -0
  66. package/src/plugins/nx-webpack-plugin/lib/instantiate-script-plugins.js +42 -0
  67. package/src/plugins/nx-webpack-plugin/lib/normalize-options.d.ts +4 -0
  68. package/src/plugins/nx-webpack-plugin/lib/normalize-options.js +143 -0
  69. package/src/plugins/nx-webpack-plugin/lib/stylesheet-loaders.d.ts +73 -0
  70. package/src/plugins/nx-webpack-plugin/lib/stylesheet-loaders.js +117 -0
  71. package/src/plugins/nx-webpack-plugin/nx-webpack-plugin-options.d.ts +216 -0
  72. package/src/plugins/nx-webpack-plugin/nx-webpack-plugin-options.js +2 -0
  73. package/src/plugins/nx-webpack-plugin/nx-webpack-plugin.d.ts +17 -0
  74. package/src/plugins/nx-webpack-plugin/nx-webpack-plugin.js +48 -0
  75. package/src/plugins/plugin.d.ts +9 -0
  76. package/src/plugins/plugin.js +131 -0
  77. package/src/plugins/stats-json-plugin.d.ts +4 -0
  78. package/src/plugins/stats-json-plugin.js +13 -0
  79. package/src/plugins/webpack-nx-build-coordination-plugin.d.ts +11 -0
  80. package/src/plugins/webpack-nx-build-coordination-plugin.js +85 -0
  81. package/src/plugins/write-index-html-plugin.d.ts +22 -0
  82. package/src/plugins/write-index-html-plugin.js +249 -0
  83. package/src/utils/config.d.ts +22 -0
  84. package/src/utils/config.js +66 -0
  85. package/src/utils/create-copy-plugin.d.ts +3 -0
  86. package/src/utils/create-copy-plugin.js +26 -0
  87. package/src/utils/ensure-dependencies.d.ts +6 -0
  88. package/src/utils/ensure-dependencies.js +28 -0
  89. package/src/utils/fs.d.ts +6 -0
  90. package/src/utils/fs.js +58 -0
  91. package/src/utils/get-client-environment.d.ts +5 -0
  92. package/src/utils/get-client-environment.js +29 -0
  93. package/src/utils/get-css-module-local-ident.d.ts +1 -0
  94. package/src/utils/get-css-module-local-ident.js +18 -0
  95. package/src/utils/has-plugin.d.ts +2 -0
  96. package/src/utils/has-plugin.js +11 -0
  97. package/src/utils/hash-format.d.ts +7 -0
  98. package/src/utils/hash-format.js +23 -0
  99. package/src/utils/models.d.ts +23 -0
  100. package/src/utils/models.js +2 -0
  101. package/src/utils/module-federation/dependencies.d.ts +6 -0
  102. package/src/utils/module-federation/dependencies.js +57 -0
  103. package/src/utils/module-federation/get-remotes-for-host.d.ts +14 -0
  104. package/src/utils/module-federation/get-remotes-for-host.js +88 -0
  105. package/src/utils/module-federation/index.d.ts +6 -0
  106. package/src/utils/module-federation/index.js +9 -0
  107. package/src/utils/module-federation/models/index.d.ts +39 -0
  108. package/src/utils/module-federation/models/index.js +2 -0
  109. package/src/utils/module-federation/package-json.d.ts +8 -0
  110. package/src/utils/module-federation/package-json.js +13 -0
  111. package/src/utils/module-federation/public-api.d.ts +6 -0
  112. package/src/utils/module-federation/public-api.js +16 -0
  113. package/src/utils/module-federation/remotes.d.ts +19 -0
  114. package/src/utils/module-federation/remotes.js +80 -0
  115. package/src/utils/module-federation/secondary-entry-points.d.ts +12 -0
  116. package/src/utils/module-federation/secondary-entry-points.js +108 -0
  117. package/src/utils/module-federation/share.d.ts +48 -0
  118. package/src/utils/module-federation/share.js +215 -0
  119. package/src/utils/module-federation/typescript.d.ts +4 -0
  120. package/src/utils/module-federation/typescript.js +54 -0
  121. package/src/utils/run-webpack.d.ts +5 -0
  122. package/src/utils/run-webpack.js +31 -0
  123. package/src/utils/versions.d.ts +8 -0
  124. package/src/utils/versions.js +12 -0
  125. package/src/utils/web-babel-loader.d.ts +0 -0
  126. package/src/utils/web-babel-loader.js +17 -0
  127. package/src/utils/webpack/deprecated-stylus-loader.d.ts +1 -0
  128. package/src/utils/webpack/deprecated-stylus-loader.js +11 -0
  129. package/src/utils/webpack/interpolate-env-variables-to-index.d.ts +1 -0
  130. package/src/utils/webpack/interpolate-env-variables-to-index.js +30 -0
  131. package/src/utils/webpack/normalize-entry.d.ts +2 -0
  132. package/src/utils/webpack/normalize-entry.js +28 -0
  133. package/src/utils/webpack/package-chunk-sort.d.ts +5 -0
  134. package/src/utils/webpack/package-chunk-sort.js +29 -0
  135. package/src/utils/webpack/plugins/postcss-cli-resources.d.ts +13 -0
  136. package/src/utils/webpack/plugins/postcss-cli-resources.js +165 -0
  137. package/src/utils/webpack/plugins/scripts-webpack-plugin.d.ts +17 -0
  138. package/src/utils/webpack/plugins/scripts-webpack-plugin.js +119 -0
  139. package/src/utils/webpack/read-webpack-options.d.ts +10 -0
  140. package/src/utils/webpack/read-webpack-options.js +41 -0
  141. package/src/utils/webpack/resolve-user-defined-webpack-config.d.ts +3 -0
  142. package/src/utils/webpack/resolve-user-defined-webpack-config.js +39 -0
  143. package/src/utils/with-nx.d.ts +8 -0
  144. package/src/utils/with-nx.js +34 -0
  145. package/src/utils/with-web.d.ts +22 -0
  146. package/src/utils/with-web.js +26 -0
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.waitUntilServerIsListening = void 0;
4
+ const net = require("net");
5
+ function waitUntilServerIsListening(port) {
6
+ const allowedErrorCodes = ['ECONNREFUSED', 'ECONNRESET'];
7
+ const maxAttempts = 25;
8
+ let attempts = 0;
9
+ const client = new net.Socket();
10
+ const cleanup = () => {
11
+ client.removeAllListeners('connect');
12
+ client.removeAllListeners('error');
13
+ client.end();
14
+ client.destroy();
15
+ client.unref();
16
+ };
17
+ return new Promise((resolve, reject) => {
18
+ const listen = () => {
19
+ client.once('connect', () => {
20
+ cleanup();
21
+ resolve();
22
+ });
23
+ client.on('error', (err) => {
24
+ if (attempts > maxAttempts ||
25
+ !allowedErrorCodes.includes(err['code'])) {
26
+ cleanup();
27
+ reject(err);
28
+ }
29
+ else {
30
+ attempts++;
31
+ setTimeout(listen, 100 * attempts);
32
+ }
33
+ });
34
+ client.connect({ port, host: 'localhost' });
35
+ };
36
+ listen();
37
+ });
38
+ }
39
+ exports.waitUntilServerIsListening = waitUntilServerIsListening;
@@ -0,0 +1,11 @@
1
+ interface TargetOptions {
2
+ [key: string]: string | boolean | number | TargetOptions;
3
+ }
4
+
5
+ export interface WebSsrDevServerOptions {
6
+ browserTarget: string;
7
+ serverTarget: string;
8
+ port: number;
9
+ browserTargetOptions: TargetOptions;
10
+ serverTargetOptions: TargetOptions;
11
+ }
@@ -0,0 +1,37 @@
1
+ {
2
+ "version": 2,
3
+ "outputCapture": "direct-nodejs",
4
+ "title": "Webpack SSR Dev Server",
5
+ "description": "Serve a SSR application using webpack.",
6
+ "cli": "nx",
7
+ "type": "object",
8
+ "properties": {
9
+ "browserTarget": {
10
+ "type": "string",
11
+ "description": "Target which builds the browser application.",
12
+ "x-priority": "important"
13
+ },
14
+ "serverTarget": {
15
+ "type": "string",
16
+ "description": "Target which builds the server application.",
17
+ "x-priority": "important"
18
+ },
19
+ "port": {
20
+ "type": "number",
21
+ "description": "The port to be set on `process.env.PORT` for use in the server.",
22
+ "default": 4200,
23
+ "x-priority": "important"
24
+ },
25
+ "browserTargetOptions": {
26
+ "type": "object",
27
+ "description": "Additional options to pass into the browser build target.",
28
+ "default": {}
29
+ },
30
+ "serverTargetOptions": {
31
+ "type": "object",
32
+ "description": "Additional options to pass into the server build target.",
33
+ "default": {}
34
+ }
35
+ },
36
+ "required": ["browserTarget", "serverTarget"]
37
+ }
@@ -0,0 +1,8 @@
1
+ import { ExecutorContext } from '@nx/devkit';
2
+ import { TargetOptions, WebSsrDevServerOptions } from './schema';
3
+ export declare function ssrDevServerExecutor(options: WebSsrDevServerOptions, context: ExecutorContext): AsyncGenerator<{
4
+ baseUrl: string;
5
+ success: boolean;
6
+ options: TargetOptions;
7
+ }, void, unknown>;
8
+ export default ssrDevServerExecutor;
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ssrDevServerExecutor = void 0;
4
+ const devkit_1 = require("@nx/devkit");
5
+ const chalk = require("chalk");
6
+ const async_iterable_1 = require("@nx/devkit/src/utils/async-iterable");
7
+ const wait_until_server_is_listening_1 = require("./lib/wait-until-server-is-listening");
8
+ async function* ssrDevServerExecutor(options, context) {
9
+ const browserTarget = (0, devkit_1.parseTargetString)(options.browserTarget, context.projectGraph);
10
+ const serverTarget = (0, devkit_1.parseTargetString)(options.serverTarget, context);
11
+ const browserOptions = (0, devkit_1.readTargetOptions)(browserTarget, context);
12
+ const serverOptions = (0, devkit_1.readTargetOptions)(serverTarget, context);
13
+ const runBrowser = await (0, devkit_1.runExecutor)(browserTarget, { ...browserOptions, ...options.browserTargetOptions }, context);
14
+ const runServer = await (0, devkit_1.runExecutor)(serverTarget, { ...serverOptions, ...options.serverTargetOptions }, context);
15
+ let browserBuilt = false;
16
+ let nodeStarted = false;
17
+ const combined = (0, async_iterable_1.combineAsyncIterables)(runBrowser, runServer);
18
+ process.env['PORT'] = `${options.port}`;
19
+ for await (const output of combined) {
20
+ if (!output.success)
21
+ throw new Error('Could not build application');
22
+ if (output.options?.target === 'node') {
23
+ nodeStarted = true;
24
+ }
25
+ else if (output.options?.target === 'web') {
26
+ browserBuilt = true;
27
+ }
28
+ if (nodeStarted && browserBuilt) {
29
+ await (0, wait_until_server_is_listening_1.waitUntilServerIsListening)(options.port);
30
+ console.log(`[ ${chalk.green('ready')} ] on http://localhost:${options.port}`);
31
+ yield {
32
+ ...output,
33
+ baseUrl: `http://localhost:${options.port}`,
34
+ };
35
+ }
36
+ }
37
+ }
38
+ exports.ssrDevServerExecutor = ssrDevServerExecutor;
39
+ exports.default = ssrDevServerExecutor;
@@ -0,0 +1,3 @@
1
+ import type { NormalizedWebpackExecutorOptions, WebpackExecutorOptions } from '../schema';
2
+ export declare function normalizeOptions(options: WebpackExecutorOptions, root: string, projectRoot: string, sourceRoot: string): NormalizedWebpackExecutorOptions;
3
+ export declare function normalizePluginPath(pluginPath: void | string, root: string): string;
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.normalizePluginPath = exports.normalizeOptions = void 0;
4
+ const path_1 = require("path");
5
+ const normalize_options_1 = require("../../../plugins/nx-webpack-plugin/lib/normalize-options");
6
+ function normalizeOptions(options, root, projectRoot, sourceRoot) {
7
+ const normalizedOptions = {
8
+ ...options,
9
+ root,
10
+ projectRoot,
11
+ sourceRoot,
12
+ target: options.target ?? 'web',
13
+ outputFileName: options.outputFileName ?? 'main.js',
14
+ webpackConfig: normalizePluginPath(options.webpackConfig, root),
15
+ fileReplacements: (0, normalize_options_1.normalizeFileReplacements)(root, options.fileReplacements),
16
+ optimization: typeof options.optimization !== 'object'
17
+ ? {
18
+ scripts: options.optimization,
19
+ styles: options.optimization,
20
+ }
21
+ : options.optimization,
22
+ };
23
+ if (options.assets) {
24
+ normalizedOptions.assets = (0, normalize_options_1.normalizeAssets)(options.assets, root, sourceRoot, projectRoot);
25
+ }
26
+ return normalizedOptions;
27
+ }
28
+ exports.normalizeOptions = normalizeOptions;
29
+ function normalizePluginPath(pluginPath, root) {
30
+ if (!pluginPath) {
31
+ return '';
32
+ }
33
+ try {
34
+ return require.resolve(pluginPath);
35
+ }
36
+ catch {
37
+ return (0, path_1.resolve)(root, pluginPath);
38
+ }
39
+ }
40
+ exports.normalizePluginPath = normalizePluginPath;
@@ -0,0 +1,3 @@
1
+ import * as webpack from 'webpack';
2
+ import { Observable } from 'rxjs';
3
+ export declare function runWebpack(config: webpack.Configuration): Observable<webpack.Stats>;
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.runWebpack = void 0;
4
+ const webpack = require("webpack");
5
+ const rxjs_1 = require("rxjs");
6
+ // TODO(jack): move to dev-server executor
7
+ function runWebpack(config) {
8
+ return new rxjs_1.Observable((subscriber) => {
9
+ // Passing `watch` option here will result in a warning due to missing callback.
10
+ // We manually call `.watch` or `.run` later so this option isn't needed here.
11
+ const { watch, ...normalizedConfig } = config;
12
+ const webpackCompiler = webpack(normalizedConfig);
13
+ const callback = (err, stats) => {
14
+ if (err) {
15
+ subscriber.error(err);
16
+ }
17
+ subscriber.next(stats);
18
+ };
19
+ if (config.watch) {
20
+ const watchOptions = config.watchOptions || {};
21
+ const watching = webpackCompiler.watch(watchOptions, callback);
22
+ return () => watching.close(() => subscriber.complete());
23
+ }
24
+ else {
25
+ webpackCompiler.run((err, stats) => {
26
+ callback(err, stats);
27
+ webpackCompiler.close((closeErr) => {
28
+ if (closeErr)
29
+ subscriber.error(closeErr);
30
+ subscriber.complete();
31
+ });
32
+ });
33
+ }
34
+ });
35
+ }
36
+ exports.runWebpack = runWebpack;
@@ -0,0 +1,96 @@
1
+ import { AssetGlob } from '@nx/js/src/utils/assets/assets';
2
+
3
+ export interface AssetGlobPattern {
4
+ glob: string;
5
+ input: string;
6
+ output: string;
7
+ ignore?: string[];
8
+ }
9
+
10
+ export interface ExtraEntryPointClass {
11
+ bundleName?: string;
12
+ inject?: boolean;
13
+ input: string;
14
+ lazy?: boolean;
15
+ }
16
+
17
+ export interface FileReplacement {
18
+ replace: string;
19
+ with: string;
20
+ }
21
+
22
+ export interface AdditionalEntryPoint {
23
+ entryName: string;
24
+ entryPath: string;
25
+ }
26
+
27
+ export interface TransformerPlugin {
28
+ name: string;
29
+ options: Record<string, unknown>;
30
+ }
31
+
32
+ export type TransformerEntry = string | TransformerPlugin;
33
+
34
+ export interface OptimizationOptions {
35
+ scripts: boolean;
36
+ styles: boolean;
37
+ }
38
+
39
+ export interface WebpackExecutorOptions {
40
+ additionalEntryPoints?: AdditionalEntryPoint[];
41
+ assets?: Array<AssetGlob | string>;
42
+ buildLibsFromSource?: boolean;
43
+ commonChunk?: boolean;
44
+ compiler?: 'babel' | 'swc' | 'tsc';
45
+ deleteOutputPath?: boolean;
46
+ externalDependencies?: 'all' | 'none' | string[];
47
+ extractLicenses?: boolean;
48
+ fileReplacements?: FileReplacement[];
49
+ generatePackageJson?: boolean;
50
+ // TODO(v19): Remove this option
51
+ /** @deprecated set webpackConfig and provide an explicit webpack.config.js file (See: https://nx.dev/recipes/webpack/webpack-config-setup) */
52
+ isolatedConfig?: boolean;
53
+ standardWebpackConfigFunction?: boolean;
54
+ main?: string;
55
+ memoryLimit?: number;
56
+ namedChunks?: boolean;
57
+ optimization?: boolean | OptimizationOptions;
58
+ outputFileName?: string;
59
+ outputHashing?: any;
60
+ outputPath: string;
61
+ poll?: number;
62
+ polyfills?: string;
63
+ progress?: boolean;
64
+ runtimeChunk?: boolean;
65
+ sourceMap?: boolean | 'hidden';
66
+ statsJson?: boolean;
67
+ target?: string;
68
+ transformers?: TransformerEntry[];
69
+ tsConfig?: string;
70
+ vendorChunk?: boolean;
71
+ verbose?: boolean;
72
+ watch?: boolean;
73
+ webpackConfig?: string;
74
+ babelConfig?: string;
75
+ babelUpwardRootMode?: boolean;
76
+ baseHref?: string;
77
+ crossOrigin?: 'none' | 'anonymous' | 'use-credentials';
78
+ deployUrl?: string;
79
+ extractCss?: boolean;
80
+ generateIndexHtml?: boolean;
81
+ index?: string;
82
+ postcssConfig?: string;
83
+ scripts?: Array<ExtraEntryPointClass | string>;
84
+ stylePreprocessorOptions?: any;
85
+ styles?: Array<ExtraEntryPointClass | string>;
86
+ subresourceIntegrity?: boolean;
87
+ }
88
+
89
+ export interface NormalizedWebpackExecutorOptions
90
+ extends WebpackExecutorOptions {
91
+ outputFileName: string;
92
+ assets: AssetGlobPattern[];
93
+ root: string;
94
+ projectRoot: string;
95
+ sourceRoot: string;
96
+ }