@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.
- package/LICENSE +22 -0
- package/README.md +68 -0
- package/executors.json +19 -0
- package/generators.json +20 -0
- package/index.d.ts +18 -0
- package/index.js +24 -0
- package/migrations.json +60 -0
- package/package.json +74 -0
- package/plugin.d.ts +1 -0
- package/plugin.js +5 -0
- package/src/executors/dev-server/dev-server.impl.d.ts +7 -0
- package/src/executors/dev-server/dev-server.impl.js +79 -0
- package/src/executors/dev-server/lib/get-dev-server-config.d.ts +4 -0
- package/src/executors/dev-server/lib/get-dev-server-config.js +79 -0
- package/src/executors/dev-server/lib/serve-path.d.ts +3 -0
- package/src/executors/dev-server/lib/serve-path.js +45 -0
- package/src/executors/dev-server/schema.d.ts +17 -0
- package/src/executors/dev-server/schema.json +76 -0
- package/src/executors/ssr-dev-server/lib/wait-until-server-is-listening.d.ts +1 -0
- package/src/executors/ssr-dev-server/lib/wait-until-server-is-listening.js +39 -0
- package/src/executors/ssr-dev-server/schema.d.ts +11 -0
- package/src/executors/ssr-dev-server/schema.json +37 -0
- package/src/executors/ssr-dev-server/ssr-dev-server.impl.d.ts +8 -0
- package/src/executors/ssr-dev-server/ssr-dev-server.impl.js +39 -0
- package/src/executors/webpack/lib/normalize-options.d.ts +3 -0
- package/src/executors/webpack/lib/normalize-options.js +40 -0
- package/src/executors/webpack/lib/run-webpack.d.ts +3 -0
- package/src/executors/webpack/lib/run-webpack.js +36 -0
- package/src/executors/webpack/schema.d.ts +96 -0
- package/src/executors/webpack/schema.json +394 -0
- package/src/executors/webpack/webpack.impl.d.ts +13 -0
- package/src/executors/webpack/webpack.impl.js +125 -0
- package/src/generators/configuration/configuration.d.ts +5 -0
- package/src/generators/configuration/configuration.js +194 -0
- package/src/generators/configuration/schema.d.ts +14 -0
- package/src/generators/configuration/schema.json +77 -0
- package/src/generators/init/init.d.ts +5 -0
- package/src/generators/init/init.js +60 -0
- package/src/generators/init/schema.d.ts +7 -0
- package/src/generators/init/schema.json +33 -0
- package/src/migrations/update-15-0-0/add-babel-inputs.d.ts +2 -0
- package/src/migrations/update-15-0-0/add-babel-inputs.js +9 -0
- package/src/migrations/update-15-4-5/remove-es2015-polyfills-option.d.ts +2 -0
- package/src/migrations/update-15-4-5/remove-es2015-polyfills-option.js +20 -0
- package/src/migrations/update-15-6-3/webpack-config-setup.d.ts +2 -0
- package/src/migrations/update-15-6-3/webpack-config-setup.js +100 -0
- package/src/migrations/update-15-7-2/add-babelUpwardRootMode-flag.d.ts +2 -0
- package/src/migrations/update-15-7-2/add-babelUpwardRootMode-flag.js +17 -0
- package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.d.ts +2 -0
- package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.js +9 -0
- package/src/migrations/update-17-2-1/webpack-config-setup.d.ts +2 -0
- package/src/migrations/update-17-2-1/webpack-config-setup.js +31 -0
- package/src/plugins/generate-package-json-plugin.d.ts +14 -0
- package/src/plugins/generate-package-json-plugin.js +44 -0
- package/src/plugins/nx-typescript-webpack-plugin/nx-tsconfig-paths-webpack-plugin.d.ts +8 -0
- package/src/plugins/nx-typescript-webpack-plugin/nx-tsconfig-paths-webpack-plugin.js +31 -0
- package/src/plugins/nx-webpack-plugin/lib/apply-base-config.d.ts +5 -0
- package/src/plugins/nx-webpack-plugin/lib/apply-base-config.js +318 -0
- package/src/plugins/nx-webpack-plugin/lib/apply-web-config.d.ts +5 -0
- package/src/plugins/nx-webpack-plugin/lib/apply-web-config.js +372 -0
- package/src/plugins/nx-webpack-plugin/lib/compiler-loaders.d.ts +53 -0
- package/src/plugins/nx-webpack-plugin/lib/compiler-loaders.js +78 -0
- package/src/plugins/nx-webpack-plugin/lib/get-terser-ecma-version.d.ts +1 -0
- package/src/plugins/nx-webpack-plugin/lib/get-terser-ecma-version.js +35 -0
- package/src/plugins/nx-webpack-plugin/lib/instantiate-script-plugins.d.ts +3 -0
- package/src/plugins/nx-webpack-plugin/lib/instantiate-script-plugins.js +42 -0
- package/src/plugins/nx-webpack-plugin/lib/normalize-options.d.ts +4 -0
- package/src/plugins/nx-webpack-plugin/lib/normalize-options.js +143 -0
- package/src/plugins/nx-webpack-plugin/lib/stylesheet-loaders.d.ts +73 -0
- package/src/plugins/nx-webpack-plugin/lib/stylesheet-loaders.js +117 -0
- package/src/plugins/nx-webpack-plugin/nx-webpack-plugin-options.d.ts +216 -0
- package/src/plugins/nx-webpack-plugin/nx-webpack-plugin-options.js +2 -0
- package/src/plugins/nx-webpack-plugin/nx-webpack-plugin.d.ts +17 -0
- package/src/plugins/nx-webpack-plugin/nx-webpack-plugin.js +48 -0
- package/src/plugins/plugin.d.ts +9 -0
- package/src/plugins/plugin.js +131 -0
- package/src/plugins/stats-json-plugin.d.ts +4 -0
- package/src/plugins/stats-json-plugin.js +13 -0
- package/src/plugins/webpack-nx-build-coordination-plugin.d.ts +11 -0
- package/src/plugins/webpack-nx-build-coordination-plugin.js +85 -0
- package/src/plugins/write-index-html-plugin.d.ts +22 -0
- package/src/plugins/write-index-html-plugin.js +249 -0
- package/src/utils/config.d.ts +22 -0
- package/src/utils/config.js +66 -0
- package/src/utils/create-copy-plugin.d.ts +3 -0
- package/src/utils/create-copy-plugin.js +26 -0
- package/src/utils/ensure-dependencies.d.ts +6 -0
- package/src/utils/ensure-dependencies.js +28 -0
- package/src/utils/fs.d.ts +6 -0
- package/src/utils/fs.js +58 -0
- package/src/utils/get-client-environment.d.ts +5 -0
- package/src/utils/get-client-environment.js +29 -0
- package/src/utils/get-css-module-local-ident.d.ts +1 -0
- package/src/utils/get-css-module-local-ident.js +18 -0
- package/src/utils/has-plugin.d.ts +2 -0
- package/src/utils/has-plugin.js +11 -0
- package/src/utils/hash-format.d.ts +7 -0
- package/src/utils/hash-format.js +23 -0
- package/src/utils/models.d.ts +23 -0
- package/src/utils/models.js +2 -0
- package/src/utils/module-federation/dependencies.d.ts +6 -0
- package/src/utils/module-federation/dependencies.js +57 -0
- package/src/utils/module-federation/get-remotes-for-host.d.ts +14 -0
- package/src/utils/module-federation/get-remotes-for-host.js +88 -0
- package/src/utils/module-federation/index.d.ts +6 -0
- package/src/utils/module-federation/index.js +9 -0
- package/src/utils/module-federation/models/index.d.ts +39 -0
- package/src/utils/module-federation/models/index.js +2 -0
- package/src/utils/module-federation/package-json.d.ts +8 -0
- package/src/utils/module-federation/package-json.js +13 -0
- package/src/utils/module-federation/public-api.d.ts +6 -0
- package/src/utils/module-federation/public-api.js +16 -0
- package/src/utils/module-federation/remotes.d.ts +19 -0
- package/src/utils/module-federation/remotes.js +80 -0
- package/src/utils/module-federation/secondary-entry-points.d.ts +12 -0
- package/src/utils/module-federation/secondary-entry-points.js +108 -0
- package/src/utils/module-federation/share.d.ts +48 -0
- package/src/utils/module-federation/share.js +215 -0
- package/src/utils/module-federation/typescript.d.ts +4 -0
- package/src/utils/module-federation/typescript.js +54 -0
- package/src/utils/run-webpack.d.ts +5 -0
- package/src/utils/run-webpack.js +31 -0
- package/src/utils/versions.d.ts +8 -0
- package/src/utils/versions.js +12 -0
- package/src/utils/web-babel-loader.d.ts +0 -0
- package/src/utils/web-babel-loader.js +17 -0
- package/src/utils/webpack/deprecated-stylus-loader.d.ts +1 -0
- package/src/utils/webpack/deprecated-stylus-loader.js +11 -0
- package/src/utils/webpack/interpolate-env-variables-to-index.d.ts +1 -0
- package/src/utils/webpack/interpolate-env-variables-to-index.js +30 -0
- package/src/utils/webpack/normalize-entry.d.ts +2 -0
- package/src/utils/webpack/normalize-entry.js +28 -0
- package/src/utils/webpack/package-chunk-sort.d.ts +5 -0
- package/src/utils/webpack/package-chunk-sort.js +29 -0
- package/src/utils/webpack/plugins/postcss-cli-resources.d.ts +13 -0
- package/src/utils/webpack/plugins/postcss-cli-resources.js +165 -0
- package/src/utils/webpack/plugins/scripts-webpack-plugin.d.ts +17 -0
- package/src/utils/webpack/plugins/scripts-webpack-plugin.js +119 -0
- package/src/utils/webpack/read-webpack-options.d.ts +10 -0
- package/src/utils/webpack/read-webpack-options.js +41 -0
- package/src/utils/webpack/resolve-user-defined-webpack-config.d.ts +3 -0
- package/src/utils/webpack/resolve-user-defined-webpack-config.js +39 -0
- package/src/utils/with-nx.d.ts +8 -0
- package/src/utils/with-nx.js +34 -0
- package/src/utils/with-web.d.ts +22 -0
- package/src/utils/with-web.js +26 -0
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.configurationGeneratorInternal = exports.configurationGenerator = void 0;
|
|
4
|
+
const devkit_1 = require("@nx/devkit");
|
|
5
|
+
const init_1 = require("../init/init");
|
|
6
|
+
const has_plugin_1 = require("../../utils/has-plugin");
|
|
7
|
+
const add_build_target_defaults_1 = require("@nx/devkit/src/generators/add-build-target-defaults");
|
|
8
|
+
const ensure_dependencies_1 = require("../../utils/ensure-dependencies");
|
|
9
|
+
function configurationGenerator(tree, options) {
|
|
10
|
+
return configurationGeneratorInternal(tree, { addPlugin: false, ...options });
|
|
11
|
+
}
|
|
12
|
+
exports.configurationGenerator = configurationGenerator;
|
|
13
|
+
async function configurationGeneratorInternal(tree, options) {
|
|
14
|
+
const tasks = [];
|
|
15
|
+
const nxJson = (0, devkit_1.readNxJson)(tree);
|
|
16
|
+
const addPluginDefault = process.env.NX_ADD_PLUGINS !== 'false' &&
|
|
17
|
+
nxJson.useInferencePlugins !== false;
|
|
18
|
+
options.addPlugin ??= addPluginDefault;
|
|
19
|
+
const initTask = await (0, init_1.webpackInitGenerator)(tree, {
|
|
20
|
+
...options,
|
|
21
|
+
skipFormat: true,
|
|
22
|
+
});
|
|
23
|
+
tasks.push(initTask);
|
|
24
|
+
const depsTask = (0, ensure_dependencies_1.ensureDependencies)(tree, {
|
|
25
|
+
compiler: options.compiler === 'babel' ? undefined : options.compiler,
|
|
26
|
+
});
|
|
27
|
+
tasks.push(depsTask);
|
|
28
|
+
checkForTargetConflicts(tree, options);
|
|
29
|
+
if (!(0, has_plugin_1.hasPlugin)(tree)) {
|
|
30
|
+
addBuildTarget(tree, options);
|
|
31
|
+
if (options.devServer) {
|
|
32
|
+
addServeTarget(tree, options);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
createWebpackConfig(tree, options);
|
|
36
|
+
if (!options.skipFormat) {
|
|
37
|
+
await (0, devkit_1.formatFiles)(tree);
|
|
38
|
+
}
|
|
39
|
+
return (0, devkit_1.runTasksInSerial)(...tasks);
|
|
40
|
+
}
|
|
41
|
+
exports.configurationGeneratorInternal = configurationGeneratorInternal;
|
|
42
|
+
function checkForTargetConflicts(tree, options) {
|
|
43
|
+
if (options.skipValidation)
|
|
44
|
+
return;
|
|
45
|
+
const project = (0, devkit_1.readProjectConfiguration)(tree, options.project);
|
|
46
|
+
if (project.targets?.build) {
|
|
47
|
+
throw new Error(`Project "${project.name}" already has a build target. Pass --skipValidation to ignore this error.`);
|
|
48
|
+
}
|
|
49
|
+
if (options.devServer && project.targets?.serve) {
|
|
50
|
+
throw new Error(`Project "${project.name}" already has a serve target. Pass --skipValidation to ignore this error.`);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
function createWebpackConfig(tree, options) {
|
|
54
|
+
const project = (0, devkit_1.readProjectConfiguration)(tree, options.project);
|
|
55
|
+
const buildOptions = {
|
|
56
|
+
target: options.target,
|
|
57
|
+
outputPath: (0, devkit_1.joinPathFragments)('dist', project.root),
|
|
58
|
+
compiler: options.compiler ?? 'swc',
|
|
59
|
+
main: options.main ?? (0, devkit_1.joinPathFragments)(project.root, 'src/main.ts'),
|
|
60
|
+
tsConfig: options.tsConfig ?? (0, devkit_1.joinPathFragments)(project.root, 'tsconfig.app.json'),
|
|
61
|
+
webpackConfig: (0, devkit_1.joinPathFragments)(project.root, 'webpack.config.js'),
|
|
62
|
+
};
|
|
63
|
+
if (options.target === 'web') {
|
|
64
|
+
tree.write((0, devkit_1.joinPathFragments)(project.root, 'webpack.config.js'), (0, has_plugin_1.hasPlugin)(tree)
|
|
65
|
+
? `
|
|
66
|
+
const { NxWebpackPlugin } = require('@nx/webpack');
|
|
67
|
+
const { join } = require('path');
|
|
68
|
+
|
|
69
|
+
module.exports = {
|
|
70
|
+
output: {
|
|
71
|
+
path: join(__dirname, '${(0, devkit_1.offsetFromRoot)(project.root)}${buildOptions.outputPath}'),
|
|
72
|
+
},
|
|
73
|
+
plugins: [
|
|
74
|
+
new NxWebpackPlugin({
|
|
75
|
+
target: '${buildOptions.target}',
|
|
76
|
+
tsConfig: '${buildOptions.tsConfig}',
|
|
77
|
+
compiler: '${buildOptions.compiler}',
|
|
78
|
+
main: '${buildOptions.main}',
|
|
79
|
+
outputHashing: '${buildOptions.target !== 'web' ? 'none' : 'all'}',
|
|
80
|
+
})
|
|
81
|
+
],
|
|
82
|
+
}
|
|
83
|
+
`
|
|
84
|
+
: `
|
|
85
|
+
const { composePlugins, withNx, withWeb } = require('@nx/webpack');
|
|
86
|
+
|
|
87
|
+
// Nx plugins for webpack.
|
|
88
|
+
module.exports = composePlugins(withNx(), withWeb(), (config) => {
|
|
89
|
+
// Update the webpack config as needed here.
|
|
90
|
+
// e.g. \`config.plugins.push(new MyPlugin())\`
|
|
91
|
+
return config;
|
|
92
|
+
});
|
|
93
|
+
`);
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
tree.write((0, devkit_1.joinPathFragments)(project.root, 'webpack.config.js'), (0, has_plugin_1.hasPlugin)(tree)
|
|
97
|
+
? `
|
|
98
|
+
const { NxWebpackPlugin } = require('@nx/webpack');
|
|
99
|
+
const { join } = require('path');
|
|
100
|
+
|
|
101
|
+
module.exports = {
|
|
102
|
+
output: {
|
|
103
|
+
path: join(__dirname, '${(0, devkit_1.offsetFromRoot)(project.root)}${buildOptions.outputPath}'),
|
|
104
|
+
},
|
|
105
|
+
plugins: [
|
|
106
|
+
new NxWebpackPlugin({
|
|
107
|
+
target: '${buildOptions.target}',
|
|
108
|
+
tsConfig: '${buildOptions.tsConfig}',
|
|
109
|
+
compiler: '${buildOptions.compiler}',
|
|
110
|
+
main: '${buildOptions.main}',
|
|
111
|
+
outputHashing: '${buildOptions.target !== 'web' ? 'none' : 'all'}',
|
|
112
|
+
})
|
|
113
|
+
],
|
|
114
|
+
}
|
|
115
|
+
`
|
|
116
|
+
: `
|
|
117
|
+
const { composePlugins, withNx } = require('@nx/webpack');
|
|
118
|
+
|
|
119
|
+
// Nx plugins for webpack.
|
|
120
|
+
module.exports = composePlugins(withNx(), (config) => {
|
|
121
|
+
// Update the webpack config as needed here.
|
|
122
|
+
// e.g. \`config.plugins.push(new MyPlugin())\`
|
|
123
|
+
return config;
|
|
124
|
+
});
|
|
125
|
+
`);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
function addBuildTarget(tree, options) {
|
|
129
|
+
(0, add_build_target_defaults_1.addBuildTargetDefaults)(tree, '@nx/webpack:webpack');
|
|
130
|
+
const project = (0, devkit_1.readProjectConfiguration)(tree, options.project);
|
|
131
|
+
const buildOptions = {
|
|
132
|
+
target: options.target,
|
|
133
|
+
outputPath: (0, devkit_1.joinPathFragments)('dist', project.root),
|
|
134
|
+
compiler: options.compiler ?? 'swc',
|
|
135
|
+
main: options.main ?? (0, devkit_1.joinPathFragments)(project.root, 'src/main.ts'),
|
|
136
|
+
tsConfig: options.tsConfig ?? (0, devkit_1.joinPathFragments)(project.root, 'tsconfig.app.json'),
|
|
137
|
+
webpackConfig: (0, devkit_1.joinPathFragments)(project.root, 'webpack.config.js'),
|
|
138
|
+
};
|
|
139
|
+
if (options.webpackConfig) {
|
|
140
|
+
buildOptions.webpackConfig = options.webpackConfig;
|
|
141
|
+
}
|
|
142
|
+
if (options.babelConfig) {
|
|
143
|
+
buildOptions.babelConfig = options.babelConfig;
|
|
144
|
+
}
|
|
145
|
+
else if (options.compiler === 'babel') {
|
|
146
|
+
// If no babel config file is provided then write a default one, otherwise build will fail.
|
|
147
|
+
(0, devkit_1.writeJson)(tree, (0, devkit_1.joinPathFragments)(project.root, '.babelrc'), {
|
|
148
|
+
presets: ['@nx/js/babel'],
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
(0, devkit_1.updateProjectConfiguration)(tree, options.project, {
|
|
152
|
+
...project,
|
|
153
|
+
targets: {
|
|
154
|
+
...project.targets,
|
|
155
|
+
build: {
|
|
156
|
+
executor: '@nx/webpack:webpack',
|
|
157
|
+
outputs: ['{options.outputPath}'],
|
|
158
|
+
defaultConfiguration: 'production',
|
|
159
|
+
options: buildOptions,
|
|
160
|
+
configurations: {
|
|
161
|
+
production: {
|
|
162
|
+
optimization: true,
|
|
163
|
+
outputHashing: options.target === 'web' ? 'all' : 'none',
|
|
164
|
+
sourceMap: false,
|
|
165
|
+
namedChunks: false,
|
|
166
|
+
extractLicenses: true,
|
|
167
|
+
vendorChunk: false,
|
|
168
|
+
},
|
|
169
|
+
},
|
|
170
|
+
},
|
|
171
|
+
},
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
function addServeTarget(tree, options) {
|
|
175
|
+
const project = (0, devkit_1.readProjectConfiguration)(tree, options.project);
|
|
176
|
+
(0, devkit_1.updateProjectConfiguration)(tree, options.project, {
|
|
177
|
+
...project,
|
|
178
|
+
targets: {
|
|
179
|
+
...project.targets,
|
|
180
|
+
serve: {
|
|
181
|
+
executor: '@nx/webpack:dev-server',
|
|
182
|
+
options: {
|
|
183
|
+
buildTarget: `${options.project}:build`,
|
|
184
|
+
},
|
|
185
|
+
configurations: {
|
|
186
|
+
production: {
|
|
187
|
+
buildTarget: `${options.project}:build:production`,
|
|
188
|
+
},
|
|
189
|
+
},
|
|
190
|
+
},
|
|
191
|
+
},
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
exports.default = configurationGenerator;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export interface ConfigurationGeneratorSchema {
|
|
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' | 'webworker';
|
|
11
|
+
webpackConfig?: string;
|
|
12
|
+
babelConfig?: string;
|
|
13
|
+
addPlugin?: boolean;
|
|
14
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/schema",
|
|
3
|
+
"$id": "NxWebpackProject",
|
|
4
|
+
"cli": "nx",
|
|
5
|
+
"title": "Add Webpack Configuration to a project",
|
|
6
|
+
"description": "Add Webpack Configuration to a project.",
|
|
7
|
+
"type": "object",
|
|
8
|
+
"properties": {
|
|
9
|
+
"project": {
|
|
10
|
+
"type": "string",
|
|
11
|
+
"description": "The name of the project.",
|
|
12
|
+
"$default": {
|
|
13
|
+
"$source": "argv",
|
|
14
|
+
"index": 0
|
|
15
|
+
},
|
|
16
|
+
"x-dropdown": "project",
|
|
17
|
+
"x-prompt": "What is the name of the project to set up a webpack for?",
|
|
18
|
+
"x-priority": "important"
|
|
19
|
+
},
|
|
20
|
+
"compiler": {
|
|
21
|
+
"type": "string",
|
|
22
|
+
"enum": ["babel", "swc", "tsc"],
|
|
23
|
+
"description": "The compiler to use to build source.",
|
|
24
|
+
"default": "swc"
|
|
25
|
+
},
|
|
26
|
+
"main": {
|
|
27
|
+
"type": "string",
|
|
28
|
+
"description": "Path relative to the workspace root for the main entry file. Defaults to '<projectRoot>/src/main.ts'.",
|
|
29
|
+
"x-priority": "important"
|
|
30
|
+
},
|
|
31
|
+
"tsConfig": {
|
|
32
|
+
"type": "string",
|
|
33
|
+
"description": "Path relative to the workspace root for the tsconfig file to build with. Defaults to '<projectRoot>/tsconfig.app.json'.",
|
|
34
|
+
"x-priority": "important"
|
|
35
|
+
},
|
|
36
|
+
"target": {
|
|
37
|
+
"type": "string",
|
|
38
|
+
"description": "Target platform for the build, same as the Webpack config option.",
|
|
39
|
+
"enum": ["node", "web", "webworker"],
|
|
40
|
+
"default": "web"
|
|
41
|
+
},
|
|
42
|
+
"skipFormat": {
|
|
43
|
+
"description": "Skip formatting files.",
|
|
44
|
+
"type": "boolean",
|
|
45
|
+
"default": false,
|
|
46
|
+
"x-priority": "internal"
|
|
47
|
+
},
|
|
48
|
+
"skipPackageJson": {
|
|
49
|
+
"type": "boolean",
|
|
50
|
+
"default": false,
|
|
51
|
+
"description": "Do not add dependencies to `package.json`.",
|
|
52
|
+
"x-priority": "internal"
|
|
53
|
+
},
|
|
54
|
+
"skipValidation": {
|
|
55
|
+
"type": "boolean",
|
|
56
|
+
"default": false,
|
|
57
|
+
"description": "Do not perform any validation on existing project.",
|
|
58
|
+
"x-priority": "internal"
|
|
59
|
+
},
|
|
60
|
+
"devServer": {
|
|
61
|
+
"type": "boolean",
|
|
62
|
+
"description": "Add a serve target to run a local webpack dev-server",
|
|
63
|
+
"default": false
|
|
64
|
+
},
|
|
65
|
+
"webpackConfig": {
|
|
66
|
+
"type": "string",
|
|
67
|
+
"description": "Path relative to workspace root to a custom webpack file that takes a config object and returns an updated config.",
|
|
68
|
+
"x-priority": "internal"
|
|
69
|
+
},
|
|
70
|
+
"babelConfig": {
|
|
71
|
+
"type": "string",
|
|
72
|
+
"description": "Optionally specify a path relative to workspace root to the babel configuration file of your project.",
|
|
73
|
+
"x-completion-type": "file"
|
|
74
|
+
}
|
|
75
|
+
},
|
|
76
|
+
"required": []
|
|
77
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { GeneratorCallback, Tree } from '@nx/devkit';
|
|
2
|
+
import { Schema } from './schema';
|
|
3
|
+
export declare function webpackInitGenerator(tree: Tree, schema: Schema): Promise<GeneratorCallback>;
|
|
4
|
+
export declare function webpackInitGeneratorInternal(tree: Tree, schema: Schema): Promise<GeneratorCallback>;
|
|
5
|
+
export default webpackInitGenerator;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.webpackInitGeneratorInternal = exports.webpackInitGenerator = void 0;
|
|
4
|
+
const devkit_1 = require("@nx/devkit");
|
|
5
|
+
const update_package_scripts_1 = require("@nx/devkit/src/utils/update-package-scripts");
|
|
6
|
+
const plugin_1 = require("../../plugins/plugin");
|
|
7
|
+
const versions_1 = require("../../utils/versions");
|
|
8
|
+
function webpackInitGenerator(tree, schema) {
|
|
9
|
+
return webpackInitGeneratorInternal(tree, { addPlugin: false, ...schema });
|
|
10
|
+
}
|
|
11
|
+
exports.webpackInitGenerator = webpackInitGenerator;
|
|
12
|
+
async function webpackInitGeneratorInternal(tree, schema) {
|
|
13
|
+
const nxJson = (0, devkit_1.readNxJson)(tree);
|
|
14
|
+
const addPluginDefault = process.env.NX_ADD_PLUGINS !== 'false' &&
|
|
15
|
+
nxJson.useInferencePlugins !== false;
|
|
16
|
+
schema.addPlugin ??= addPluginDefault;
|
|
17
|
+
if (schema.addPlugin) {
|
|
18
|
+
addPlugin(tree);
|
|
19
|
+
}
|
|
20
|
+
let installTask = () => { };
|
|
21
|
+
if (!schema.skipPackageJson) {
|
|
22
|
+
const devDependencies = {
|
|
23
|
+
'@nx/webpack': versions_1.nxVersion,
|
|
24
|
+
'@nx/web': versions_1.nxVersion,
|
|
25
|
+
};
|
|
26
|
+
if (schema.addPlugin) {
|
|
27
|
+
devDependencies['webpack-cli'] = versions_1.webpackCliVersion;
|
|
28
|
+
}
|
|
29
|
+
installTask = (0, devkit_1.addDependenciesToPackageJson)(tree, {}, devDependencies, undefined, schema.keepExistingVersions);
|
|
30
|
+
}
|
|
31
|
+
if (schema.updatePackageScripts) {
|
|
32
|
+
await (0, update_package_scripts_1.updatePackageScripts)(tree, plugin_1.createNodes);
|
|
33
|
+
}
|
|
34
|
+
if (!schema.skipFormat) {
|
|
35
|
+
await (0, devkit_1.formatFiles)(tree);
|
|
36
|
+
}
|
|
37
|
+
return installTask;
|
|
38
|
+
}
|
|
39
|
+
exports.webpackInitGeneratorInternal = webpackInitGeneratorInternal;
|
|
40
|
+
function addPlugin(tree) {
|
|
41
|
+
const nxJson = (0, devkit_1.readNxJson)(tree);
|
|
42
|
+
nxJson.plugins ??= [];
|
|
43
|
+
for (const plugin of nxJson.plugins) {
|
|
44
|
+
if (typeof plugin === 'string'
|
|
45
|
+
? plugin === '@nx/webpack/plugin'
|
|
46
|
+
: plugin.plugin === '@nx/webpack/plugin') {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
nxJson.plugins.push({
|
|
51
|
+
plugin: '@nx/webpack/plugin',
|
|
52
|
+
options: {
|
|
53
|
+
buildTargetName: 'build',
|
|
54
|
+
serveTargetName: 'serve',
|
|
55
|
+
previewTargetName: 'preview',
|
|
56
|
+
},
|
|
57
|
+
});
|
|
58
|
+
(0, devkit_1.updateNxJson)(tree, nxJson);
|
|
59
|
+
}
|
|
60
|
+
exports.default = webpackInitGenerator;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://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
|
+
"skipFormat": {
|
|
10
|
+
"description": "Skip formatting files.",
|
|
11
|
+
"type": "boolean",
|
|
12
|
+
"default": false
|
|
13
|
+
},
|
|
14
|
+
"skipPackageJson": {
|
|
15
|
+
"description": "Do not add dependencies to `package.json`.",
|
|
16
|
+
"type": "boolean",
|
|
17
|
+
"default": false
|
|
18
|
+
},
|
|
19
|
+
"keepExistingVersions": {
|
|
20
|
+
"type": "boolean",
|
|
21
|
+
"x-priority": "internal",
|
|
22
|
+
"description": "Keep existing dependencies versions",
|
|
23
|
+
"default": false
|
|
24
|
+
},
|
|
25
|
+
"updatePackageScripts": {
|
|
26
|
+
"type": "boolean",
|
|
27
|
+
"x-priority": "internal",
|
|
28
|
+
"description": "Update `package.json` scripts with inferred targets",
|
|
29
|
+
"default": false
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
"required": []
|
|
33
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const devkit_1 = require("@nx/devkit");
|
|
4
|
+
const add_babel_inputs_1 = require("@nx/js/src/utils/add-babel-inputs");
|
|
5
|
+
async function default_1(tree) {
|
|
6
|
+
(0, add_babel_inputs_1.addBabelInputs)(tree);
|
|
7
|
+
await (0, devkit_1.formatFiles)(tree);
|
|
8
|
+
}
|
|
9
|
+
exports.default = default_1;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const devkit_1 = require("@nx/devkit");
|
|
4
|
+
async function default_1(tree) {
|
|
5
|
+
const projects = (0, devkit_1.getProjects)(tree);
|
|
6
|
+
projects.forEach((p) => {
|
|
7
|
+
let shouldUpdate = false;
|
|
8
|
+
Object.entries(p.targets).forEach(([name, config]) => {
|
|
9
|
+
if (p.targets?.[name]?.executor === '@nrwl/webpack:webpack' &&
|
|
10
|
+
p.targets?.[name]?.options.es2015Polyfills) {
|
|
11
|
+
delete p.targets?.[name]?.options.es2015Polyfills;
|
|
12
|
+
shouldUpdate = true;
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
if (shouldUpdate) {
|
|
16
|
+
(0, devkit_1.updateProjectConfiguration)(tree, p.name, p);
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
exports.default = default_1;
|
|
@@ -0,0 +1,100 @@
|
|
|
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
|
+
const path_1 = require("path");
|
|
6
|
+
async function default_1(tree) {
|
|
7
|
+
// Since projects can have multiple configurations, we need to know if the default options
|
|
8
|
+
// need to be migrated or not. If so then the subsequent configurations with `webpackConfig` also need to be.
|
|
9
|
+
const defaultOptionsUpdated = new Set();
|
|
10
|
+
(0, executor_options_utils_1.forEachExecutorOptions)(tree, '@nrwl/webpack:webpack', (options, projectName, targetName, configurationName) => {
|
|
11
|
+
const projectConfiguration = (0, devkit_1.readProjectConfiguration)(tree, projectName);
|
|
12
|
+
const defaultOptions = projectConfiguration.targets[targetName].options;
|
|
13
|
+
const defaultWasUpdated = defaultOptionsUpdated.has(projectName);
|
|
14
|
+
// If default was not updated (for different configurations), we don't do anything
|
|
15
|
+
// If isolatedConfig is set, we don't need to do anything
|
|
16
|
+
// If project is React, we don't need to do anything
|
|
17
|
+
if (!defaultWasUpdated &&
|
|
18
|
+
(defaultOptions?.isolatedConfig ||
|
|
19
|
+
defaultOptions?.main?.match(/main\.(t|j)sx$/) ||
|
|
20
|
+
defaultOptions?.webpackConfig === '@nrwl/react/plugins/webpack')) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
defaultOptionsUpdated.add(projectName);
|
|
24
|
+
// If this is not the base options (e.g. for development, production, or something custom),
|
|
25
|
+
// then skip it unless it specifically configures a webpackConfig file
|
|
26
|
+
if (configurationName && !options?.webpackConfig) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
// If webpackConfig is set, update it with the new options
|
|
30
|
+
// If webpackConfig is not set, we need to create a new
|
|
31
|
+
// webpack.config.js file and set the path to it in the
|
|
32
|
+
// executor options
|
|
33
|
+
if (options?.webpackConfig) {
|
|
34
|
+
let oldName = options.webpackConfig;
|
|
35
|
+
if (options.webpackConfig.endsWith('.js')) {
|
|
36
|
+
oldName = options.webpackConfig.replace('.js', '.old.js');
|
|
37
|
+
}
|
|
38
|
+
if (options.webpackConfig.endsWith('.ts')) {
|
|
39
|
+
oldName = options.webpackConfig.replace('.ts', '.old.ts');
|
|
40
|
+
}
|
|
41
|
+
renameFile(tree, options.webpackConfig, oldName);
|
|
42
|
+
const justTheFileName = (0, path_1.basename)(oldName);
|
|
43
|
+
tree.write(options.webpackConfig, `
|
|
44
|
+
const { composePlugins, withNx } = require('@nrwl/webpack');
|
|
45
|
+
|
|
46
|
+
// Nx plugins for webpack.
|
|
47
|
+
module.exports = composePlugins(withNx(), (config, { options, context }) => {
|
|
48
|
+
// Note: This was added by an Nx migration.
|
|
49
|
+
// You should consider inlining the logic into this file.
|
|
50
|
+
// For more information on webpack config and Nx see:
|
|
51
|
+
// https://nx.dev/recipes/webpack/webpack-config-setup
|
|
52
|
+
return require('./${justTheFileName}')(config, context);
|
|
53
|
+
});
|
|
54
|
+
`);
|
|
55
|
+
options.isolatedConfig = true;
|
|
56
|
+
projectConfiguration.targets[targetName][configurationName ?? 'options'] = options;
|
|
57
|
+
(0, devkit_1.updateProjectConfiguration)(tree, projectName, projectConfiguration);
|
|
58
|
+
devkit_1.logger.info(`
|
|
59
|
+
${options.webpackConfig} has been renamed to ${oldName} and a new ${options.webpackConfig}
|
|
60
|
+
has been created for your project ${projectName}.
|
|
61
|
+
You should consider inlining the logic from ${oldName} into ${options.webpackConfig}.
|
|
62
|
+
You can read our guide on how to do this here:
|
|
63
|
+
|
|
64
|
+
https://nx.dev/recipes/webpack/webpack-config-setup
|
|
65
|
+
`);
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
const projectConfiguration = (0, devkit_1.readProjectConfiguration)(tree, projectName);
|
|
69
|
+
if (!options) {
|
|
70
|
+
options = {};
|
|
71
|
+
}
|
|
72
|
+
options.webpackConfig = `${projectConfiguration.root}/webpack.config.js`;
|
|
73
|
+
options.isolatedConfig = true;
|
|
74
|
+
tree.write(options.webpackConfig, `
|
|
75
|
+
const { composePlugins, withNx } = require('@nrwl/webpack');
|
|
76
|
+
|
|
77
|
+
// Nx plugins for webpack.
|
|
78
|
+
module.exports = composePlugins(withNx(), (config) => {
|
|
79
|
+
// Update the webpack config as needed here.
|
|
80
|
+
// e.g. config.plugins.push(new MyPlugin())
|
|
81
|
+
// For more information on webpack config and Nx see:
|
|
82
|
+
// https://nx.dev/recipes/webpack/webpack-config-setup
|
|
83
|
+
return config;
|
|
84
|
+
});
|
|
85
|
+
`);
|
|
86
|
+
projectConfiguration.targets[targetName].options = options;
|
|
87
|
+
(0, devkit_1.updateProjectConfiguration)(tree, projectName, projectConfiguration);
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
await (0, devkit_1.formatFiles)(tree);
|
|
91
|
+
}
|
|
92
|
+
exports.default = default_1;
|
|
93
|
+
function renameFile(tree, from, to) {
|
|
94
|
+
const buffer = tree.read(from);
|
|
95
|
+
if (!buffer) {
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
tree.write(to, buffer);
|
|
99
|
+
tree.delete(from);
|
|
100
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
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
|
+
(0, executor_options_utils_1.forEachExecutorOptions)(tree, '@nrwl/webpack:webpack', (options, projectName, targetName, _configurationName) => {
|
|
7
|
+
if (options.babelUpwardRootMode !== undefined) {
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
const projectConfiguration = (0, devkit_1.readProjectConfiguration)(tree, projectName);
|
|
11
|
+
projectConfiguration.targets[targetName].options.babelUpwardRootMode =
|
|
12
|
+
true;
|
|
13
|
+
(0, devkit_1.updateProjectConfiguration)(tree, projectName, projectConfiguration);
|
|
14
|
+
});
|
|
15
|
+
await (0, devkit_1.formatFiles)(tree);
|
|
16
|
+
}
|
|
17
|
+
exports.default = default_1;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const devkit_1 = require("@nx/devkit");
|
|
4
|
+
const replace_package_1 = require("@nx/devkit/src/utils/replace-package");
|
|
5
|
+
async function replacePackage(tree) {
|
|
6
|
+
await (0, replace_package_1.replaceNrwlPackageWithNxPackage)(tree, '@nrwl/webpack', '@nx/webpack');
|
|
7
|
+
await (0, devkit_1.formatFiles)(tree);
|
|
8
|
+
}
|
|
9
|
+
exports.default = replacePackage;
|
|
@@ -0,0 +1,31 @@
|
|
|
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;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type Compiler, type WebpackPluginInstance } from 'webpack';
|
|
2
|
+
import { type ProjectGraph } from '@nx/devkit';
|
|
3
|
+
export declare class GeneratePackageJsonPlugin implements WebpackPluginInstance {
|
|
4
|
+
private readonly options;
|
|
5
|
+
constructor(options: {
|
|
6
|
+
tsConfig: string;
|
|
7
|
+
outputFileName: string;
|
|
8
|
+
root: string;
|
|
9
|
+
projectName: string;
|
|
10
|
+
targetName: string;
|
|
11
|
+
projectGraph: ProjectGraph;
|
|
12
|
+
});
|
|
13
|
+
apply(compiler: Compiler): void;
|
|
14
|
+
}
|