@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,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GeneratePackageJsonPlugin = void 0;
|
|
4
|
+
const webpack_1 = require("webpack");
|
|
5
|
+
const js_1 = require("@nx/js");
|
|
6
|
+
const devkit_1 = require("@nx/devkit");
|
|
7
|
+
const pluginName = 'GeneratePackageJsonPlugin';
|
|
8
|
+
class GeneratePackageJsonPlugin {
|
|
9
|
+
constructor(options) {
|
|
10
|
+
this.options = options;
|
|
11
|
+
}
|
|
12
|
+
apply(compiler) {
|
|
13
|
+
compiler.hooks.thisCompilation.tap(pluginName, (compilation) => {
|
|
14
|
+
compilation.hooks.processAssets.tap({
|
|
15
|
+
name: pluginName,
|
|
16
|
+
stage: compiler.webpack.Compilation.PROCESS_ASSETS_STAGE_ADDITIONAL,
|
|
17
|
+
}, () => {
|
|
18
|
+
const helperDependencies = (0, js_1.getHelperDependenciesFromProjectGraph)(this.options.root, this.options.projectName, this.options.projectGraph);
|
|
19
|
+
const importHelpers = !!(0, js_1.readTsConfig)(this.options.tsConfig).options
|
|
20
|
+
.importHelpers;
|
|
21
|
+
const shouldAddHelperDependency = importHelpers &&
|
|
22
|
+
helperDependencies.every((dep) => dep.target !== js_1.HelperDependency.tsc);
|
|
23
|
+
if (shouldAddHelperDependency) {
|
|
24
|
+
helperDependencies.push({
|
|
25
|
+
type: 'static',
|
|
26
|
+
source: this.options.projectName,
|
|
27
|
+
target: js_1.HelperDependency.tsc,
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
const packageJson = (0, js_1.createPackageJson)(this.options.projectName, this.options.projectGraph, {
|
|
31
|
+
target: this.options.targetName,
|
|
32
|
+
root: this.options.root,
|
|
33
|
+
isProduction: true,
|
|
34
|
+
helperDependencies: helperDependencies.map((dep) => dep.target),
|
|
35
|
+
});
|
|
36
|
+
packageJson.main = packageJson.main ?? this.options.outputFileName;
|
|
37
|
+
compilation.emitAsset('package.json', new webpack_1.sources.RawSource((0, devkit_1.serializeJson)(packageJson)));
|
|
38
|
+
const packageManager = (0, devkit_1.detectPackageManager)(this.options.root);
|
|
39
|
+
compilation.emitAsset((0, js_1.getLockFileName)(packageManager), new webpack_1.sources.RawSource((0, js_1.createLockFile)(packageJson, this.options.projectGraph, packageManager)));
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
exports.GeneratePackageJsonPlugin = GeneratePackageJsonPlugin;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NxTsconfigPathsWebpackPlugin = void 0;
|
|
4
|
+
const path = require("path");
|
|
5
|
+
const tsconfig_paths_webpack_plugin_1 = require("tsconfig-paths-webpack-plugin");
|
|
6
|
+
const devkit_1 = require("@nx/devkit");
|
|
7
|
+
class NxTsconfigPathsWebpackPlugin {
|
|
8
|
+
constructor(options) {
|
|
9
|
+
this.options = options;
|
|
10
|
+
if (!this.options.tsConfig)
|
|
11
|
+
throw new Error(`Missing "tsConfig" option. Set this option in your Nx webpack plugin.`);
|
|
12
|
+
}
|
|
13
|
+
apply(compiler) {
|
|
14
|
+
const extensions = new Set([
|
|
15
|
+
...['.ts', '.tsx', '.mjs', '.js', '.jsx'],
|
|
16
|
+
...(compiler.options?.resolve?.extensions ?? []),
|
|
17
|
+
]);
|
|
18
|
+
compiler.options.resolve = {
|
|
19
|
+
...compiler.options.resolve,
|
|
20
|
+
plugins: compiler.options.resolve?.plugins ?? [],
|
|
21
|
+
};
|
|
22
|
+
compiler.options.resolve.plugins.push(new tsconfig_paths_webpack_plugin_1.TsconfigPathsPlugin({
|
|
23
|
+
configFile: !path.isAbsolute(this.options.tsConfig)
|
|
24
|
+
? path.join(devkit_1.workspaceRoot, this.options.tsConfig)
|
|
25
|
+
: this.options.tsConfig,
|
|
26
|
+
extensions: Array.from(extensions),
|
|
27
|
+
mainFields: ['module', 'main'],
|
|
28
|
+
}));
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
exports.NxTsconfigPathsWebpackPlugin = NxTsconfigPathsWebpackPlugin;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { Configuration, WebpackOptionsNormalized } from 'webpack';
|
|
2
|
+
import { NormalizedNxWebpackPluginOptions } from '../nx-webpack-plugin-options';
|
|
3
|
+
export declare function applyBaseConfig(options: NormalizedNxWebpackPluginOptions, config?: Partial<WebpackOptionsNormalized | Configuration>, { useNormalizedEntry, }?: {
|
|
4
|
+
useNormalizedEntry?: boolean;
|
|
5
|
+
}): void;
|
|
@@ -0,0 +1,318 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.applyBaseConfig = void 0;
|
|
4
|
+
const path = require("path");
|
|
5
|
+
const license_webpack_plugin_1 = require("license-webpack-plugin");
|
|
6
|
+
const CopyWebpackPlugin = require("copy-webpack-plugin");
|
|
7
|
+
const webpack_1 = require("webpack");
|
|
8
|
+
const js_1 = require("@nx/js");
|
|
9
|
+
const stats_json_plugin_1 = require("../../stats-json-plugin");
|
|
10
|
+
const generate_package_json_plugin_1 = require("../../generate-package-json-plugin");
|
|
11
|
+
const hash_format_1 = require("../../../utils/hash-format");
|
|
12
|
+
const nx_tsconfig_paths_webpack_plugin_1 = require("../../nx-typescript-webpack-plugin/nx-tsconfig-paths-webpack-plugin");
|
|
13
|
+
const get_terser_ecma_version_1 = require("./get-terser-ecma-version");
|
|
14
|
+
const compiler_loaders_1 = require("./compiler-loaders");
|
|
15
|
+
const TerserPlugin = require("terser-webpack-plugin");
|
|
16
|
+
const nodeExternals = require("webpack-node-externals");
|
|
17
|
+
const IGNORED_WEBPACK_WARNINGS = [
|
|
18
|
+
/The comment file/i,
|
|
19
|
+
/could not find any license/i,
|
|
20
|
+
];
|
|
21
|
+
const extensions = ['.ts', '.tsx', '.mjs', '.js', '.jsx'];
|
|
22
|
+
const mainFields = ['module', 'main'];
|
|
23
|
+
function applyBaseConfig(options, config = {}, { useNormalizedEntry, } = {}) {
|
|
24
|
+
// Defaults that was applied from executor schema previously.
|
|
25
|
+
options.compiler ??= 'babel';
|
|
26
|
+
options.deleteOutputPath ??= true;
|
|
27
|
+
options.externalDependencies ??= 'all';
|
|
28
|
+
options.fileReplacements ??= [];
|
|
29
|
+
options.memoryLimit ??= 2048;
|
|
30
|
+
options.transformers ??= [];
|
|
31
|
+
applyNxIndependentConfig(options, config);
|
|
32
|
+
// Some of the options only work during actual tasks, not when reading the webpack config during CreateNodes.
|
|
33
|
+
if (!process.env['NX_TASK_TARGET_PROJECT'])
|
|
34
|
+
return;
|
|
35
|
+
applyNxDependentConfig(options, config, { useNormalizedEntry });
|
|
36
|
+
}
|
|
37
|
+
exports.applyBaseConfig = applyBaseConfig;
|
|
38
|
+
function applyNxIndependentConfig(options, config) {
|
|
39
|
+
const hashFormat = (0, hash_format_1.getOutputHashFormat)(options.outputHashing);
|
|
40
|
+
config.context = path.join(options.root, options.projectRoot);
|
|
41
|
+
config.target ??= options.target;
|
|
42
|
+
config.node = false;
|
|
43
|
+
config.mode =
|
|
44
|
+
// When the target is Node avoid any optimizations, such as replacing `process.env.NODE_ENV` with build time value.
|
|
45
|
+
config.target === 'node'
|
|
46
|
+
? 'none'
|
|
47
|
+
: // Otherwise, make sure it matches `process.env.NODE_ENV`.
|
|
48
|
+
// When mode is development or production, webpack will automatically
|
|
49
|
+
// configure DefinePlugin to replace `process.env.NODE_ENV` with the
|
|
50
|
+
// build-time value. Thus, we need to make sure it's the same value to
|
|
51
|
+
// avoid conflicts.
|
|
52
|
+
//
|
|
53
|
+
// When the NODE_ENV is something else (e.g. test), then set it to none
|
|
54
|
+
// to prevent extra behavior from webpack.
|
|
55
|
+
process.env.NODE_ENV === 'development' ||
|
|
56
|
+
process.env.NODE_ENV === 'production'
|
|
57
|
+
? process.env.NODE_ENV
|
|
58
|
+
: 'none';
|
|
59
|
+
// When target is Node, the Webpack mode will be set to 'none' which disables in memory caching and causes a full rebuild on every change.
|
|
60
|
+
// So to mitigate this we enable in memory caching when target is Node and in watch mode.
|
|
61
|
+
config.cache =
|
|
62
|
+
options.target === 'node' && options.watch ? { type: 'memory' } : undefined;
|
|
63
|
+
config.devtool =
|
|
64
|
+
options.sourceMap === 'hidden'
|
|
65
|
+
? 'hidden-source-map'
|
|
66
|
+
: options.sourceMap
|
|
67
|
+
? 'source-map'
|
|
68
|
+
: false;
|
|
69
|
+
config.output = {
|
|
70
|
+
...config.output,
|
|
71
|
+
libraryTarget: (config.output?.libraryTarget ??
|
|
72
|
+
options.target === 'node')
|
|
73
|
+
? 'commonjs'
|
|
74
|
+
: undefined,
|
|
75
|
+
path: config.output?.path ??
|
|
76
|
+
(options.outputPath
|
|
77
|
+
? path.join(options.root, options.outputPath)
|
|
78
|
+
: undefined),
|
|
79
|
+
filename: config.output?.filename ?? options.outputHashing
|
|
80
|
+
? `[name]${hashFormat.script}.js`
|
|
81
|
+
: '[name].js',
|
|
82
|
+
chunkFilename: config.output?.chunkFilename ?? options.outputHashing
|
|
83
|
+
? `[name]${hashFormat.chunk}.js`
|
|
84
|
+
: '[name].js',
|
|
85
|
+
hashFunction: config.output?.hashFunction ?? 'xxhash64',
|
|
86
|
+
// Disabled for performance
|
|
87
|
+
pathinfo: config.output?.pathinfo ?? false,
|
|
88
|
+
// Use CJS for Node since it has the widest support.
|
|
89
|
+
scriptType: config.output?.scriptType ?? options.target === 'node'
|
|
90
|
+
? undefined
|
|
91
|
+
: 'module',
|
|
92
|
+
};
|
|
93
|
+
config.watch = options.watch;
|
|
94
|
+
config.watchOptions = {
|
|
95
|
+
poll: options.poll,
|
|
96
|
+
};
|
|
97
|
+
config.profile = options.statsJson;
|
|
98
|
+
config.performance = {
|
|
99
|
+
...config.performance,
|
|
100
|
+
hints: false,
|
|
101
|
+
};
|
|
102
|
+
config.experiments = { ...config.experiments, cacheUnaffected: true };
|
|
103
|
+
config.ignoreWarnings = [
|
|
104
|
+
(x) => IGNORED_WEBPACK_WARNINGS.some((r) => typeof x === 'string' ? r.test(x) : r.test(x.message)),
|
|
105
|
+
];
|
|
106
|
+
config.optimization = {
|
|
107
|
+
...config.optimization,
|
|
108
|
+
sideEffects: true,
|
|
109
|
+
minimize: typeof options.optimization === 'object'
|
|
110
|
+
? !!options.optimization.scripts
|
|
111
|
+
: !!options.optimization,
|
|
112
|
+
minimizer: [
|
|
113
|
+
options.compiler !== 'swc'
|
|
114
|
+
? new TerserPlugin({
|
|
115
|
+
parallel: true,
|
|
116
|
+
terserOptions: {
|
|
117
|
+
keep_classnames: true,
|
|
118
|
+
ecma: (0, get_terser_ecma_version_1.getTerserEcmaVersion)(path.join(options.root, options.projectRoot)),
|
|
119
|
+
safari10: true,
|
|
120
|
+
format: {
|
|
121
|
+
ascii_only: true,
|
|
122
|
+
comments: false,
|
|
123
|
+
webkit: true,
|
|
124
|
+
},
|
|
125
|
+
},
|
|
126
|
+
extractComments: false,
|
|
127
|
+
})
|
|
128
|
+
: new TerserPlugin({
|
|
129
|
+
minify: TerserPlugin.swcMinify,
|
|
130
|
+
// `terserOptions` options will be passed to `swc`
|
|
131
|
+
terserOptions: {
|
|
132
|
+
module: true,
|
|
133
|
+
mangle: false,
|
|
134
|
+
},
|
|
135
|
+
}),
|
|
136
|
+
],
|
|
137
|
+
runtimeChunk: false,
|
|
138
|
+
concatenateModules: true,
|
|
139
|
+
};
|
|
140
|
+
config.stats = {
|
|
141
|
+
hash: true,
|
|
142
|
+
timings: false,
|
|
143
|
+
cached: false,
|
|
144
|
+
cachedAssets: false,
|
|
145
|
+
modules: false,
|
|
146
|
+
warnings: true,
|
|
147
|
+
errors: true,
|
|
148
|
+
colors: !options.verbose && !options.statsJson,
|
|
149
|
+
chunks: !options.verbose,
|
|
150
|
+
assets: !!options.verbose,
|
|
151
|
+
chunkOrigins: !!options.verbose,
|
|
152
|
+
chunkModules: !!options.verbose,
|
|
153
|
+
children: !!options.verbose,
|
|
154
|
+
reasons: !!options.verbose,
|
|
155
|
+
version: !!options.verbose,
|
|
156
|
+
errorDetails: !!options.verbose,
|
|
157
|
+
moduleTrace: !!options.verbose,
|
|
158
|
+
usedExports: !!options.verbose,
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
function applyNxDependentConfig(options, config, { useNormalizedEntry } = {}) {
|
|
162
|
+
const tsConfig = options.tsConfig ?? (0, js_1.getRootTsConfigPath)();
|
|
163
|
+
const plugins = [
|
|
164
|
+
new nx_tsconfig_paths_webpack_plugin_1.NxTsconfigPathsWebpackPlugin({ tsConfig }),
|
|
165
|
+
];
|
|
166
|
+
const executorContext = {
|
|
167
|
+
projectName: options.projectName,
|
|
168
|
+
targetName: options.targetName,
|
|
169
|
+
projectGraph: options.projectGraph,
|
|
170
|
+
configurationName: options.configurationName,
|
|
171
|
+
root: options.root,
|
|
172
|
+
};
|
|
173
|
+
if (!options?.skipTypeChecking) {
|
|
174
|
+
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
|
|
175
|
+
plugins.push(new ForkTsCheckerWebpackPlugin({
|
|
176
|
+
typescript: {
|
|
177
|
+
configFile: path.isAbsolute(tsConfig)
|
|
178
|
+
? tsConfig
|
|
179
|
+
: path.join(options.root, tsConfig),
|
|
180
|
+
memoryLimit: options.memoryLimit || 2018,
|
|
181
|
+
},
|
|
182
|
+
}));
|
|
183
|
+
}
|
|
184
|
+
const entries = [];
|
|
185
|
+
if (options.main) {
|
|
186
|
+
const mainEntry = options.outputFileName
|
|
187
|
+
? path.parse(options.outputFileName).name
|
|
188
|
+
: 'main';
|
|
189
|
+
entries.push({
|
|
190
|
+
name: mainEntry,
|
|
191
|
+
import: [path.resolve(options.root, options.main)],
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
if (options.additionalEntryPoints) {
|
|
195
|
+
for (const { entryName, entryPath } of options.additionalEntryPoints) {
|
|
196
|
+
entries.push({
|
|
197
|
+
name: entryName,
|
|
198
|
+
import: [path.resolve(options.root, entryPath)],
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
if (options.polyfills) {
|
|
203
|
+
entries.push({
|
|
204
|
+
name: 'polyfills',
|
|
205
|
+
import: [path.resolve(options.root, options.polyfills)],
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
config.entry ??= {};
|
|
209
|
+
entries.forEach((entry) => {
|
|
210
|
+
if (useNormalizedEntry) {
|
|
211
|
+
config.entry[entry.name] = { import: entry.import };
|
|
212
|
+
}
|
|
213
|
+
else {
|
|
214
|
+
config.entry[entry.name] = entry.import;
|
|
215
|
+
}
|
|
216
|
+
});
|
|
217
|
+
if (options.progress) {
|
|
218
|
+
plugins.push(new webpack_1.ProgressPlugin({ profile: options.verbose }));
|
|
219
|
+
}
|
|
220
|
+
if (options.extractLicenses) {
|
|
221
|
+
plugins.push(new license_webpack_plugin_1.LicenseWebpackPlugin({
|
|
222
|
+
stats: {
|
|
223
|
+
warnings: false,
|
|
224
|
+
errors: false,
|
|
225
|
+
},
|
|
226
|
+
perChunkOutput: false,
|
|
227
|
+
outputFilename: `3rdpartylicenses.txt`,
|
|
228
|
+
}));
|
|
229
|
+
}
|
|
230
|
+
if (Array.isArray(options.assets) && options.assets.length > 0) {
|
|
231
|
+
plugins.push(new CopyWebpackPlugin({
|
|
232
|
+
patterns: options.assets.map((asset) => {
|
|
233
|
+
return {
|
|
234
|
+
context: asset.input,
|
|
235
|
+
// Now we remove starting slash to make Webpack place it from the output root.
|
|
236
|
+
to: asset.output,
|
|
237
|
+
from: asset.glob,
|
|
238
|
+
globOptions: {
|
|
239
|
+
ignore: [
|
|
240
|
+
'.gitkeep',
|
|
241
|
+
'**/.DS_Store',
|
|
242
|
+
'**/Thumbs.db',
|
|
243
|
+
...(asset.ignore ?? []),
|
|
244
|
+
],
|
|
245
|
+
dot: true,
|
|
246
|
+
},
|
|
247
|
+
};
|
|
248
|
+
}),
|
|
249
|
+
}));
|
|
250
|
+
}
|
|
251
|
+
if (options.generatePackageJson && executorContext) {
|
|
252
|
+
plugins.push(new generate_package_json_plugin_1.GeneratePackageJsonPlugin({ ...options, tsConfig }));
|
|
253
|
+
}
|
|
254
|
+
if (options.statsJson) {
|
|
255
|
+
plugins.push(new stats_json_plugin_1.StatsJsonPlugin());
|
|
256
|
+
}
|
|
257
|
+
const externals = [];
|
|
258
|
+
if (options.target === 'node' && options.externalDependencies === 'all') {
|
|
259
|
+
const modulesDir = `${options.root}/node_modules`;
|
|
260
|
+
externals.push(nodeExternals({ modulesDir }));
|
|
261
|
+
}
|
|
262
|
+
else if (Array.isArray(options.externalDependencies)) {
|
|
263
|
+
externals.push(function (ctx, callback) {
|
|
264
|
+
if (options.externalDependencies.includes(ctx.request)) {
|
|
265
|
+
// not bundled
|
|
266
|
+
return callback(null, `commonjs ${ctx.request}`);
|
|
267
|
+
}
|
|
268
|
+
// bundled
|
|
269
|
+
callback();
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
config.resolve = {
|
|
273
|
+
...config.resolve,
|
|
274
|
+
extensions: [...(config?.resolve?.extensions ?? []), ...extensions],
|
|
275
|
+
alias: {
|
|
276
|
+
...(config.resolve?.alias ?? {}),
|
|
277
|
+
...(options.fileReplacements?.reduce((aliases, replacement) => ({
|
|
278
|
+
...aliases,
|
|
279
|
+
[replacement.replace]: replacement.with,
|
|
280
|
+
}), {}) ?? {}),
|
|
281
|
+
},
|
|
282
|
+
mainFields: config.resolve?.mainFields ?? mainFields,
|
|
283
|
+
};
|
|
284
|
+
config.externals = externals;
|
|
285
|
+
config.module = {
|
|
286
|
+
...config.module,
|
|
287
|
+
// Enabled for performance
|
|
288
|
+
unsafeCache: true,
|
|
289
|
+
rules: [
|
|
290
|
+
...(config?.module?.rules ?? []),
|
|
291
|
+
options.sourceMap && {
|
|
292
|
+
test: /\.js$/,
|
|
293
|
+
enforce: 'pre',
|
|
294
|
+
loader: require.resolve('source-map-loader'),
|
|
295
|
+
},
|
|
296
|
+
{
|
|
297
|
+
// There's an issue resolving paths without fully specified extensions
|
|
298
|
+
// See: https://github.com/graphql/graphql-js/issues/2721
|
|
299
|
+
// TODO(jack): Add a flag to turn this option on like Next.js does via experimental flag.
|
|
300
|
+
// See: https://github.com/vercel/next.js/pull/29880
|
|
301
|
+
test: /\.m?jsx?$/,
|
|
302
|
+
resolve: {
|
|
303
|
+
fullySpecified: false,
|
|
304
|
+
},
|
|
305
|
+
},
|
|
306
|
+
// There's an issue when using buildable libs and .js files (instead of .ts files),
|
|
307
|
+
// where the wrong type is used (commonjs vs esm) resulting in export-imports throwing errors.
|
|
308
|
+
// See: https://github.com/nrwl/nx/issues/10990
|
|
309
|
+
{
|
|
310
|
+
test: /\.js$/,
|
|
311
|
+
type: 'javascript/auto',
|
|
312
|
+
},
|
|
313
|
+
(0, compiler_loaders_1.createLoaderFromCompiler)(options),
|
|
314
|
+
].filter((r) => !!r),
|
|
315
|
+
};
|
|
316
|
+
config.plugins ??= [];
|
|
317
|
+
config.plugins.push(...plugins);
|
|
318
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { Configuration, WebpackOptionsNormalized } from 'webpack';
|
|
2
|
+
import { NormalizedNxWebpackPluginOptions } from '../nx-webpack-plugin-options';
|
|
3
|
+
export declare function applyWebConfig(options: NormalizedNxWebpackPluginOptions, config?: Partial<WebpackOptionsNormalized | Configuration>, { useNormalizedEntry, }?: {
|
|
4
|
+
useNormalizedEntry?: boolean;
|
|
5
|
+
}): void;
|