@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,165 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PostcssCliResources = void 0;
|
|
4
|
+
const loader_utils_1 = require("loader-utils");
|
|
5
|
+
const path = require("path");
|
|
6
|
+
const url = require("node:url");
|
|
7
|
+
function wrapUrl(url) {
|
|
8
|
+
let wrappedUrl;
|
|
9
|
+
const hasSingleQuotes = url.indexOf("'") >= 0;
|
|
10
|
+
if (hasSingleQuotes) {
|
|
11
|
+
wrappedUrl = `"${url}"`;
|
|
12
|
+
}
|
|
13
|
+
else {
|
|
14
|
+
wrappedUrl = `'${url}'`;
|
|
15
|
+
}
|
|
16
|
+
return `url(${wrappedUrl})`;
|
|
17
|
+
}
|
|
18
|
+
async function resolve(file, base, resolver) {
|
|
19
|
+
try {
|
|
20
|
+
return await resolver(`./${file}`, base);
|
|
21
|
+
}
|
|
22
|
+
catch {
|
|
23
|
+
return resolver(file, base);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
module.exports.postcss = true;
|
|
27
|
+
function PostcssCliResources(options) {
|
|
28
|
+
const { deployUrl = '', baseHref = '', resourcesOutputPath = '', rebaseRootRelative = false, filename, loader, } = options;
|
|
29
|
+
const dedupeSlashes = (url) => url.replace(/\/\/+/g, '/');
|
|
30
|
+
const process = async (inputUrl, context, resourceCache) => {
|
|
31
|
+
// If root-relative, absolute or protocol relative url, leave as is
|
|
32
|
+
if (/^((?:\w+:)?\/\/|data:|chrome:|#)/.test(inputUrl)) {
|
|
33
|
+
return inputUrl;
|
|
34
|
+
}
|
|
35
|
+
if (!rebaseRootRelative && /^\//.test(inputUrl)) {
|
|
36
|
+
return inputUrl;
|
|
37
|
+
}
|
|
38
|
+
// If starts with a caret, remove and return remainder
|
|
39
|
+
// this supports bypassing asset processing
|
|
40
|
+
if (inputUrl.startsWith('^')) {
|
|
41
|
+
return inputUrl.slice(1);
|
|
42
|
+
}
|
|
43
|
+
const cacheKey = path.resolve(context, inputUrl);
|
|
44
|
+
const cachedUrl = resourceCache.get(cacheKey);
|
|
45
|
+
if (cachedUrl) {
|
|
46
|
+
return cachedUrl;
|
|
47
|
+
}
|
|
48
|
+
if (inputUrl.startsWith('~')) {
|
|
49
|
+
inputUrl = inputUrl.slice(1);
|
|
50
|
+
}
|
|
51
|
+
if (inputUrl.startsWith('/')) {
|
|
52
|
+
let outputUrl = '';
|
|
53
|
+
if (deployUrl.match(/:\/\//) || deployUrl.startsWith('/')) {
|
|
54
|
+
// If deployUrl is absolute or root relative, ignore baseHref & use deployUrl as is.
|
|
55
|
+
outputUrl = `${deployUrl.replace(/\/$/, '')}${inputUrl}`;
|
|
56
|
+
}
|
|
57
|
+
else if (baseHref.match(/:\/\//)) {
|
|
58
|
+
// If baseHref contains a scheme, include it as is.
|
|
59
|
+
outputUrl =
|
|
60
|
+
baseHref.replace(/\/$/, '') +
|
|
61
|
+
dedupeSlashes(`/${deployUrl}/${inputUrl}`);
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
// Join together base-href, deploy-url and the original URL.
|
|
65
|
+
outputUrl = dedupeSlashes(`/${baseHref}/${deployUrl}/${inputUrl}`);
|
|
66
|
+
}
|
|
67
|
+
resourceCache.set(cacheKey, outputUrl);
|
|
68
|
+
return outputUrl;
|
|
69
|
+
}
|
|
70
|
+
const { pathname, hash, search } = url.parse(inputUrl.replace(/\\/g, '/'));
|
|
71
|
+
const resolver = (file, base) => new Promise((resolve, reject) => {
|
|
72
|
+
loader.resolve(base, decodeURI(file), (err, result) => {
|
|
73
|
+
if (err) {
|
|
74
|
+
reject(err);
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
resolve(result);
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
const result = await resolve(pathname, context, resolver);
|
|
81
|
+
return new Promise((resolve, reject) => {
|
|
82
|
+
loader.fs.readFile(result, (err, content) => {
|
|
83
|
+
if (err) {
|
|
84
|
+
reject(err);
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
let outputPath = (0, loader_utils_1.interpolateName)({ resourcePath: result }, filename, { content });
|
|
88
|
+
if (resourcesOutputPath) {
|
|
89
|
+
outputPath = path.posix.join(resourcesOutputPath, outputPath);
|
|
90
|
+
}
|
|
91
|
+
loader.addDependency(result);
|
|
92
|
+
loader.emitFile(outputPath, content, undefined);
|
|
93
|
+
let outputUrl = outputPath.replace(/\\/g, '/');
|
|
94
|
+
if (hash || search) {
|
|
95
|
+
outputUrl = url.format({ pathname: outputUrl, hash, search });
|
|
96
|
+
}
|
|
97
|
+
const loaderOptions = loader.loaders[loader.loaderIndex].options;
|
|
98
|
+
if (deployUrl && loaderOptions.ident !== 'extracted') {
|
|
99
|
+
outputUrl = url.resolve(deployUrl, outputUrl);
|
|
100
|
+
}
|
|
101
|
+
resourceCache.set(cacheKey, outputUrl);
|
|
102
|
+
resolve(outputUrl);
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
};
|
|
106
|
+
return {
|
|
107
|
+
postcssPlugin: 'postcss-cli-resources',
|
|
108
|
+
Once(root) {
|
|
109
|
+
const urlDeclarations = [];
|
|
110
|
+
/**
|
|
111
|
+
* TODO: Explore if this can be rewritten using the new `Declaration()`
|
|
112
|
+
* listener added in postcss v8
|
|
113
|
+
*/
|
|
114
|
+
root.walkDecls((decl) => {
|
|
115
|
+
if (decl.value && decl.value.includes('url')) {
|
|
116
|
+
urlDeclarations.push(decl);
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
if (urlDeclarations.length === 0) {
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
const resourceCache = new Map();
|
|
123
|
+
return Promise.all(urlDeclarations.map(async (decl) => {
|
|
124
|
+
const value = decl.value;
|
|
125
|
+
const urlRegex = /url(?:\(\s*(['"]?))(.*?)(?:\1\s*\))/g;
|
|
126
|
+
const segments = [];
|
|
127
|
+
let match;
|
|
128
|
+
let lastIndex = 0;
|
|
129
|
+
let modified = false;
|
|
130
|
+
// We want to load it relative to the file that imports
|
|
131
|
+
const inputFile = decl.source && decl.source.input.file;
|
|
132
|
+
const context = (inputFile && path.dirname(inputFile)) || loader.context;
|
|
133
|
+
while ((match = urlRegex.exec(value))) {
|
|
134
|
+
const originalUrl = match[2];
|
|
135
|
+
let processedUrl;
|
|
136
|
+
try {
|
|
137
|
+
processedUrl = await process(originalUrl, context, resourceCache);
|
|
138
|
+
}
|
|
139
|
+
catch (err) {
|
|
140
|
+
loader.emitError(decl.error(err.message, { word: originalUrl }));
|
|
141
|
+
continue;
|
|
142
|
+
}
|
|
143
|
+
if (lastIndex < match.index) {
|
|
144
|
+
segments.push(value.slice(lastIndex, match.index));
|
|
145
|
+
}
|
|
146
|
+
if (!processedUrl || originalUrl === processedUrl) {
|
|
147
|
+
segments.push(match[0]);
|
|
148
|
+
}
|
|
149
|
+
else {
|
|
150
|
+
segments.push(wrapUrl(processedUrl));
|
|
151
|
+
modified = true;
|
|
152
|
+
}
|
|
153
|
+
lastIndex = match.index + match[0].length;
|
|
154
|
+
}
|
|
155
|
+
if (lastIndex < value.length) {
|
|
156
|
+
segments.push(value.slice(lastIndex));
|
|
157
|
+
}
|
|
158
|
+
if (modified) {
|
|
159
|
+
decl.value = segments.join('');
|
|
160
|
+
}
|
|
161
|
+
}));
|
|
162
|
+
},
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
exports.PostcssCliResources = PostcssCliResources;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import * as webpack from 'webpack';
|
|
2
|
+
export interface ScriptsWebpackPluginOptions {
|
|
3
|
+
name: string;
|
|
4
|
+
sourceMap: boolean;
|
|
5
|
+
scripts: string[];
|
|
6
|
+
filename: string;
|
|
7
|
+
basePath: string;
|
|
8
|
+
}
|
|
9
|
+
export declare class ScriptsWebpackPlugin {
|
|
10
|
+
private options;
|
|
11
|
+
private _lastBuildTime?;
|
|
12
|
+
private _cachedOutput?;
|
|
13
|
+
constructor(options?: Partial<ScriptsWebpackPluginOptions>);
|
|
14
|
+
shouldSkip(compilation: any, scripts: string[]): boolean;
|
|
15
|
+
private _insertOutput;
|
|
16
|
+
apply(compiler: webpack.Compiler): void;
|
|
17
|
+
}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ScriptsWebpackPlugin = void 0;
|
|
4
|
+
const loader_utils_1 = require("loader-utils");
|
|
5
|
+
const path = require("path");
|
|
6
|
+
const webpack = require("webpack");
|
|
7
|
+
const Chunk = require('webpack/lib/Chunk');
|
|
8
|
+
const EntryPoint = require('webpack/lib/Entrypoint');
|
|
9
|
+
function addDependencies(compilation, scripts) {
|
|
10
|
+
for (const script of scripts) {
|
|
11
|
+
compilation.fileDependencies.add(script);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
function hook(compiler, action) {
|
|
15
|
+
compiler.hooks.thisCompilation.tap('scripts-webpack-plugin', (compilation) => {
|
|
16
|
+
compilation.hooks.additionalAssets.tapAsync('scripts-webpack-plugin', (callback) => action(compilation, callback));
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
class ScriptsWebpackPlugin {
|
|
20
|
+
constructor(options = {}) {
|
|
21
|
+
this.options = options;
|
|
22
|
+
}
|
|
23
|
+
shouldSkip(compilation, scripts) {
|
|
24
|
+
if (this._lastBuildTime == undefined) {
|
|
25
|
+
this._lastBuildTime = Date.now();
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
for (let i = 0; i < scripts.length; i++) {
|
|
29
|
+
const scriptTime = compilation.fileTimestamps?.get(scripts[i]);
|
|
30
|
+
if (!scriptTime || scriptTime > this._lastBuildTime) {
|
|
31
|
+
this._lastBuildTime = Date.now();
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
37
|
+
_insertOutput(compilation, { filename, source }, cached = false) {
|
|
38
|
+
const chunk = new Chunk(this.options.name);
|
|
39
|
+
chunk.rendered = !cached;
|
|
40
|
+
chunk.id = this.options.name;
|
|
41
|
+
chunk.ids = [chunk.id];
|
|
42
|
+
if (chunk.files instanceof Set) {
|
|
43
|
+
chunk.files.add(filename);
|
|
44
|
+
}
|
|
45
|
+
else if (chunk.files instanceof Array) {
|
|
46
|
+
chunk.files.push(filename);
|
|
47
|
+
}
|
|
48
|
+
const entrypoint = new EntryPoint(this.options.name);
|
|
49
|
+
entrypoint.pushChunk(chunk);
|
|
50
|
+
chunk.addGroup(entrypoint);
|
|
51
|
+
compilation.entrypoints.set(this.options.name, entrypoint);
|
|
52
|
+
if (compilation.chunks instanceof Set) {
|
|
53
|
+
compilation.chunks.add(chunk);
|
|
54
|
+
}
|
|
55
|
+
else if (compilation.chunks instanceof Array) {
|
|
56
|
+
compilation.chunks.push(chunk);
|
|
57
|
+
}
|
|
58
|
+
compilation.assets[filename] = source;
|
|
59
|
+
}
|
|
60
|
+
apply(compiler) {
|
|
61
|
+
if (!this.options.scripts || this.options.scripts.length === 0) {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
const scripts = this.options.scripts
|
|
65
|
+
.filter((script) => !!script)
|
|
66
|
+
.map((script) => path.resolve(this.options.basePath || '', script));
|
|
67
|
+
hook(compiler, (compilation, callback) => {
|
|
68
|
+
if (this.shouldSkip(compilation, scripts)) {
|
|
69
|
+
if (this._cachedOutput) {
|
|
70
|
+
this._insertOutput(compilation, this._cachedOutput, true);
|
|
71
|
+
}
|
|
72
|
+
addDependencies(compilation, scripts);
|
|
73
|
+
callback();
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
const sourceGetters = scripts.map((fullPath) => {
|
|
77
|
+
return new Promise((resolve, reject) => {
|
|
78
|
+
compilation.inputFileSystem.readFile(fullPath, (err, data) => {
|
|
79
|
+
if (err) {
|
|
80
|
+
reject(err);
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
const content = data.toString();
|
|
84
|
+
let source;
|
|
85
|
+
if (this.options.sourceMap) {
|
|
86
|
+
// TODO: Look for source map file (for '.min' scripts, etc.)
|
|
87
|
+
let adjustedPath = fullPath;
|
|
88
|
+
if (this.options.basePath) {
|
|
89
|
+
adjustedPath = path.relative(this.options.basePath, fullPath);
|
|
90
|
+
}
|
|
91
|
+
source = new webpack.sources.OriginalSource(content, adjustedPath);
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
source = new webpack.sources.RawSource(content);
|
|
95
|
+
}
|
|
96
|
+
resolve(source);
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
Promise.all(sourceGetters)
|
|
101
|
+
.then((sources) => {
|
|
102
|
+
const concatSource = new webpack.sources.ConcatSource();
|
|
103
|
+
sources.forEach((source) => {
|
|
104
|
+
concatSource.add(source);
|
|
105
|
+
concatSource.add('\n;');
|
|
106
|
+
});
|
|
107
|
+
const combinedSource = new webpack.sources.CachedSource(concatSource);
|
|
108
|
+
const filename = (0, loader_utils_1.interpolateName)({ resourcePath: 'scripts.js' }, this.options.filename, { content: combinedSource.source() });
|
|
109
|
+
const output = { filename, source: combinedSource };
|
|
110
|
+
this._insertOutput(compilation, output);
|
|
111
|
+
this._cachedOutput = output;
|
|
112
|
+
addDependencies(compilation, scripts);
|
|
113
|
+
callback();
|
|
114
|
+
})
|
|
115
|
+
.catch((err) => callback(err));
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
exports.ScriptsWebpackPlugin = ScriptsWebpackPlugin;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Configuration } from 'webpack';
|
|
2
|
+
/**
|
|
3
|
+
* Reads the webpack options from a give webpack configuration. The configuration can be:
|
|
4
|
+
* 1. A standard config object
|
|
5
|
+
* 2. A standard function that returns a config object (webpack.js.org/configuration/configuration-types/#exporting-a-function)
|
|
6
|
+
* 3. A Nx-specific composable function that takes Nx context, webpack config, and returns the config object.
|
|
7
|
+
*
|
|
8
|
+
* @param webpackConfig
|
|
9
|
+
*/
|
|
10
|
+
export declare function readWebpackOptions(webpackConfig: unknown): Promise<Configuration>;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.readWebpackOptions = void 0;
|
|
4
|
+
const devkit_1 = require("@nx/devkit");
|
|
5
|
+
const config_1 = require("../config");
|
|
6
|
+
/**
|
|
7
|
+
* Reads the webpack options from a give webpack configuration. The configuration can be:
|
|
8
|
+
* 1. A standard config object
|
|
9
|
+
* 2. A standard function that returns a config object (webpack.js.org/configuration/configuration-types/#exporting-a-function)
|
|
10
|
+
* 3. A Nx-specific composable function that takes Nx context, webpack config, and returns the config object.
|
|
11
|
+
*
|
|
12
|
+
* @param webpackConfig
|
|
13
|
+
*/
|
|
14
|
+
async function readWebpackOptions(webpackConfig) {
|
|
15
|
+
let config;
|
|
16
|
+
if ((0, config_1.isNxWebpackComposablePlugin)(webpackConfig)) {
|
|
17
|
+
config = await webpackConfig({}, {
|
|
18
|
+
// These values are only used during build-time, so passing stubs here just to read out
|
|
19
|
+
// the returned config object.
|
|
20
|
+
options: {
|
|
21
|
+
root: devkit_1.workspaceRoot,
|
|
22
|
+
projectRoot: '',
|
|
23
|
+
sourceRoot: '',
|
|
24
|
+
outputFileName: undefined,
|
|
25
|
+
outputPath: undefined,
|
|
26
|
+
assets: undefined,
|
|
27
|
+
},
|
|
28
|
+
context: { root: devkit_1.workspaceRoot, cwd: undefined, isVerbose: false },
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
else if (typeof webpackConfig === 'function') {
|
|
32
|
+
config = await webpackConfig({
|
|
33
|
+
production: true, // we want the production build options
|
|
34
|
+
}, {});
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
config = webpackConfig;
|
|
38
|
+
}
|
|
39
|
+
return config;
|
|
40
|
+
}
|
|
41
|
+
exports.readWebpackOptions = readWebpackOptions;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resolveUserDefinedWebpackConfig = void 0;
|
|
4
|
+
const internal_1 = require("@nx/js/src/internal");
|
|
5
|
+
function resolveUserDefinedWebpackConfig(path, tsConfig,
|
|
6
|
+
/** Skip require cache and return latest content */
|
|
7
|
+
reload = false) {
|
|
8
|
+
if (reload) {
|
|
9
|
+
// Clear cache if the path is in the cache
|
|
10
|
+
if (require.cache[path]) {
|
|
11
|
+
// Clear all entries because config may import other modules
|
|
12
|
+
for (const k of Object.keys(require.cache)) {
|
|
13
|
+
delete require.cache[k];
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
// Don't transpile non-TS files. This prevents workspaces libs from being registered via tsconfig-paths.
|
|
18
|
+
// There's an issue here with Nx workspace where loading plugins from source (via tsconfig-paths) can lead to errors.
|
|
19
|
+
if (!/\.(ts|mts|cts)$/.test(path)) {
|
|
20
|
+
return require(path);
|
|
21
|
+
}
|
|
22
|
+
const cleanupTranspiler = (0, internal_1.registerTsProject)(tsConfig);
|
|
23
|
+
const maybeCustomWebpackConfig = require(path);
|
|
24
|
+
cleanupTranspiler();
|
|
25
|
+
// If the user provides a configuration in TS file
|
|
26
|
+
// then there are 3 cases for exporing an object. The first one is:
|
|
27
|
+
// `module.exports = { ... }`. And the second one is:
|
|
28
|
+
// `export default { ... }`. The ESM format is compiled into:
|
|
29
|
+
// `{ default: { ... } }`
|
|
30
|
+
// There is also a case of
|
|
31
|
+
// `{ default: { default: { ... } }`
|
|
32
|
+
const customWebpackConfig = 'default' in maybeCustomWebpackConfig
|
|
33
|
+
? 'default' in maybeCustomWebpackConfig.default
|
|
34
|
+
? maybeCustomWebpackConfig.default.default
|
|
35
|
+
: maybeCustomWebpackConfig.default
|
|
36
|
+
: maybeCustomWebpackConfig;
|
|
37
|
+
return customWebpackConfig;
|
|
38
|
+
}
|
|
39
|
+
exports.resolveUserDefinedWebpackConfig = resolveUserDefinedWebpackConfig;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { NxComposableWebpackPlugin } from './config';
|
|
2
|
+
import { NxWebpackPluginOptions } from '../plugins/nx-webpack-plugin/nx-webpack-plugin-options';
|
|
3
|
+
export type WithNxOptions = Partial<NxWebpackPluginOptions>;
|
|
4
|
+
/**
|
|
5
|
+
* @param {WithNxOptions} pluginOptions
|
|
6
|
+
* @returns {NxWebpackPlugin}
|
|
7
|
+
*/
|
|
8
|
+
export declare function withNx(pluginOptions?: WithNxOptions): NxComposableWebpackPlugin;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.withNx = void 0;
|
|
4
|
+
const apply_base_config_1 = require("../plugins/nx-webpack-plugin/lib/apply-base-config");
|
|
5
|
+
const normalize_options_1 = require("../plugins/nx-webpack-plugin/lib/normalize-options");
|
|
6
|
+
const processed = new Set();
|
|
7
|
+
/**
|
|
8
|
+
* @param {WithNxOptions} pluginOptions
|
|
9
|
+
* @returns {NxWebpackPlugin}
|
|
10
|
+
*/
|
|
11
|
+
function withNx(pluginOptions = {}) {
|
|
12
|
+
return function configure(config, { options, context }) {
|
|
13
|
+
if (processed.has(config))
|
|
14
|
+
return config;
|
|
15
|
+
(0, apply_base_config_1.applyBaseConfig)({
|
|
16
|
+
...options,
|
|
17
|
+
...pluginOptions,
|
|
18
|
+
target: options.target ?? 'web',
|
|
19
|
+
assets: options.assets
|
|
20
|
+
? options.assets
|
|
21
|
+
: pluginOptions.assets
|
|
22
|
+
? (0, normalize_options_1.normalizeAssets)(pluginOptions.assets, options.root, options.sourceRoot, options.projectRoot)
|
|
23
|
+
: [],
|
|
24
|
+
root: context.root,
|
|
25
|
+
projectName: context.projectName,
|
|
26
|
+
targetName: context.targetName,
|
|
27
|
+
configurationName: context.configurationName,
|
|
28
|
+
projectGraph: context.projectGraph,
|
|
29
|
+
}, config);
|
|
30
|
+
processed.add(config);
|
|
31
|
+
return config;
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
exports.withNx = withNx;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { NxComposableWebpackPlugin } from './config';
|
|
2
|
+
import { ExtraEntryPointClass, NormalizedWebpackExecutorOptions } from '../executors/webpack/schema';
|
|
3
|
+
export interface WithWebOptions {
|
|
4
|
+
baseHref?: string;
|
|
5
|
+
crossOrigin?: 'none' | 'anonymous' | 'use-credentials';
|
|
6
|
+
deployUrl?: string;
|
|
7
|
+
extractCss?: boolean;
|
|
8
|
+
generateIndexHtml?: boolean;
|
|
9
|
+
index?: string;
|
|
10
|
+
postcssConfig?: string;
|
|
11
|
+
scripts?: Array<ExtraEntryPointClass | string>;
|
|
12
|
+
stylePreprocessorOptions?: any;
|
|
13
|
+
styles?: Array<ExtraEntryPointClass | string>;
|
|
14
|
+
subresourceIntegrity?: boolean;
|
|
15
|
+
ssr?: boolean;
|
|
16
|
+
}
|
|
17
|
+
export type MergedOptions = Omit<NormalizedWebpackExecutorOptions, keyof WithWebOptions> & WithWebOptions;
|
|
18
|
+
/**
|
|
19
|
+
* @param {WithWebOptions} pluginOptions
|
|
20
|
+
* @returns {NxWebpackPlugin}
|
|
21
|
+
*/
|
|
22
|
+
export declare function withWeb(pluginOptions?: WithWebOptions): NxComposableWebpackPlugin;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.withWeb = void 0;
|
|
4
|
+
const apply_web_config_1 = require("../plugins/nx-webpack-plugin/lib/apply-web-config");
|
|
5
|
+
const processed = new Set();
|
|
6
|
+
/**
|
|
7
|
+
* @param {WithWebOptions} pluginOptions
|
|
8
|
+
* @returns {NxWebpackPlugin}
|
|
9
|
+
*/
|
|
10
|
+
function withWeb(pluginOptions = {}) {
|
|
11
|
+
return function configure(config, { options, context }) {
|
|
12
|
+
if (processed.has(config))
|
|
13
|
+
return config;
|
|
14
|
+
(0, apply_web_config_1.applyWebConfig)({
|
|
15
|
+
...options,
|
|
16
|
+
...pluginOptions,
|
|
17
|
+
projectName: context.projectName,
|
|
18
|
+
targetName: context.targetName,
|
|
19
|
+
configurationName: context.configurationName,
|
|
20
|
+
projectGraph: context.projectGraph,
|
|
21
|
+
}, config);
|
|
22
|
+
processed.add(config);
|
|
23
|
+
return config;
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
exports.withWeb = withWeb;
|