@nx/webpack 17.2.0-beta.0 → 17.2.0-beta.10
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/package.json +4 -4
- package/plugin.d.ts +1 -0
- package/plugin.js +5 -0
- package/src/executors/dev-server/dev-server.impl.js +16 -25
- 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.js +6 -2
- package/src/executors/webpack/schema.d.ts +5 -3
- package/src/executors/webpack/schema.json +26 -51
- package/src/executors/webpack/webpack.impl.js +21 -19
- package/src/generators/configuration/configuration.js +69 -18
- package/src/generators/init/init.js +28 -2
- package/src/plugins/nx-webpack-plugin/lib/apply-base-config.js +146 -127
- package/src/plugins/nx-webpack-plugin/lib/apply-web-config.js +15 -5
- package/src/plugins/nx-webpack-plugin/lib/normalize-options.d.ts +2 -1
- package/src/plugins/nx-webpack-plugin/lib/normalize-options.js +25 -2
- package/src/plugins/nx-webpack-plugin/lib/stylesheet-loaders.js +3 -1
- package/src/plugins/nx-webpack-plugin/nx-webpack-plugin-options.d.ts +132 -3
- package/src/plugins/nx-webpack-plugin/nx-webpack-plugin.d.ts +1 -2
- package/src/plugins/nx-webpack-plugin/nx-webpack-plugin.js +9 -17
- package/src/plugins/plugin.d.ts +9 -0
- package/src/plugins/plugin.js +127 -0
- package/src/utils/config.d.ts +11 -6
- package/src/utils/config.js +48 -13
- package/src/utils/has-plugin.d.ts +2 -0
- package/src/utils/has-plugin.js +11 -0
- package/src/utils/versions.d.ts +1 -0
- package/src/utils/versions.js +2 -1
- 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 +1 -0
- package/src/utils/webpack/{custom-webpack.js → resolve-user-defined-webpack-config.js} +3 -8
- package/src/utils/with-nx.d.ts +4 -5
- package/src/utils/with-nx.js +7 -1
- package/src/utils/with-web.d.ts +2 -2
- 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
|
@@ -30,48 +30,177 @@ export interface OptimizationOptions {
|
|
|
30
30
|
styles: boolean;
|
|
31
31
|
}
|
|
32
32
|
export interface NxWebpackPluginOptions {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
33
|
+
/**
|
|
34
|
+
* The tsconfig file for the project. e.g. `tsconfig.json`
|
|
35
|
+
*/
|
|
36
|
+
tsConfig?: string;
|
|
37
|
+
/**
|
|
38
|
+
* The entry point for the bundle. e.g. `src/main.ts`
|
|
39
|
+
*/
|
|
40
|
+
main?: string;
|
|
41
|
+
/**
|
|
42
|
+
* Secondary entry points for the bundle.
|
|
43
|
+
*/
|
|
36
44
|
additionalEntryPoints?: AdditionalEntryPoint[];
|
|
45
|
+
/**
|
|
46
|
+
* Assets to be copied over to the output path.
|
|
47
|
+
*/
|
|
37
48
|
assets?: Array<AssetGlob | string>;
|
|
49
|
+
/**
|
|
50
|
+
* Babel configuration file if compiler is babel.
|
|
51
|
+
*/
|
|
38
52
|
babelConfig?: string;
|
|
53
|
+
/**
|
|
54
|
+
* If true, Babel will look for a babel.config.json up the directory tree.
|
|
55
|
+
*/
|
|
39
56
|
babelUpwardRootMode?: boolean;
|
|
57
|
+
/**
|
|
58
|
+
* Set <base href> for the resulting index.html.
|
|
59
|
+
*/
|
|
40
60
|
baseHref?: string;
|
|
41
61
|
commonChunk?: boolean;
|
|
62
|
+
/**
|
|
63
|
+
* The compiler to use. Default is `babel` and requires a `.babelrc` file.
|
|
64
|
+
*/
|
|
42
65
|
compiler?: 'babel' | 'swc' | 'tsc';
|
|
66
|
+
/**
|
|
67
|
+
* Set `crossorigin` attribute on the `script` and `link` tags.
|
|
68
|
+
*/
|
|
43
69
|
crossOrigin?: 'none' | 'anonymous' | 'use-credentials';
|
|
70
|
+
/**
|
|
71
|
+
* Delete the output path before building.
|
|
72
|
+
*/
|
|
44
73
|
deleteOutputPath?: boolean;
|
|
74
|
+
/**
|
|
75
|
+
* The deploy path for the application. e.g. `/my-app/`
|
|
76
|
+
*/
|
|
45
77
|
deployUrl?: string;
|
|
78
|
+
/**
|
|
79
|
+
* Define external packages that will not be bundled.
|
|
80
|
+
* Use `all` to exclude all 3rd party packages, and `none` to bundle all packages.
|
|
81
|
+
* Use an array to exclude specific packages from the bundle.
|
|
82
|
+
* Default is `none`.
|
|
83
|
+
*/
|
|
46
84
|
externalDependencies?: 'all' | 'none' | string[];
|
|
85
|
+
/**
|
|
86
|
+
* Extract CSS as an external file. Default is `true`.
|
|
87
|
+
*/
|
|
47
88
|
extractCss?: boolean;
|
|
89
|
+
/**
|
|
90
|
+
* Extract licenses from 3rd party modules and add them to the output.
|
|
91
|
+
*/
|
|
48
92
|
extractLicenses?: boolean;
|
|
93
|
+
/**
|
|
94
|
+
* Replace files at build time. e.g. `[{ "replace": "src/a.dev.ts", "with": "src/a.prod.ts" }]`
|
|
95
|
+
*/
|
|
49
96
|
fileReplacements?: FileReplacement[];
|
|
97
|
+
/**
|
|
98
|
+
* Generate an `index.html` file if `index.html` is passed. Default is `true`
|
|
99
|
+
*/
|
|
50
100
|
generateIndexHtml?: boolean;
|
|
101
|
+
/**
|
|
102
|
+
* Generate a `package.json` file for the bundle. Useful for Node applications.
|
|
103
|
+
*/
|
|
51
104
|
generatePackageJson?: boolean;
|
|
105
|
+
/**
|
|
106
|
+
* Path to the `index.html`.
|
|
107
|
+
*/
|
|
52
108
|
index?: string;
|
|
109
|
+
/**
|
|
110
|
+
* Set the memory limit for the type-checking process. Default is `2048`.
|
|
111
|
+
*/
|
|
53
112
|
memoryLimit?: number;
|
|
113
|
+
/**
|
|
114
|
+
* Use the source file name in output chunks. Useful for development or for Node.
|
|
115
|
+
*/
|
|
54
116
|
namedChunks?: boolean;
|
|
117
|
+
/**
|
|
118
|
+
* Optimize the bundle using Terser.
|
|
119
|
+
*/
|
|
55
120
|
optimization?: boolean | OptimizationOptions;
|
|
121
|
+
/**
|
|
122
|
+
* Specify the output filename for the bundle. Useful for Node applications that use `@nx/js:node` to serve.
|
|
123
|
+
*/
|
|
56
124
|
outputFileName?: string;
|
|
125
|
+
/**
|
|
126
|
+
* Use file hashes in the output filenames. Recommended for production web applications.
|
|
127
|
+
*/
|
|
57
128
|
outputHashing?: any;
|
|
129
|
+
/**
|
|
130
|
+
* Override `output.path` in webpack configuration. This setting is not recommended and exists for backwards compatibility.
|
|
131
|
+
*/
|
|
132
|
+
outputPath?: string;
|
|
133
|
+
/**
|
|
134
|
+
* Override `watchOptions.poll` in webpack configuration. This setting is not recommended and exists for backwards compatibility.
|
|
135
|
+
*/
|
|
58
136
|
poll?: number;
|
|
137
|
+
/**
|
|
138
|
+
* The polyfill file to use. Useful for supporting legacy browsers. e.g. `src/polyfills.ts`
|
|
139
|
+
*/
|
|
59
140
|
polyfills?: string;
|
|
141
|
+
/**
|
|
142
|
+
* Manually set the PostCSS configuration file. By default, PostCSS will look for `postcss.config.js` in the directory.
|
|
143
|
+
*/
|
|
60
144
|
postcssConfig?: string;
|
|
145
|
+
/**
|
|
146
|
+
* Display build progress in the terminal.
|
|
147
|
+
*/
|
|
61
148
|
progress?: boolean;
|
|
149
|
+
/**
|
|
150
|
+
* Add an additional chunk for the Webpack runtime. Defaults to `true` when `target === 'web'`.
|
|
151
|
+
*/
|
|
62
152
|
runtimeChunk?: boolean;
|
|
153
|
+
/**
|
|
154
|
+
* External scripts that will be included before the main application entry.
|
|
155
|
+
*/
|
|
63
156
|
scripts?: Array<ExtraEntryPointClass | string>;
|
|
157
|
+
/**
|
|
158
|
+
* Skip type checking. Default is `false`.
|
|
159
|
+
*/
|
|
64
160
|
skipTypeChecking?: boolean;
|
|
161
|
+
/**
|
|
162
|
+
* Generate source maps.
|
|
163
|
+
*/
|
|
65
164
|
sourceMap?: boolean | 'hidden';
|
|
165
|
+
/**
|
|
166
|
+
* When `true`, `process.env.NODE_ENV` will be excluded from the bundle. Useful for building a web application to run in a Node environment.
|
|
167
|
+
*/
|
|
66
168
|
ssr?: boolean;
|
|
169
|
+
/**
|
|
170
|
+
* Generate a `stats.json` file which can be analyzed using tools such as `webpack-bundle-analyzer`.
|
|
171
|
+
*/
|
|
67
172
|
statsJson?: boolean;
|
|
173
|
+
/**
|
|
174
|
+
* Options for the style preprocessor. e.g. `{ "includePaths": [] }` for SASS.
|
|
175
|
+
*/
|
|
68
176
|
stylePreprocessorOptions?: any;
|
|
177
|
+
/**
|
|
178
|
+
* External stylesheets that will be included with the application.
|
|
179
|
+
*/
|
|
69
180
|
styles?: Array<ExtraEntryPointClass | string>;
|
|
181
|
+
/**
|
|
182
|
+
* Enables the use of subresource integrity validation.
|
|
183
|
+
*/
|
|
70
184
|
subresourceIntegrity?: boolean;
|
|
185
|
+
/**
|
|
186
|
+
* Override the `target` option in webpack configuration. This setting is not recommended and exists for backwards compatibility.
|
|
187
|
+
*/
|
|
71
188
|
target?: string | string[];
|
|
189
|
+
/**
|
|
190
|
+
* List of TypeScript Compiler Transformers Plugins.
|
|
191
|
+
*/
|
|
72
192
|
transformers?: TransformerEntry[];
|
|
193
|
+
/**
|
|
194
|
+
* Generate a separate vendor chunk for 3rd party packages.
|
|
195
|
+
*/
|
|
73
196
|
vendorChunk?: boolean;
|
|
197
|
+
/**
|
|
198
|
+
* Log additional information for debugging purposes.
|
|
199
|
+
*/
|
|
74
200
|
verbose?: boolean;
|
|
201
|
+
/**
|
|
202
|
+
* Watch for file changes.
|
|
203
|
+
*/
|
|
75
204
|
watch?: boolean;
|
|
76
205
|
}
|
|
77
206
|
export interface NormalizedNxWebpackPluginOptions extends NxWebpackPluginOptions {
|
|
@@ -12,7 +12,6 @@ import { NxWebpackPluginOptions } from './nx-webpack-plugin-options';
|
|
|
12
12
|
*/
|
|
13
13
|
export declare class NxWebpackPlugin {
|
|
14
14
|
private readonly options;
|
|
15
|
-
constructor(options
|
|
15
|
+
constructor(options?: NxWebpackPluginOptions);
|
|
16
16
|
apply(compiler: Compiler): void;
|
|
17
|
-
private readExecutorOptions;
|
|
18
17
|
}
|
|
@@ -16,21 +16,19 @@ const apply_web_config_1 = require("./lib/apply-web-config");
|
|
|
16
16
|
* Web-only features, such as stylesheets and images, are only supported when `target` is 'web' or 'webworker'.
|
|
17
17
|
*/
|
|
18
18
|
class NxWebpackPlugin {
|
|
19
|
-
constructor(options) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
19
|
+
constructor(options = {}) {
|
|
20
|
+
// If we're not in an Nx task, we're building inferred targets, so skip normalizing build options.
|
|
21
|
+
if (process.env['NX_TASK_TARGET_PROJECT']) {
|
|
22
|
+
this.options = (0, normalize_options_1.normalizeOptions)(options);
|
|
23
|
+
}
|
|
24
24
|
}
|
|
25
25
|
apply(compiler) {
|
|
26
|
-
|
|
26
|
+
// Defaults to 'web' if not specified to match Webpack's default.
|
|
27
|
+
const target = this.options.target ?? compiler.options.target ?? 'web';
|
|
27
28
|
this.options.outputPath ??= compiler.options.output?.path;
|
|
28
29
|
if (typeof target === 'string') {
|
|
29
30
|
this.options.target = target;
|
|
30
31
|
}
|
|
31
|
-
if (this.options.deleteOutputPath) {
|
|
32
|
-
(0, fs_1.deleteOutputDir)(this.options.root, this.options.outputPath);
|
|
33
|
-
}
|
|
34
32
|
(0, apply_base_config_1.applyBaseConfig)(this.options, compiler.options, {
|
|
35
33
|
useNormalizedEntry: true,
|
|
36
34
|
});
|
|
@@ -42,14 +40,8 @@ class NxWebpackPlugin {
|
|
|
42
40
|
useNormalizedEntry: true,
|
|
43
41
|
});
|
|
44
42
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
const fromExecutor = process.env['NX_WEBPACK_EXECUTOR_RAW_OPTIONS'] ?? '{}';
|
|
48
|
-
try {
|
|
49
|
-
return JSON.parse(fromExecutor);
|
|
50
|
-
}
|
|
51
|
-
catch {
|
|
52
|
-
return {};
|
|
43
|
+
if (this.options.deleteOutputPath) {
|
|
44
|
+
(0, fs_1.deleteOutputDir)(this.options.root, this.options.outputPath);
|
|
53
45
|
}
|
|
54
46
|
}
|
|
55
47
|
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { CreateDependencies, CreateNodes } from '@nx/devkit';
|
|
2
|
+
export interface WebpackPluginOptions {
|
|
3
|
+
buildTargetName?: string;
|
|
4
|
+
serveTargetName?: string;
|
|
5
|
+
staticServeTargetName?: string;
|
|
6
|
+
previewTargetName?: string;
|
|
7
|
+
}
|
|
8
|
+
export declare const createDependencies: CreateDependencies;
|
|
9
|
+
export declare const createNodes: CreateNodes<WebpackPluginOptions>;
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createNodes = exports.createDependencies = void 0;
|
|
4
|
+
const devkit_1 = require("@nx/devkit");
|
|
5
|
+
const path_1 = require("path");
|
|
6
|
+
const get_named_inputs_1 = require("@nx/devkit/src/utils/get-named-inputs");
|
|
7
|
+
const project_configuration_utils_1 = require("nx/src/project-graph/utils/project-configuration-utils");
|
|
8
|
+
const fs_1 = require("fs");
|
|
9
|
+
const read_webpack_options_1 = require("../utils/webpack/read-webpack-options");
|
|
10
|
+
const resolve_user_defined_webpack_config_1 = require("../utils/webpack/resolve-user-defined-webpack-config");
|
|
11
|
+
const js_1 = require("@nx/js");
|
|
12
|
+
const cache_directory_1 = require("nx/src/utils/cache-directory");
|
|
13
|
+
const calculate_hash_for_create_nodes_1 = require("@nx/devkit/src/utils/calculate-hash-for-create-nodes");
|
|
14
|
+
const cachePath = (0, path_1.join)(cache_directory_1.projectGraphCacheDirectory, 'webpack.hash');
|
|
15
|
+
const targetsCache = (0, fs_1.existsSync)(cachePath) ? readTargetsCache() : {};
|
|
16
|
+
const calculatedTargets = {};
|
|
17
|
+
function readTargetsCache() {
|
|
18
|
+
return (0, devkit_1.readJsonFile)(cachePath);
|
|
19
|
+
}
|
|
20
|
+
function writeTargetsToCache(targets) {
|
|
21
|
+
(0, devkit_1.writeJsonFile)(cachePath, targets);
|
|
22
|
+
}
|
|
23
|
+
const createDependencies = () => {
|
|
24
|
+
writeTargetsToCache(calculatedTargets);
|
|
25
|
+
return [];
|
|
26
|
+
};
|
|
27
|
+
exports.createDependencies = createDependencies;
|
|
28
|
+
exports.createNodes = [
|
|
29
|
+
'**/webpack.config.{js,ts,mjs,mts,cjs,cts}',
|
|
30
|
+
async (configFilePath, options, context) => {
|
|
31
|
+
options ??= {};
|
|
32
|
+
options.buildTargetName ??= 'build';
|
|
33
|
+
options.serveTargetName ??= 'serve';
|
|
34
|
+
options.staticServeTargetName ??= 'static-serve';
|
|
35
|
+
options.previewTargetName ??= 'preview';
|
|
36
|
+
const projectRoot = (0, path_1.dirname)(configFilePath);
|
|
37
|
+
// Do not create a project if package.json and project.json isn't there.
|
|
38
|
+
const siblingFiles = (0, fs_1.readdirSync)((0, path_1.join)(context.workspaceRoot, projectRoot));
|
|
39
|
+
if (!siblingFiles.includes('package.json') &&
|
|
40
|
+
!siblingFiles.includes('project.json')) {
|
|
41
|
+
return {};
|
|
42
|
+
}
|
|
43
|
+
const hash = (0, calculate_hash_for_create_nodes_1.calculateHashForCreateNodes)(projectRoot, options, context, [
|
|
44
|
+
(0, js_1.getLockFileName)((0, devkit_1.detectPackageManager)(context.workspaceRoot)),
|
|
45
|
+
]);
|
|
46
|
+
const targets = targetsCache[hash]
|
|
47
|
+
? targetsCache[hash]
|
|
48
|
+
: await createWebpackTargets(configFilePath, projectRoot, options, context);
|
|
49
|
+
return {
|
|
50
|
+
projects: {
|
|
51
|
+
[projectRoot]: {
|
|
52
|
+
projectType: 'application',
|
|
53
|
+
targets,
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
},
|
|
58
|
+
];
|
|
59
|
+
async function createWebpackTargets(configFilePath, projectRoot, options, context) {
|
|
60
|
+
const namedInputs = (0, get_named_inputs_1.getNamedInputs)(projectRoot, context);
|
|
61
|
+
const webpackConfig = (0, resolve_user_defined_webpack_config_1.resolveUserDefinedWebpackConfig)((0, path_1.join)(context.workspaceRoot, configFilePath), (0, js_1.getRootTsConfigPath)());
|
|
62
|
+
const webpackOptions = await (0, read_webpack_options_1.readWebpackOptions)(webpackConfig);
|
|
63
|
+
const outputPath = normalizeOutputPath(webpackOptions.output?.path) ??
|
|
64
|
+
'{workspaceRoot}/dist/{projectRoot}';
|
|
65
|
+
const targets = {};
|
|
66
|
+
const configBasename = (0, path_1.basename)(configFilePath);
|
|
67
|
+
targets[options.buildTargetName] = {
|
|
68
|
+
command: `webpack -c ${configBasename} --node-env=production`,
|
|
69
|
+
options: {
|
|
70
|
+
cwd: projectRoot,
|
|
71
|
+
},
|
|
72
|
+
};
|
|
73
|
+
const buildTargetDefaults = (0, project_configuration_utils_1.readTargetDefaultsForTarget)(options.buildTargetName, context.nxJsonConfiguration.targetDefaults);
|
|
74
|
+
if (buildTargetDefaults?.cache === undefined) {
|
|
75
|
+
targets[options.buildTargetName].cache = true;
|
|
76
|
+
}
|
|
77
|
+
if (buildTargetDefaults?.inputs === undefined) {
|
|
78
|
+
targets[options.buildTargetName].inputs =
|
|
79
|
+
'production' in namedInputs
|
|
80
|
+
? [
|
|
81
|
+
'default',
|
|
82
|
+
'^production',
|
|
83
|
+
{
|
|
84
|
+
externalDependencies: ['webpack-cli'],
|
|
85
|
+
},
|
|
86
|
+
]
|
|
87
|
+
: [
|
|
88
|
+
'default',
|
|
89
|
+
'^default',
|
|
90
|
+
{
|
|
91
|
+
externalDependencies: ['webpack-cli'],
|
|
92
|
+
},
|
|
93
|
+
];
|
|
94
|
+
}
|
|
95
|
+
if (buildTargetDefaults?.outputs === undefined) {
|
|
96
|
+
targets[options.buildTargetName].outputs = [outputPath];
|
|
97
|
+
}
|
|
98
|
+
targets[options.serveTargetName] = {
|
|
99
|
+
command: `webpack serve -c ${configBasename} --node-env=development`,
|
|
100
|
+
options: {
|
|
101
|
+
cwd: projectRoot,
|
|
102
|
+
},
|
|
103
|
+
};
|
|
104
|
+
targets[options.previewTargetName] = {
|
|
105
|
+
command: `webpack serve -c ${configBasename} --node-env=production`,
|
|
106
|
+
options: {
|
|
107
|
+
cwd: projectRoot,
|
|
108
|
+
},
|
|
109
|
+
};
|
|
110
|
+
targets[options.staticServeTargetName] = {
|
|
111
|
+
executor: '@nx/web:file-server',
|
|
112
|
+
options: {
|
|
113
|
+
buildTarget: `${projectRoot}:${options.buildTargetName}`,
|
|
114
|
+
},
|
|
115
|
+
};
|
|
116
|
+
return targets;
|
|
117
|
+
}
|
|
118
|
+
function normalizeOutputPath(outputPath) {
|
|
119
|
+
if (!outputPath)
|
|
120
|
+
return undefined;
|
|
121
|
+
if ((0, path_1.isAbsolute)(outputPath)) {
|
|
122
|
+
return `{workspaceRoot}/${(0, path_1.relative)(devkit_1.workspaceRoot, outputPath)}`;
|
|
123
|
+
}
|
|
124
|
+
else {
|
|
125
|
+
return outputPath;
|
|
126
|
+
}
|
|
127
|
+
}
|
package/src/utils/config.d.ts
CHANGED
|
@@ -1,17 +1,22 @@
|
|
|
1
1
|
import { ExecutorContext } from '@nx/devkit';
|
|
2
2
|
import { Configuration } from 'webpack';
|
|
3
3
|
import { NormalizedWebpackExecutorOptions } from '../executors/webpack/schema';
|
|
4
|
-
|
|
5
|
-
export declare function
|
|
4
|
+
export declare const nxWebpackComposablePlugin = "nxWebpackComposablePlugin";
|
|
5
|
+
export declare function isNxWebpackComposablePlugin(a: unknown): a is AsyncNxComposableWebpackPlugin;
|
|
6
6
|
export interface NxWebpackExecutionContext {
|
|
7
7
|
options: NormalizedWebpackExecutorOptions;
|
|
8
8
|
context: ExecutorContext;
|
|
9
|
+
configuration?: string;
|
|
9
10
|
}
|
|
10
|
-
export interface
|
|
11
|
+
export interface NxComposableWebpackPlugin {
|
|
11
12
|
(config: Configuration, ctx: NxWebpackExecutionContext): Configuration;
|
|
12
13
|
}
|
|
13
|
-
export interface
|
|
14
|
+
export interface AsyncNxComposableWebpackPlugin {
|
|
14
15
|
(config: Configuration, ctx: NxWebpackExecutionContext): Configuration | Promise<Configuration>;
|
|
15
16
|
}
|
|
16
|
-
export declare function composePlugins(...plugins: (
|
|
17
|
-
|
|
17
|
+
export declare function composePlugins(...plugins: (NxComposableWebpackPlugin | AsyncNxComposableWebpackPlugin | Promise<NxComposableWebpackPlugin | AsyncNxComposableWebpackPlugin>)[]): ((config: Configuration, ctx: NxWebpackExecutionContext) => Promise<Configuration>) & {
|
|
18
|
+
nxWebpackComposablePlugin: boolean;
|
|
19
|
+
};
|
|
20
|
+
export declare function composePluginsSync(...plugins: NxComposableWebpackPlugin[]): ((config: Configuration, ctx: NxWebpackExecutionContext) => Configuration) & {
|
|
21
|
+
nxWebpackComposablePlugin: boolean;
|
|
22
|
+
};
|
package/src/utils/config.js
CHANGED
|
@@ -1,31 +1,66 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.composePluginsSync = exports.composePlugins = exports.
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const config = {};
|
|
9
|
-
const configure = composePluginsSync((0, with_nx_1.withNx)(), (0, with_web_1.withWeb)());
|
|
10
|
-
return configure(config, { options, context });
|
|
3
|
+
exports.composePluginsSync = exports.composePlugins = exports.isNxWebpackComposablePlugin = exports.nxWebpackComposablePlugin = void 0;
|
|
4
|
+
const devkit_1 = require("@nx/devkit");
|
|
5
|
+
exports.nxWebpackComposablePlugin = 'nxWebpackComposablePlugin';
|
|
6
|
+
function isNxWebpackComposablePlugin(a) {
|
|
7
|
+
return a?.[exports.nxWebpackComposablePlugin] === true;
|
|
11
8
|
}
|
|
12
|
-
exports.
|
|
9
|
+
exports.isNxWebpackComposablePlugin = isNxWebpackComposablePlugin;
|
|
13
10
|
function composePlugins(...plugins) {
|
|
14
|
-
return async function combined(config, ctx) {
|
|
11
|
+
return Object.assign(async function combined(config, ctx) {
|
|
12
|
+
// Webpack may be calling us as a standard config function.
|
|
13
|
+
// Build up Nx context from environment variables.
|
|
14
|
+
// This is to enable `@nx/webpack/plugin` to work with existing projects.
|
|
15
|
+
if (ctx['env']) {
|
|
16
|
+
ensureNxWebpackExecutionContext(ctx);
|
|
17
|
+
// Build this from scratch since what webpack passes us is the env, not config,
|
|
18
|
+
// and `withNX()` creates a new config object anyway.
|
|
19
|
+
config = {};
|
|
20
|
+
}
|
|
15
21
|
for (const plugin of plugins) {
|
|
16
22
|
const fn = await plugin;
|
|
17
23
|
config = await fn(config, ctx);
|
|
18
24
|
}
|
|
19
25
|
return config;
|
|
20
|
-
}
|
|
26
|
+
}, {
|
|
27
|
+
[exports.nxWebpackComposablePlugin]: true,
|
|
28
|
+
});
|
|
21
29
|
}
|
|
22
30
|
exports.composePlugins = composePlugins;
|
|
23
31
|
function composePluginsSync(...plugins) {
|
|
24
|
-
return function combined(config, ctx) {
|
|
32
|
+
return Object.assign(function combined(config, ctx) {
|
|
25
33
|
for (const plugin of plugins) {
|
|
26
34
|
config = plugin(config, ctx);
|
|
27
35
|
}
|
|
28
36
|
return config;
|
|
29
|
-
}
|
|
37
|
+
}, {
|
|
38
|
+
[exports.nxWebpackComposablePlugin]: true,
|
|
39
|
+
});
|
|
30
40
|
}
|
|
31
41
|
exports.composePluginsSync = composePluginsSync;
|
|
42
|
+
function ensureNxWebpackExecutionContext(ctx) {
|
|
43
|
+
const projectName = process.env.NX_TASK_TARGET_PROJECT;
|
|
44
|
+
const targetName = process.env.NX_TASK_TARGET_TARGET;
|
|
45
|
+
const configurationName = process.env.NX_TASK_TARGET_CONFIGURATION;
|
|
46
|
+
const projectGraph = (0, devkit_1.readCachedProjectGraph)();
|
|
47
|
+
const projectNode = projectGraph.nodes[projectName];
|
|
48
|
+
ctx.options ??= {
|
|
49
|
+
root: devkit_1.workspaceRoot,
|
|
50
|
+
projectRoot: projectNode.data.root,
|
|
51
|
+
sourceRoot: projectNode.data.sourceRoot ?? projectNode.data.root,
|
|
52
|
+
// These aren't actually needed since NxWebpackPlugin and withNx both support them being undefined.
|
|
53
|
+
assets: undefined,
|
|
54
|
+
outputPath: undefined,
|
|
55
|
+
tsConfig: undefined,
|
|
56
|
+
outputFileName: undefined,
|
|
57
|
+
};
|
|
58
|
+
ctx.context ??= {
|
|
59
|
+
projectName,
|
|
60
|
+
targetName,
|
|
61
|
+
configurationName,
|
|
62
|
+
cwd: process.cwd(),
|
|
63
|
+
root: devkit_1.workspaceRoot,
|
|
64
|
+
isVerbose: process.env['NX_VERBOSE_LOGGING'] === 'true',
|
|
65
|
+
};
|
|
66
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.hasPlugin = void 0;
|
|
4
|
+
const devkit_1 = require("@nx/devkit");
|
|
5
|
+
function hasPlugin(tree) {
|
|
6
|
+
const nxJson = (0, devkit_1.readNxJson)(tree);
|
|
7
|
+
return !!nxJson.plugins?.some((p) => typeof p === 'string'
|
|
8
|
+
? p === '@nx/webpack/plugin'
|
|
9
|
+
: p.plugin === '@nx/webpack/plugin');
|
|
10
|
+
}
|
|
11
|
+
exports.hasPlugin = hasPlugin;
|
package/src/utils/versions.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export declare const nxVersion: any;
|
|
2
2
|
export declare const swcLoaderVersion = "0.1.15";
|
|
3
3
|
export declare const tsLibVersion = "^2.3.0";
|
|
4
|
+
export declare const webpackCliVersion = "^5.1.4";
|
|
4
5
|
export declare const reactRefreshWebpackPluginVersion = "^0.5.7";
|
|
5
6
|
export declare const svgrWebpackVersion = "^8.0.1";
|
|
6
7
|
export declare const reactRefreshVersion = "^0.10.0";
|
package/src/utils/versions.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.urlLoaderVersion = exports.reactRefreshVersion = exports.svgrWebpackVersion = exports.reactRefreshWebpackPluginVersion = exports.tsLibVersion = exports.swcLoaderVersion = exports.nxVersion = void 0;
|
|
3
|
+
exports.urlLoaderVersion = exports.reactRefreshVersion = exports.svgrWebpackVersion = exports.reactRefreshWebpackPluginVersion = exports.webpackCliVersion = exports.tsLibVersion = exports.swcLoaderVersion = exports.nxVersion = void 0;
|
|
4
4
|
exports.nxVersion = require('../../package.json').version;
|
|
5
5
|
exports.swcLoaderVersion = '0.1.15';
|
|
6
6
|
exports.tsLibVersion = '^2.3.0';
|
|
7
|
+
exports.webpackCliVersion = '^5.1.4';
|
|
7
8
|
// React apps
|
|
8
9
|
exports.reactRefreshWebpackPluginVersion = '^0.5.7';
|
|
9
10
|
exports.svgrWebpackVersion = '^8.0.1';
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Configuration } from 'webpack';
|
|
2
|
+
/**
|
|
3
|
+
* Reads the webpack options from a give webpack configuration. The configuration can be:
|
|
4
|
+
* 1. A standard config object
|
|
5
|
+
* 2. A standard function that returns a config object (webpack.js.org/configuration/configuration-types/#exporting-a-function)
|
|
6
|
+
* 3. A Nx-specific composable function that takes Nx context, webpack config, and returns the config object.
|
|
7
|
+
*
|
|
8
|
+
* @param webpackConfig
|
|
9
|
+
*/
|
|
10
|
+
export declare function readWebpackOptions(webpackConfig: unknown): Promise<Configuration>;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.readWebpackOptions = void 0;
|
|
4
|
+
const devkit_1 = require("@nx/devkit");
|
|
5
|
+
const config_1 = require("../config");
|
|
6
|
+
/**
|
|
7
|
+
* Reads the webpack options from a give webpack configuration. The configuration can be:
|
|
8
|
+
* 1. A standard config object
|
|
9
|
+
* 2. A standard function that returns a config object (webpack.js.org/configuration/configuration-types/#exporting-a-function)
|
|
10
|
+
* 3. A Nx-specific composable function that takes Nx context, webpack config, and returns the config object.
|
|
11
|
+
*
|
|
12
|
+
* @param webpackConfig
|
|
13
|
+
*/
|
|
14
|
+
async function readWebpackOptions(webpackConfig) {
|
|
15
|
+
let config;
|
|
16
|
+
if ((0, config_1.isNxWebpackComposablePlugin)(webpackConfig)) {
|
|
17
|
+
config = await webpackConfig({}, {
|
|
18
|
+
// These values are only used during build-time, so passing stubs here just to read out
|
|
19
|
+
// the returned config object.
|
|
20
|
+
options: {
|
|
21
|
+
root: devkit_1.workspaceRoot,
|
|
22
|
+
projectRoot: '',
|
|
23
|
+
sourceRoot: '',
|
|
24
|
+
outputFileName: undefined,
|
|
25
|
+
outputPath: undefined,
|
|
26
|
+
assets: undefined,
|
|
27
|
+
},
|
|
28
|
+
context: { root: devkit_1.workspaceRoot, cwd: undefined, isVerbose: false },
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
else if (typeof webpackConfig === 'function') {
|
|
32
|
+
config = await webpackConfig({
|
|
33
|
+
production: true, // we want the production build options
|
|
34
|
+
}, {});
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
config = webpackConfig;
|
|
38
|
+
}
|
|
39
|
+
return config;
|
|
40
|
+
}
|
|
41
|
+
exports.readWebpackOptions = readWebpackOptions;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function resolveUserDefinedWebpackConfig(path: string, tsConfig: string): any;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.resolveUserDefinedWebpackConfig = void 0;
|
|
4
4
|
const internal_1 = require("@nx/js/src/internal");
|
|
5
|
-
function
|
|
5
|
+
function resolveUserDefinedWebpackConfig(path, tsConfig) {
|
|
6
6
|
// Don't transpile non-TS files. This prevents workspaces libs from being registered via tsconfig-paths.
|
|
7
7
|
// There's an issue here with Nx workspace where loading plugins from source (via tsconfig-paths) can lead to errors.
|
|
8
8
|
if (!/\.(ts|mts|cts)$/.test(path)) {
|
|
@@ -25,9 +25,4 @@ function resolveCustomWebpackConfig(path, tsConfig) {
|
|
|
25
25
|
: maybeCustomWebpackConfig;
|
|
26
26
|
return customWebpackConfig;
|
|
27
27
|
}
|
|
28
|
-
exports.
|
|
29
|
-
function isRegistered() {
|
|
30
|
-
return (require.extensions['.ts'] != undefined ||
|
|
31
|
-
require.extensions['.tsx'] != undefined);
|
|
32
|
-
}
|
|
33
|
-
exports.isRegistered = isRegistered;
|
|
28
|
+
exports.resolveUserDefinedWebpackConfig = resolveUserDefinedWebpackConfig;
|
package/src/utils/with-nx.d.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
}
|
|
1
|
+
import { NxComposableWebpackPlugin } from './config';
|
|
2
|
+
import { NxWebpackPluginOptions } from '../plugins/nx-webpack-plugin/nx-webpack-plugin-options';
|
|
3
|
+
export type WithNxOptions = Partial<NxWebpackPluginOptions>;
|
|
5
4
|
/**
|
|
6
5
|
* @param {WithNxOptions} pluginOptions
|
|
7
6
|
* @returns {NxWebpackPlugin}
|
|
8
7
|
*/
|
|
9
|
-
export declare function withNx(pluginOptions?: WithNxOptions):
|
|
8
|
+
export declare function withNx(pluginOptions?: WithNxOptions): NxComposableWebpackPlugin;
|
package/src/utils/with-nx.js
CHANGED
|
@@ -2,18 +2,24 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.withNx = void 0;
|
|
4
4
|
const apply_base_config_1 = require("../plugins/nx-webpack-plugin/lib/apply-base-config");
|
|
5
|
+
const normalize_options_1 = require("../plugins/nx-webpack-plugin/lib/normalize-options");
|
|
5
6
|
const processed = new Set();
|
|
6
7
|
/**
|
|
7
8
|
* @param {WithNxOptions} pluginOptions
|
|
8
9
|
* @returns {NxWebpackPlugin}
|
|
9
10
|
*/
|
|
10
|
-
function withNx(pluginOptions) {
|
|
11
|
+
function withNx(pluginOptions = {}) {
|
|
11
12
|
return function configure(config, { options, context }) {
|
|
12
13
|
if (processed.has(config))
|
|
13
14
|
return config;
|
|
14
15
|
(0, apply_base_config_1.applyBaseConfig)({
|
|
15
16
|
...options,
|
|
16
17
|
...pluginOptions,
|
|
18
|
+
assets: options.assets
|
|
19
|
+
? options.assets
|
|
20
|
+
: pluginOptions.assets
|
|
21
|
+
? (0, normalize_options_1.normalizeAssets)(pluginOptions.assets, options.root, options.sourceRoot)
|
|
22
|
+
: [],
|
|
17
23
|
root: context.root,
|
|
18
24
|
projectName: context.projectName,
|
|
19
25
|
targetName: context.targetName,
|
package/src/utils/with-web.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { NxComposableWebpackPlugin } from './config';
|
|
2
2
|
import { ExtraEntryPointClass, NormalizedWebpackExecutorOptions } from '../executors/webpack/schema';
|
|
3
3
|
export interface WithWebOptions {
|
|
4
4
|
baseHref?: string;
|
|
@@ -19,4 +19,4 @@ export type MergedOptions = Omit<NormalizedWebpackExecutorOptions, keyof WithWeb
|
|
|
19
19
|
* @param {WithWebOptions} pluginOptions
|
|
20
20
|
* @returns {NxWebpackPlugin}
|
|
21
21
|
*/
|
|
22
|
-
export declare function withWeb(pluginOptions?: WithWebOptions):
|
|
22
|
+
export declare function withWeb(pluginOptions?: WithWebOptions): NxComposableWebpackPlugin;
|
|
@@ -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;
|