@nx/webpack 17.0.2 → 17.0.4
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 +1 -1
- package/README.md +9 -4
- package/generators.json +2 -2
- package/index.d.ts +3 -1
- package/index.js +7 -2
- package/migrations.json +6 -0
- package/package.json +6 -5
- package/plugin.d.ts +1 -0
- package/plugin.js +5 -0
- package/src/executors/dev-server/dev-server.impl.js +31 -17
- 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.d.ts +1 -2
- package/src/executors/webpack/lib/normalize-options.js +9 -53
- package/src/executors/webpack/schema.d.ts +10 -7
- package/src/executors/webpack/schema.json +30 -50
- package/src/executors/webpack/webpack.impl.js +36 -16
- package/src/generators/configuration/configuration.d.ts +3 -2
- package/src/generators/configuration/configuration.js +95 -23
- package/src/generators/configuration/schema.d.ts +1 -0
- package/src/generators/configuration/schema.json +1 -1
- package/src/generators/init/init.d.ts +1 -0
- package/src/generators/init/init.js +48 -23
- package/src/generators/init/schema.d.ts +4 -2
- package/src/generators/init/schema.json +18 -13
- 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 +6 -4
- package/src/plugins/generate-package-json-plugin.js +11 -14
- 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 +148 -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 +132 -0
- package/src/utils/config.d.ts +11 -6
- package/src/utils/config.js +48 -13
- package/src/utils/ensure-dependencies.d.ts +6 -0
- package/src/utils/ensure-dependencies.js +28 -0
- package/src/utils/get-client-environment.js +4 -1
- package/src/utils/has-plugin.d.ts +2 -0
- package/src/utils/has-plugin.js +11 -0
- package/src/utils/module-federation/dependencies.js +15 -3
- package/src/utils/module-federation/get-remotes-for-host.js +2 -2
- package/src/utils/module-federation/remotes.js +1 -1
- package/src/utils/module-federation/secondary-entry-points.js +1 -1
- package/src/utils/module-federation/typescript.js +14 -9
- package/src/utils/versions.d.ts +1 -0
- package/src/utils/versions.js +2 -1
- package/src/utils/webpack/deprecated-stylus-loader.js +2 -2
- package/src/utils/webpack/interpolate-env-variables-to-index.js +4 -1
- package/src/utils/webpack/plugins/postcss-cli-resources.js +2 -2
- 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/{custom-webpack.js → resolve-user-defined-webpack-config.js} +14 -8
- package/src/utils/with-nx.d.ts +4 -58
- package/src/utils/with-nx.js +22 -362
- package/src/utils/with-web.d.ts +2 -2
- package/src/utils/with-web.js +9 -488
- 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
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.normalizeFileReplacements = exports.normalizeAssets = exports.normalizeOptions = void 0;
|
|
4
|
+
const path_1 = require("path");
|
|
5
|
+
const fs_1 = require("fs");
|
|
6
|
+
const devkit_1 = require("@nx/devkit");
|
|
7
|
+
function normalizeOptions(options) {
|
|
8
|
+
const combinedPluginAndMaybeExecutorOptions = {};
|
|
9
|
+
const isProd = process.env.NODE_ENV === 'production';
|
|
10
|
+
const projectName = process.env.NX_TASK_TARGET_PROJECT;
|
|
11
|
+
const targetName = process.env.NX_TASK_TARGET_TARGET;
|
|
12
|
+
const configurationName = process.env.NX_TASK_TARGET_CONFIGURATION;
|
|
13
|
+
// Since this is invoked by the executor, the graph has already been created and cached.
|
|
14
|
+
const projectGraph = (0, devkit_1.readCachedProjectGraph)();
|
|
15
|
+
const projectNode = projectGraph.nodes[projectName];
|
|
16
|
+
const targetConfig = projectNode.data.targets[targetName];
|
|
17
|
+
normalizeRelativePaths(projectNode.data.root, options);
|
|
18
|
+
// Merge options from `@nx/webpack:webpack` into plugin options.
|
|
19
|
+
// Options from `@nx/webpack:webpack` take precedence.
|
|
20
|
+
const originalTargetOptions = targetConfig.options;
|
|
21
|
+
if (configurationName) {
|
|
22
|
+
Object.assign(originalTargetOptions, targetConfig.configurations?.[configurationName]);
|
|
23
|
+
}
|
|
24
|
+
// This could be called from dev-server which means we need to read `buildTarget` to get actual build options.
|
|
25
|
+
// Otherwise, the options are passed from the `@nx/webpack:webpack` executor.
|
|
26
|
+
if (originalTargetOptions.buildTarget) {
|
|
27
|
+
const buildTargetOptions = targetConfig.options;
|
|
28
|
+
if (configurationName) {
|
|
29
|
+
Object.assign(buildTargetOptions, targetConfig.configurations?.[configurationName]);
|
|
30
|
+
}
|
|
31
|
+
Object.assign(combinedPluginAndMaybeExecutorOptions, options,
|
|
32
|
+
// executor options take precedence (especially for overriding with CLI args)
|
|
33
|
+
buildTargetOptions);
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
Object.assign(combinedPluginAndMaybeExecutorOptions, options,
|
|
37
|
+
// executor options take precedence (especially for overriding with CLI args)
|
|
38
|
+
originalTargetOptions);
|
|
39
|
+
}
|
|
40
|
+
const sourceRoot = projectNode.data.sourceRoot ?? projectNode.data.root;
|
|
41
|
+
if (!options.main) {
|
|
42
|
+
throw new Error(`Missing "main" option for the entry file. Set this option in your Nx webpack plugin.`);
|
|
43
|
+
}
|
|
44
|
+
return {
|
|
45
|
+
...combinedPluginAndMaybeExecutorOptions,
|
|
46
|
+
assets: combinedPluginAndMaybeExecutorOptions.assets
|
|
47
|
+
? normalizeAssets(combinedPluginAndMaybeExecutorOptions.assets, devkit_1.workspaceRoot, sourceRoot, projectNode.data.root)
|
|
48
|
+
: [],
|
|
49
|
+
baseHref: combinedPluginAndMaybeExecutorOptions.baseHref ?? '/',
|
|
50
|
+
commonChunk: combinedPluginAndMaybeExecutorOptions.commonChunk ?? true,
|
|
51
|
+
compiler: combinedPluginAndMaybeExecutorOptions.compiler ?? 'babel',
|
|
52
|
+
configurationName,
|
|
53
|
+
deleteOutputPath: combinedPluginAndMaybeExecutorOptions.deleteOutputPath ?? true,
|
|
54
|
+
extractCss: combinedPluginAndMaybeExecutorOptions.extractCss ?? true,
|
|
55
|
+
fileReplacements: normalizeFileReplacements(devkit_1.workspaceRoot, combinedPluginAndMaybeExecutorOptions.fileReplacements),
|
|
56
|
+
generateIndexHtml: combinedPluginAndMaybeExecutorOptions.generateIndexHtml ?? true,
|
|
57
|
+
main: combinedPluginAndMaybeExecutorOptions.main,
|
|
58
|
+
namedChunks: combinedPluginAndMaybeExecutorOptions.namedChunks ?? !isProd,
|
|
59
|
+
optimization: combinedPluginAndMaybeExecutorOptions.optimization ?? isProd,
|
|
60
|
+
outputFileName: combinedPluginAndMaybeExecutorOptions.outputFileName ?? 'main.js',
|
|
61
|
+
outputHashing: combinedPluginAndMaybeExecutorOptions.outputHashing ??
|
|
62
|
+
(isProd ? 'all' : 'none'),
|
|
63
|
+
outputPath: combinedPluginAndMaybeExecutorOptions.outputPath,
|
|
64
|
+
projectGraph,
|
|
65
|
+
projectName,
|
|
66
|
+
projectRoot: projectNode.data.root,
|
|
67
|
+
root: devkit_1.workspaceRoot,
|
|
68
|
+
runtimeChunk: combinedPluginAndMaybeExecutorOptions.runtimeChunk ?? true,
|
|
69
|
+
scripts: combinedPluginAndMaybeExecutorOptions.scripts ?? [],
|
|
70
|
+
sourceMap: combinedPluginAndMaybeExecutorOptions.sourceMap ?? !isProd,
|
|
71
|
+
sourceRoot,
|
|
72
|
+
styles: combinedPluginAndMaybeExecutorOptions.styles ?? [],
|
|
73
|
+
target: combinedPluginAndMaybeExecutorOptions.target,
|
|
74
|
+
targetName,
|
|
75
|
+
vendorChunk: combinedPluginAndMaybeExecutorOptions.vendorChunk ?? !isProd,
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
exports.normalizeOptions = normalizeOptions;
|
|
79
|
+
function normalizeAssets(assets, root, sourceRoot, projectRoot, resolveRelativePathsToProjectRoot = true) {
|
|
80
|
+
return assets.map((asset) => {
|
|
81
|
+
if (typeof asset === 'string') {
|
|
82
|
+
const assetPath = (0, devkit_1.normalizePath)(asset);
|
|
83
|
+
const resolvedAssetPath = (0, path_1.resolve)(root, assetPath);
|
|
84
|
+
const resolvedSourceRoot = (0, path_1.resolve)(root, sourceRoot);
|
|
85
|
+
if (!resolvedAssetPath.startsWith(resolvedSourceRoot)) {
|
|
86
|
+
throw new Error(`The ${resolvedAssetPath} asset path must start with the project source root: ${sourceRoot}`);
|
|
87
|
+
}
|
|
88
|
+
const isDirectory = (0, fs_1.statSync)(resolvedAssetPath).isDirectory();
|
|
89
|
+
const input = isDirectory
|
|
90
|
+
? resolvedAssetPath
|
|
91
|
+
: (0, path_1.dirname)(resolvedAssetPath);
|
|
92
|
+
const output = (0, path_1.relative)(resolvedSourceRoot, (0, path_1.resolve)(root, input));
|
|
93
|
+
const glob = isDirectory ? '**/*' : (0, path_1.basename)(resolvedAssetPath);
|
|
94
|
+
return {
|
|
95
|
+
input,
|
|
96
|
+
output,
|
|
97
|
+
glob,
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
if (asset.output.startsWith('..')) {
|
|
102
|
+
throw new Error('An asset cannot be written to a location outside of the output path.');
|
|
103
|
+
}
|
|
104
|
+
const assetPath = (0, devkit_1.normalizePath)(asset.input);
|
|
105
|
+
let resolvedAssetPath = (0, path_1.resolve)(root, assetPath);
|
|
106
|
+
if (resolveRelativePathsToProjectRoot && asset.input.startsWith('.')) {
|
|
107
|
+
const resolvedProjectRoot = (0, path_1.resolve)(root, projectRoot);
|
|
108
|
+
resolvedAssetPath = (0, path_1.resolve)(resolvedProjectRoot, assetPath);
|
|
109
|
+
}
|
|
110
|
+
return {
|
|
111
|
+
...asset,
|
|
112
|
+
input: resolvedAssetPath,
|
|
113
|
+
// Now we remove starting slash to make Webpack place it from the output root.
|
|
114
|
+
output: asset.output.replace(/^\//, ''),
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
exports.normalizeAssets = normalizeAssets;
|
|
120
|
+
function normalizeFileReplacements(root, fileReplacements) {
|
|
121
|
+
return fileReplacements
|
|
122
|
+
? fileReplacements.map((fileReplacement) => ({
|
|
123
|
+
replace: (0, path_1.resolve)(root, fileReplacement.replace),
|
|
124
|
+
with: (0, path_1.resolve)(root, fileReplacement.with),
|
|
125
|
+
}))
|
|
126
|
+
: [];
|
|
127
|
+
}
|
|
128
|
+
exports.normalizeFileReplacements = normalizeFileReplacements;
|
|
129
|
+
function normalizeRelativePaths(projectRoot, options) {
|
|
130
|
+
for (const [fieldName, fieldValue] of Object.entries(options)) {
|
|
131
|
+
if (isRelativePath(fieldValue)) {
|
|
132
|
+
options[fieldName] = (0, path_1.join)(projectRoot, fieldValue);
|
|
133
|
+
}
|
|
134
|
+
else if (Array.isArray(fieldValue)) {
|
|
135
|
+
for (let i = 0; i < fieldValue.length; i++) {
|
|
136
|
+
if (isRelativePath(fieldValue[i])) {
|
|
137
|
+
fieldValue[i] = (0, path_1.join)(projectRoot, fieldValue[i]);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
function isRelativePath(val) {
|
|
144
|
+
return (typeof val === 'string' &&
|
|
145
|
+
(val.startsWith('./') ||
|
|
146
|
+
// Windows
|
|
147
|
+
val.startsWith('.\\')));
|
|
148
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { getCSSModuleLocalIdent } from '../../../utils/get-css-module-local-ident';
|
|
2
|
+
import { NormalizedNxWebpackPluginOptions } from '../nx-webpack-plugin-options';
|
|
3
|
+
interface PostcssOptions {
|
|
4
|
+
(loader: any): any;
|
|
5
|
+
config?: string;
|
|
6
|
+
}
|
|
7
|
+
export declare function getCommonLoadersForCssModules(options: NormalizedNxWebpackPluginOptions, includePaths: string[]): ({
|
|
8
|
+
loader: any;
|
|
9
|
+
options?: undefined;
|
|
10
|
+
} | {
|
|
11
|
+
loader: string;
|
|
12
|
+
options: {
|
|
13
|
+
modules: {
|
|
14
|
+
mode: string;
|
|
15
|
+
getLocalIdent: typeof getCSSModuleLocalIdent;
|
|
16
|
+
};
|
|
17
|
+
importLoaders: number;
|
|
18
|
+
implementation?: undefined;
|
|
19
|
+
postcssOptions?: undefined;
|
|
20
|
+
};
|
|
21
|
+
} | {
|
|
22
|
+
loader: string;
|
|
23
|
+
options: {
|
|
24
|
+
implementation: any;
|
|
25
|
+
postcssOptions: PostcssOptions;
|
|
26
|
+
modules?: undefined;
|
|
27
|
+
importLoaders?: undefined;
|
|
28
|
+
};
|
|
29
|
+
})[];
|
|
30
|
+
export declare function getCommonLoadersForGlobalCss(options: NormalizedNxWebpackPluginOptions, includePaths: string[]): ({
|
|
31
|
+
loader: any;
|
|
32
|
+
options?: undefined;
|
|
33
|
+
} | {
|
|
34
|
+
loader: string;
|
|
35
|
+
options: {
|
|
36
|
+
url: boolean;
|
|
37
|
+
implementation?: undefined;
|
|
38
|
+
postcssOptions?: undefined;
|
|
39
|
+
};
|
|
40
|
+
} | {
|
|
41
|
+
loader: string;
|
|
42
|
+
options: {
|
|
43
|
+
implementation: any;
|
|
44
|
+
postcssOptions: PostcssOptions;
|
|
45
|
+
url?: undefined;
|
|
46
|
+
};
|
|
47
|
+
})[];
|
|
48
|
+
export declare function getCommonLoadersForGlobalStyle(options: NormalizedNxWebpackPluginOptions, includePaths: string[]): ({
|
|
49
|
+
loader: any;
|
|
50
|
+
options: {
|
|
51
|
+
esModule: boolean;
|
|
52
|
+
url?: undefined;
|
|
53
|
+
implementation?: undefined;
|
|
54
|
+
postcssOptions?: undefined;
|
|
55
|
+
};
|
|
56
|
+
} | {
|
|
57
|
+
loader: string;
|
|
58
|
+
options: {
|
|
59
|
+
url: boolean;
|
|
60
|
+
esModule?: undefined;
|
|
61
|
+
implementation?: undefined;
|
|
62
|
+
postcssOptions?: undefined;
|
|
63
|
+
};
|
|
64
|
+
} | {
|
|
65
|
+
loader: string;
|
|
66
|
+
options: {
|
|
67
|
+
implementation: any;
|
|
68
|
+
postcssOptions: PostcssOptions;
|
|
69
|
+
esModule?: undefined;
|
|
70
|
+
url?: undefined;
|
|
71
|
+
};
|
|
72
|
+
})[];
|
|
73
|
+
export {};
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getCommonLoadersForGlobalStyle = exports.getCommonLoadersForGlobalCss = exports.getCommonLoadersForCssModules = void 0;
|
|
4
|
+
const path = require("path");
|
|
5
|
+
const autoprefixer = require("autoprefixer");
|
|
6
|
+
const postcssImports = require("postcss-import");
|
|
7
|
+
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
|
|
8
|
+
const get_css_module_local_ident_1 = require("../../../utils/get-css-module-local-ident");
|
|
9
|
+
const hash_format_1 = require("../../../utils/hash-format");
|
|
10
|
+
const postcss_cli_resources_1 = require("../../../utils/webpack/plugins/postcss-cli-resources");
|
|
11
|
+
function getCommonLoadersForCssModules(options, includePaths) {
|
|
12
|
+
// load component css as raw strings
|
|
13
|
+
return [
|
|
14
|
+
{
|
|
15
|
+
loader: options.extractCss
|
|
16
|
+
? MiniCssExtractPlugin.loader
|
|
17
|
+
: require.resolve('style-loader'),
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
loader: require.resolve('css-loader'),
|
|
21
|
+
options: {
|
|
22
|
+
modules: {
|
|
23
|
+
mode: 'local',
|
|
24
|
+
getLocalIdent: get_css_module_local_ident_1.getCSSModuleLocalIdent,
|
|
25
|
+
},
|
|
26
|
+
importLoaders: 1,
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
loader: require.resolve('postcss-loader'),
|
|
31
|
+
options: {
|
|
32
|
+
implementation: require('postcss'),
|
|
33
|
+
postcssOptions: postcssOptionsCreator(options, {
|
|
34
|
+
includePaths,
|
|
35
|
+
forCssModules: true,
|
|
36
|
+
}),
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
];
|
|
40
|
+
}
|
|
41
|
+
exports.getCommonLoadersForCssModules = getCommonLoadersForCssModules;
|
|
42
|
+
function getCommonLoadersForGlobalCss(options, includePaths) {
|
|
43
|
+
return [
|
|
44
|
+
{
|
|
45
|
+
loader: options.extractCss
|
|
46
|
+
? MiniCssExtractPlugin.loader
|
|
47
|
+
: require.resolve('style-loader'),
|
|
48
|
+
},
|
|
49
|
+
{ loader: require.resolve('css-loader'), options: { url: false } },
|
|
50
|
+
{
|
|
51
|
+
loader: require.resolve('postcss-loader'),
|
|
52
|
+
options: {
|
|
53
|
+
implementation: require('postcss'),
|
|
54
|
+
postcssOptions: postcssOptionsCreator(options, {
|
|
55
|
+
includePaths,
|
|
56
|
+
}),
|
|
57
|
+
},
|
|
58
|
+
},
|
|
59
|
+
];
|
|
60
|
+
}
|
|
61
|
+
exports.getCommonLoadersForGlobalCss = getCommonLoadersForGlobalCss;
|
|
62
|
+
function getCommonLoadersForGlobalStyle(options, includePaths) {
|
|
63
|
+
return [
|
|
64
|
+
{
|
|
65
|
+
loader: options.extractCss
|
|
66
|
+
? MiniCssExtractPlugin.loader
|
|
67
|
+
: require.resolve('style-loader'),
|
|
68
|
+
options: { esModule: true },
|
|
69
|
+
},
|
|
70
|
+
{ loader: require.resolve('css-loader'), options: { url: false } },
|
|
71
|
+
{
|
|
72
|
+
loader: require.resolve('postcss-loader'),
|
|
73
|
+
options: {
|
|
74
|
+
implementation: require('postcss'),
|
|
75
|
+
postcssOptions: postcssOptionsCreator(options, {
|
|
76
|
+
includePaths,
|
|
77
|
+
}),
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
];
|
|
81
|
+
}
|
|
82
|
+
exports.getCommonLoadersForGlobalStyle = getCommonLoadersForGlobalStyle;
|
|
83
|
+
function postcssOptionsCreator(options, { includePaths, forCssModules = false, }) {
|
|
84
|
+
const hashFormat = (0, hash_format_1.getOutputHashFormat)(options.outputHashing);
|
|
85
|
+
// PostCSS options depend on the webpack loader, but we need to set the `config` path as a string due to this check:
|
|
86
|
+
// https://github.com/webpack-contrib/postcss-loader/blob/0d342b1/src/utils.js#L36
|
|
87
|
+
const postcssOptions = (loader) => ({
|
|
88
|
+
map: options.sourceMap &&
|
|
89
|
+
options.sourceMap !== 'hidden' && {
|
|
90
|
+
inline: true,
|
|
91
|
+
annotation: false,
|
|
92
|
+
},
|
|
93
|
+
plugins: [
|
|
94
|
+
postcssImports({
|
|
95
|
+
addModulesDirectories: includePaths,
|
|
96
|
+
resolve: (url) => (url.startsWith('~') ? url.slice(1) : url),
|
|
97
|
+
}),
|
|
98
|
+
...(forCssModules
|
|
99
|
+
? []
|
|
100
|
+
: [
|
|
101
|
+
(0, postcss_cli_resources_1.PostcssCliResources)({
|
|
102
|
+
baseHref: options.baseHref,
|
|
103
|
+
deployUrl: options.deployUrl,
|
|
104
|
+
loader,
|
|
105
|
+
filename: `[name]${hashFormat.file}.[ext]`,
|
|
106
|
+
}),
|
|
107
|
+
autoprefixer(),
|
|
108
|
+
]),
|
|
109
|
+
],
|
|
110
|
+
});
|
|
111
|
+
// If a path to postcssConfig is passed in, set it for app and all libs, otherwise
|
|
112
|
+
// use automatic detection.
|
|
113
|
+
if (typeof options.postcssConfig === 'string') {
|
|
114
|
+
postcssOptions.config = path.join(options.root, options.postcssConfig);
|
|
115
|
+
}
|
|
116
|
+
return postcssOptions;
|
|
117
|
+
}
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
import { ProjectGraph } from '@nx/devkit';
|
|
2
|
+
import { AssetGlob } from '@nx/js/src/utils/assets/assets';
|
|
3
|
+
export interface AssetGlobPattern {
|
|
4
|
+
glob: string;
|
|
5
|
+
input: string;
|
|
6
|
+
output: string;
|
|
7
|
+
ignore?: string[];
|
|
8
|
+
}
|
|
9
|
+
export interface ExtraEntryPointClass {
|
|
10
|
+
bundleName?: string;
|
|
11
|
+
inject?: boolean;
|
|
12
|
+
input: string;
|
|
13
|
+
lazy?: boolean;
|
|
14
|
+
}
|
|
15
|
+
export interface FileReplacement {
|
|
16
|
+
replace: string;
|
|
17
|
+
with: string;
|
|
18
|
+
}
|
|
19
|
+
export interface AdditionalEntryPoint {
|
|
20
|
+
entryName: string;
|
|
21
|
+
entryPath: string;
|
|
22
|
+
}
|
|
23
|
+
export interface TransformerPlugin {
|
|
24
|
+
name: string;
|
|
25
|
+
options: Record<string, unknown>;
|
|
26
|
+
}
|
|
27
|
+
export type TransformerEntry = string | TransformerPlugin;
|
|
28
|
+
export interface OptimizationOptions {
|
|
29
|
+
scripts: boolean;
|
|
30
|
+
styles: boolean;
|
|
31
|
+
}
|
|
32
|
+
export interface NxWebpackPluginOptions {
|
|
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
|
+
*/
|
|
44
|
+
additionalEntryPoints?: AdditionalEntryPoint[];
|
|
45
|
+
/**
|
|
46
|
+
* Assets to be copied over to the output path.
|
|
47
|
+
*/
|
|
48
|
+
assets?: Array<AssetGlob | string>;
|
|
49
|
+
/**
|
|
50
|
+
* Babel configuration file if compiler is babel.
|
|
51
|
+
*/
|
|
52
|
+
babelConfig?: string;
|
|
53
|
+
/**
|
|
54
|
+
* If true, Babel will look for a babel.config.json up the directory tree.
|
|
55
|
+
*/
|
|
56
|
+
babelUpwardRootMode?: boolean;
|
|
57
|
+
/**
|
|
58
|
+
* Set <base href> for the resulting index.html.
|
|
59
|
+
*/
|
|
60
|
+
baseHref?: string;
|
|
61
|
+
commonChunk?: boolean;
|
|
62
|
+
/**
|
|
63
|
+
* The compiler to use. Default is `babel` and requires a `.babelrc` file.
|
|
64
|
+
*/
|
|
65
|
+
compiler?: 'babel' | 'swc' | 'tsc';
|
|
66
|
+
/**
|
|
67
|
+
* Set `crossorigin` attribute on the `script` and `link` tags.
|
|
68
|
+
*/
|
|
69
|
+
crossOrigin?: 'none' | 'anonymous' | 'use-credentials';
|
|
70
|
+
/**
|
|
71
|
+
* Delete the output path before building.
|
|
72
|
+
*/
|
|
73
|
+
deleteOutputPath?: boolean;
|
|
74
|
+
/**
|
|
75
|
+
* The deploy path for the application. e.g. `/my-app/`
|
|
76
|
+
*/
|
|
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
|
+
*/
|
|
84
|
+
externalDependencies?: 'all' | 'none' | string[];
|
|
85
|
+
/**
|
|
86
|
+
* Extract CSS as an external file. Default is `true`.
|
|
87
|
+
*/
|
|
88
|
+
extractCss?: boolean;
|
|
89
|
+
/**
|
|
90
|
+
* Extract licenses from 3rd party modules and add them to the output.
|
|
91
|
+
*/
|
|
92
|
+
extractLicenses?: boolean;
|
|
93
|
+
/**
|
|
94
|
+
* Replace files at build time. e.g. `[{ "replace": "src/a.dev.ts", "with": "src/a.prod.ts" }]`
|
|
95
|
+
*/
|
|
96
|
+
fileReplacements?: FileReplacement[];
|
|
97
|
+
/**
|
|
98
|
+
* Generate an `index.html` file if `index.html` is passed. Default is `true`
|
|
99
|
+
*/
|
|
100
|
+
generateIndexHtml?: boolean;
|
|
101
|
+
/**
|
|
102
|
+
* Generate a `package.json` file for the bundle. Useful for Node applications.
|
|
103
|
+
*/
|
|
104
|
+
generatePackageJson?: boolean;
|
|
105
|
+
/**
|
|
106
|
+
* Path to the `index.html`.
|
|
107
|
+
*/
|
|
108
|
+
index?: string;
|
|
109
|
+
/**
|
|
110
|
+
* Set the memory limit for the type-checking process. Default is `2048`.
|
|
111
|
+
*/
|
|
112
|
+
memoryLimit?: number;
|
|
113
|
+
/**
|
|
114
|
+
* Use the source file name in output chunks. Useful for development or for Node.
|
|
115
|
+
*/
|
|
116
|
+
namedChunks?: boolean;
|
|
117
|
+
/**
|
|
118
|
+
* Optimize the bundle using Terser.
|
|
119
|
+
*/
|
|
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
|
+
*/
|
|
124
|
+
outputFileName?: string;
|
|
125
|
+
/**
|
|
126
|
+
* Use file hashes in the output filenames. Recommended for production web applications.
|
|
127
|
+
*/
|
|
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
|
+
*/
|
|
136
|
+
poll?: number;
|
|
137
|
+
/**
|
|
138
|
+
* The polyfill file to use. Useful for supporting legacy browsers. e.g. `src/polyfills.ts`
|
|
139
|
+
*/
|
|
140
|
+
polyfills?: string;
|
|
141
|
+
/**
|
|
142
|
+
* Manually set the PostCSS configuration file. By default, PostCSS will look for `postcss.config.js` in the directory.
|
|
143
|
+
*/
|
|
144
|
+
postcssConfig?: string;
|
|
145
|
+
/**
|
|
146
|
+
* Display build progress in the terminal.
|
|
147
|
+
*/
|
|
148
|
+
progress?: boolean;
|
|
149
|
+
/**
|
|
150
|
+
* Add an additional chunk for the Webpack runtime. Defaults to `true` when `target === 'web'`.
|
|
151
|
+
*/
|
|
152
|
+
runtimeChunk?: boolean;
|
|
153
|
+
/**
|
|
154
|
+
* External scripts that will be included before the main application entry.
|
|
155
|
+
*/
|
|
156
|
+
scripts?: Array<ExtraEntryPointClass | string>;
|
|
157
|
+
/**
|
|
158
|
+
* Skip type checking. Default is `false`.
|
|
159
|
+
*/
|
|
160
|
+
skipTypeChecking?: boolean;
|
|
161
|
+
/**
|
|
162
|
+
* Generate source maps.
|
|
163
|
+
*/
|
|
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
|
+
*/
|
|
168
|
+
ssr?: boolean;
|
|
169
|
+
/**
|
|
170
|
+
* Generate a `stats.json` file which can be analyzed using tools such as `webpack-bundle-analyzer`.
|
|
171
|
+
*/
|
|
172
|
+
statsJson?: boolean;
|
|
173
|
+
/**
|
|
174
|
+
* Options for the style preprocessor. e.g. `{ "includePaths": [] }` for SASS.
|
|
175
|
+
*/
|
|
176
|
+
stylePreprocessorOptions?: any;
|
|
177
|
+
/**
|
|
178
|
+
* External stylesheets that will be included with the application.
|
|
179
|
+
*/
|
|
180
|
+
styles?: Array<ExtraEntryPointClass | string>;
|
|
181
|
+
/**
|
|
182
|
+
* Enables the use of subresource integrity validation.
|
|
183
|
+
*/
|
|
184
|
+
subresourceIntegrity?: boolean;
|
|
185
|
+
/**
|
|
186
|
+
* Override the `target` option in webpack configuration. This setting is not recommended and exists for backwards compatibility.
|
|
187
|
+
*/
|
|
188
|
+
target?: string | string[];
|
|
189
|
+
/**
|
|
190
|
+
* List of TypeScript Compiler Transformers Plugins.
|
|
191
|
+
*/
|
|
192
|
+
transformers?: TransformerEntry[];
|
|
193
|
+
/**
|
|
194
|
+
* Generate a separate vendor chunk for 3rd party packages.
|
|
195
|
+
*/
|
|
196
|
+
vendorChunk?: boolean;
|
|
197
|
+
/**
|
|
198
|
+
* Log additional information for debugging purposes.
|
|
199
|
+
*/
|
|
200
|
+
verbose?: boolean;
|
|
201
|
+
/**
|
|
202
|
+
* Watch for file changes.
|
|
203
|
+
*/
|
|
204
|
+
watch?: boolean;
|
|
205
|
+
}
|
|
206
|
+
export interface NormalizedNxWebpackPluginOptions extends NxWebpackPluginOptions {
|
|
207
|
+
projectName: string;
|
|
208
|
+
root: string;
|
|
209
|
+
projectRoot: string;
|
|
210
|
+
sourceRoot: string;
|
|
211
|
+
configurationName: string;
|
|
212
|
+
targetName: string;
|
|
213
|
+
projectGraph: ProjectGraph;
|
|
214
|
+
outputFileName: string;
|
|
215
|
+
assets: AssetGlobPattern[];
|
|
216
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Compiler } from 'webpack';
|
|
2
|
+
import { NxWebpackPluginOptions } from './nx-webpack-plugin-options';
|
|
3
|
+
/**
|
|
4
|
+
* This plugin provides features to build Node and Web applications.
|
|
5
|
+
* - TS support (including tsconfig paths)
|
|
6
|
+
* - Different compiler options
|
|
7
|
+
* - Assets handling
|
|
8
|
+
* - Stylesheets handling
|
|
9
|
+
* - index.html and package.json generation
|
|
10
|
+
*
|
|
11
|
+
* Web-only features, such as stylesheets and images, are only supported when `target` is 'web' or 'webworker'.
|
|
12
|
+
*/
|
|
13
|
+
export declare class NxWebpackPlugin {
|
|
14
|
+
private readonly options;
|
|
15
|
+
constructor(options?: NxWebpackPluginOptions);
|
|
16
|
+
apply(compiler: Compiler): void;
|
|
17
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NxWebpackPlugin = void 0;
|
|
4
|
+
const normalize_options_1 = require("./lib/normalize-options");
|
|
5
|
+
const fs_1 = require("../../utils/fs");
|
|
6
|
+
const apply_base_config_1 = require("./lib/apply-base-config");
|
|
7
|
+
const apply_web_config_1 = require("./lib/apply-web-config");
|
|
8
|
+
/**
|
|
9
|
+
* This plugin provides features to build Node and Web applications.
|
|
10
|
+
* - TS support (including tsconfig paths)
|
|
11
|
+
* - Different compiler options
|
|
12
|
+
* - Assets handling
|
|
13
|
+
* - Stylesheets handling
|
|
14
|
+
* - index.html and package.json generation
|
|
15
|
+
*
|
|
16
|
+
* Web-only features, such as stylesheets and images, are only supported when `target` is 'web' or 'webworker'.
|
|
17
|
+
*/
|
|
18
|
+
class NxWebpackPlugin {
|
|
19
|
+
constructor(options = {}) {
|
|
20
|
+
// If we're building inferred targets, skip normalizing build options.
|
|
21
|
+
if (!global.NX_GRAPH_CREATION) {
|
|
22
|
+
this.options = (0, normalize_options_1.normalizeOptions)(options);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
apply(compiler) {
|
|
26
|
+
// Defaults to 'web' if not specified to match Webpack's default.
|
|
27
|
+
const target = this.options.target ?? compiler.options.target ?? 'web';
|
|
28
|
+
this.options.outputPath ??= compiler.options.output?.path;
|
|
29
|
+
if (typeof target === 'string') {
|
|
30
|
+
this.options.target = target;
|
|
31
|
+
}
|
|
32
|
+
(0, apply_base_config_1.applyBaseConfig)(this.options, compiler.options, {
|
|
33
|
+
useNormalizedEntry: true,
|
|
34
|
+
});
|
|
35
|
+
if (compiler.options.target) {
|
|
36
|
+
this.options.target = compiler.options.target;
|
|
37
|
+
}
|
|
38
|
+
if (this.options.target === 'web' || this.options.target === 'webworker') {
|
|
39
|
+
(0, apply_web_config_1.applyWebConfig)(this.options, compiler.options, {
|
|
40
|
+
useNormalizedEntry: true,
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
if (this.options.deleteOutputPath) {
|
|
44
|
+
(0, fs_1.deleteOutputDir)(this.options.root, this.options.outputPath);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
exports.NxWebpackPlugin = NxWebpackPlugin;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { CreateDependencies, CreateNodes } from '@nx/devkit';
|
|
2
|
+
export interface WebpackPluginOptions {
|
|
3
|
+
buildTargetName?: string;
|
|
4
|
+
serveTargetName?: string;
|
|
5
|
+
serveStaticTargetName?: string;
|
|
6
|
+
previewTargetName?: string;
|
|
7
|
+
}
|
|
8
|
+
export declare const createDependencies: CreateDependencies;
|
|
9
|
+
export declare const createNodes: CreateNodes<WebpackPluginOptions>;
|