@simplysm/sd-cli 11.0.12 → 11.0.14
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/dist/build-tools/SdLinter.js +2 -2
- package/dist/build-tools/SdLinter.js.map +1 -1
- package/dist/build-tools/SdNgBundler.d.ts +2 -3
- package/dist/build-tools/SdNgBundler.js +59 -74
- package/dist/build-tools/SdNgBundler.js.map +1 -1
- package/dist/build-tools/SdNgBundlerContext.d.ts +16 -0
- package/dist/build-tools/SdNgBundlerContext.js +98 -0
- package/dist/build-tools/SdNgBundlerContext.js.map +1 -0
- package/dist/build-tools/SdTsBundler.js +4 -4
- package/dist/build-tools/SdTsBundler.js.map +1 -1
- package/dist/builders/SdCliClientBuilder.js +2 -2
- package/dist/builders/SdCliClientBuilder.js.map +1 -1
- package/dist/entry/SdCliProject.js +20 -15
- package/dist/entry/SdCliProject.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/utils/SdCliBuildResultUtil.js +3 -3
- package/dist/utils/SdCliBuildResultUtil.js.map +1 -1
- package/dist/utils/SdMemoryLoadResultCache.js +1 -5
- package/dist/utils/SdMemoryLoadResultCache.js.map +1 -1
- package/dist/utils/SdSourceFileCache.d.ts +2 -1
- package/dist/utils/SdSourceFileCache.js +7 -1
- package/dist/utils/SdSourceFileCache.js.map +1 -1
- package/package.json +11 -11
- package/src/build-tools/SdLinter.ts +2 -2
- package/src/build-tools/SdNgBundler.ts +215 -234
- package/src/build-tools/SdNgBundlerContext.ts +116 -0
- package/src/build-tools/SdTsBundler.ts +4 -4
- package/src/builders/SdCliClientBuilder.ts +2 -2
- package/src/entry/SdCliProject.ts +22 -15
- package/src/index.ts +1 -0
- package/src/utils/SdCliBuildResultUtil.ts +3 -3
- package/src/utils/SdMemoryLoadResultCache.ts +1 -5
- package/src/utils/SdSourceFileCache.ts +9 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {createCompilerPlugin} from "@angular-devkit/build-angular/src/tools/esbuild/angular/compiler-plugin";
|
|
2
2
|
import path from "path";
|
|
3
|
-
import {
|
|
4
|
-
import esbuild from "esbuild";
|
|
3
|
+
import {InitialFileRecord} from "@angular-devkit/build-angular/src/tools/esbuild/bundler-context";
|
|
4
|
+
import esbuild, {Metafile} from "esbuild";
|
|
5
5
|
import {FsUtil, PathUtil} from "@simplysm/sd-core-node";
|
|
6
6
|
import {fileURLToPath} from "url";
|
|
7
7
|
import {createVirtualModulePlugin} from "@angular-devkit/build-angular/src/tools/esbuild/virtual-module-plugin";
|
|
@@ -10,13 +10,15 @@ import {
|
|
|
10
10
|
} from "@angular-devkit/build-angular/src/tools/esbuild/sourcemap-ignorelist-plugin";
|
|
11
11
|
import nodeStdLibBrowser from "node-stdlib-browser";
|
|
12
12
|
import nodeStdLibBrowserPlugin from "node-stdlib-browser/helpers/esbuild/plugin";
|
|
13
|
-
import {
|
|
14
|
-
import {INpmConfig, ISdCliPackageBuildResult} from "../commons";
|
|
13
|
+
import {INpmConfig, ISdCliClientBuilderCordovaConfig, ISdCliPackageBuildResult} from "../commons";
|
|
15
14
|
import {copyAssets} from "@angular-devkit/build-angular/src/utils/copy-assets";
|
|
16
15
|
import {extractLicenses} from "@angular-devkit/build-angular/src/tools/esbuild/license-extractor";
|
|
17
16
|
import {augmentAppWithServiceWorkerEsbuild} from "@angular-devkit/build-angular/src/utils/service-worker";
|
|
18
17
|
import browserslist from "browserslist";
|
|
19
|
-
import {
|
|
18
|
+
import {
|
|
19
|
+
createOutputFileFromText,
|
|
20
|
+
transformSupportedBrowsersToTargets
|
|
21
|
+
} from "@angular-devkit/build-angular/src/tools/esbuild/utils";
|
|
20
22
|
import {createCssResourcePlugin} from "@angular-devkit/build-angular/src/tools/esbuild/stylesheets/css-resource-plugin";
|
|
21
23
|
import {CssStylesheetLanguage} from "@angular-devkit/build-angular/src/tools/esbuild/stylesheets/css-language";
|
|
22
24
|
import {SassStylesheetLanguage} from "@angular-devkit/build-angular/src/tools/esbuild/stylesheets/sass-language";
|
|
@@ -32,11 +34,14 @@ import {Entrypoint} from "@angular-devkit/build-angular/src/utils/index-file/aug
|
|
|
32
34
|
import {CrossOrigin} from "@angular-devkit/build-angular";
|
|
33
35
|
import {InlineCriticalCssProcessor} from "@angular-devkit/build-angular/src/utils/index-file/inline-critical-css";
|
|
34
36
|
import {SdSourceFileCache} from "../utils/SdSourceFileCache";
|
|
37
|
+
import {SdNgBundlerContext} from "./SdNgBundlerContext";
|
|
35
38
|
|
|
36
39
|
export class SdNgBundler {
|
|
37
|
-
private readonly _sourceFileCache = new SdSourceFileCache(
|
|
40
|
+
private readonly _sourceFileCache = new SdSourceFileCache(
|
|
41
|
+
path.resolve(this._opt.pkgPath, ".cache")
|
|
42
|
+
);
|
|
38
43
|
|
|
39
|
-
private _contexts:
|
|
44
|
+
private _contexts: SdNgBundlerContext[] | undefined;
|
|
40
45
|
|
|
41
46
|
private readonly _outputCache = new Map<string, string | number>();
|
|
42
47
|
|
|
@@ -49,15 +54,13 @@ export class SdNgBundler {
|
|
|
49
54
|
private readonly _pkgName: string;
|
|
50
55
|
private readonly _baseHref: string;
|
|
51
56
|
|
|
52
|
-
private _depsMap?: Map<string, Set<string>>;
|
|
53
|
-
|
|
54
57
|
public constructor(private readonly _opt: {
|
|
55
58
|
dev: boolean;
|
|
56
59
|
outputPath: string;
|
|
57
60
|
pkgPath: string;
|
|
58
61
|
builderType: string;
|
|
59
|
-
cordovaPlatforms: string[] | undefined;
|
|
60
62
|
env: Record<string, string> | undefined;
|
|
63
|
+
cordovaConfig: ISdCliClientBuilderCordovaConfig | undefined;
|
|
61
64
|
}) {
|
|
62
65
|
this._pkgNpmConf = FsUtil.readJson(path.resolve(this._opt.pkgPath, "package.json"));
|
|
63
66
|
this._mainFilePath = path.resolve(this._opt.pkgPath, "src/main.ts");
|
|
@@ -85,28 +88,10 @@ export class SdNgBundler {
|
|
|
85
88
|
}
|
|
86
89
|
|
|
87
90
|
//-- build
|
|
88
|
-
const
|
|
91
|
+
const bundlingResults = await this._contexts.mapAsync(async ctx => await ctx.bundleAsync());
|
|
92
|
+
|
|
93
|
+
const results = bundlingResults.mapMany(bundlingResult => bundlingResult.results);
|
|
89
94
|
|
|
90
|
-
const results = [
|
|
91
|
-
...bundlingResult.warnings.map((warn) => ({
|
|
92
|
-
filePath: warn.location?.file !== undefined ? path.resolve(this._opt.pkgPath, warn.location.file) : undefined,
|
|
93
|
-
line: warn.location?.line,
|
|
94
|
-
char: warn.location?.column,
|
|
95
|
-
code: undefined,
|
|
96
|
-
severity: "warning",
|
|
97
|
-
message: warn.text.replace(/^(NG|TS)[0-9]+: /, ""),
|
|
98
|
-
type: "build"
|
|
99
|
-
})),
|
|
100
|
-
...bundlingResult.errors?.map((err) => ({
|
|
101
|
-
filePath: err.location?.file !== undefined ? path.resolve(this._opt.pkgPath, err.location.file) : undefined,
|
|
102
|
-
line: err.location?.line,
|
|
103
|
-
char: err.location?.column !== undefined ? err.location.column + 1 : undefined,
|
|
104
|
-
code: undefined,
|
|
105
|
-
severity: "error",
|
|
106
|
-
message: err.text.replace(/^[^:]*: /, ""),
|
|
107
|
-
type: "build"
|
|
108
|
-
})) ?? []
|
|
109
|
-
] as ISdCliPackageBuildResult[];
|
|
110
95
|
const watchFilePaths = [
|
|
111
96
|
...this._sourceFileCache.keys(),
|
|
112
97
|
...this._sourceFileCache.babelFileCache.keys(),
|
|
@@ -115,36 +100,34 @@ export class SdNgBundler {
|
|
|
115
100
|
|
|
116
101
|
let affectedSourceFilePaths = watchFilePaths.filter((item) => PathUtil.isChildPath(item, this._opt.pkgPath));
|
|
117
102
|
|
|
118
|
-
if (
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
for (const entry of Object.entries(bundlingResult.metafile.inputs)) {
|
|
125
|
-
for (const imp of entry[1].imports) {
|
|
126
|
-
const deps = this._depsMap.getOrCreate(path.resolve(this._opt.pkgPath, imp.path), new Set<string>());
|
|
127
|
-
deps.add(path.resolve(this._opt.pkgPath, entry[0]));
|
|
103
|
+
if (this._sourceFileCache.modifiedFiles.size > 0) {
|
|
104
|
+
const depMap = new Map<string, Set<string>>();
|
|
105
|
+
for (const bundlingResult of bundlingResults) {
|
|
106
|
+
for (const [k, v] of bundlingResult.dependencyMap) {
|
|
107
|
+
const currSet = depMap.getOrCreate(k, new Set<string>());
|
|
108
|
+
currSet.adds(...v);
|
|
128
109
|
}
|
|
129
110
|
}
|
|
130
|
-
|
|
111
|
+
for (const [k, v] of this._sourceFileCache.loadResultCache.fileDependencies) {
|
|
112
|
+
const currSet = depMap.getOrCreate(k, new Set<string>());
|
|
113
|
+
currSet.adds(...Array.from(v).map((item) => item.startsWith("file:") ? fileURLToPath(item) : undefined).filterExists());
|
|
114
|
+
}
|
|
131
115
|
|
|
132
|
-
|
|
133
|
-
|
|
116
|
+
const searchAffectedFiles = (filePath: string, prev?: Set<string>): Set<string> => {
|
|
117
|
+
const result = new Set<string>(prev);
|
|
134
118
|
|
|
135
|
-
|
|
136
|
-
|
|
119
|
+
const importerPaths = depMap.get(filePath);
|
|
120
|
+
if (!importerPaths) return result;
|
|
137
121
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
122
|
+
for (const importerPath of importerPaths) {
|
|
123
|
+
if (result.has(importerPath)) continue;
|
|
124
|
+
result.adds(importerPath);
|
|
125
|
+
result.adds(...searchAffectedFiles(importerPath, result));
|
|
126
|
+
}
|
|
143
127
|
|
|
144
|
-
|
|
145
|
-
|
|
128
|
+
return result;
|
|
129
|
+
};
|
|
146
130
|
|
|
147
|
-
if (this._sourceFileCache.modifiedFiles.size > 0) {
|
|
148
131
|
const affectedFilePathSet = new Set<string>();
|
|
149
132
|
for (const modFile of this._sourceFileCache.modifiedFiles) {
|
|
150
133
|
affectedFilePathSet.add(path.resolve(modFile));
|
|
@@ -153,16 +136,26 @@ export class SdNgBundler {
|
|
|
153
136
|
affectedSourceFilePaths = Array.from(affectedFilePathSet.values()).filter((item) => PathUtil.isChildPath(item, this._opt.pkgPath));
|
|
154
137
|
}
|
|
155
138
|
|
|
156
|
-
if (bundlingResult.errors) {
|
|
157
|
-
return {
|
|
158
|
-
filePaths: watchFilePaths,
|
|
159
|
-
affectedFilePaths: affectedSourceFilePaths,
|
|
160
|
-
results
|
|
161
|
-
};
|
|
162
|
-
}
|
|
163
139
|
|
|
164
|
-
const executionResult = new ExecutionResult(this._contexts, this._sourceFileCache);
|
|
165
|
-
executionResult.outputFiles.push(...bundlingResult.outputFiles)
|
|
140
|
+
/*const executionResult = new ExecutionResult(this._contexts, this._sourceFileCache);
|
|
141
|
+
executionResult.outputFiles.push(...bundlingResult.outputFiles);*/
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
const outputFiles = bundlingResults.mapMany(item => item.outputFiles ?? []);
|
|
145
|
+
const initialFiles = new Map<string, InitialFileRecord>();
|
|
146
|
+
const metafile: {
|
|
147
|
+
inputs: Metafile["inputs"],
|
|
148
|
+
outputs: Metafile["outputs"]
|
|
149
|
+
} = {
|
|
150
|
+
inputs: {},
|
|
151
|
+
outputs: {}
|
|
152
|
+
};
|
|
153
|
+
for (const bundlingResult of bundlingResults) {
|
|
154
|
+
bundlingResult.initialFiles.forEach((v, k) => initialFiles.set(k, v));
|
|
155
|
+
metafile.inputs = {...metafile.inputs, ...bundlingResult.metafile?.inputs};
|
|
156
|
+
metafile.outputs = {...metafile.outputs, ...bundlingResult.metafile?.outputs};
|
|
157
|
+
}
|
|
158
|
+
const assetFiles: { source: string; destination: string }[] = [];
|
|
166
159
|
|
|
167
160
|
//-- Check commonjs
|
|
168
161
|
// if (!this._opt.dev) {
|
|
@@ -181,10 +174,8 @@ export class SdNgBundler {
|
|
|
181
174
|
// }
|
|
182
175
|
|
|
183
176
|
//-- index
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
bundlingResult.initialFiles
|
|
187
|
-
);
|
|
177
|
+
|
|
178
|
+
const genIndexHtmlResult = await this._genIndexHtmlAsync(outputFiles, initialFiles);
|
|
188
179
|
for (const warning of genIndexHtmlResult.warnings) {
|
|
189
180
|
results.push({
|
|
190
181
|
filePath: undefined,
|
|
@@ -192,7 +183,7 @@ export class SdNgBundler {
|
|
|
192
183
|
char: undefined,
|
|
193
184
|
code: undefined,
|
|
194
185
|
severity: "warning",
|
|
195
|
-
message: warning
|
|
186
|
+
message: `(gen-index) ${warning}`,
|
|
196
187
|
type: "build",
|
|
197
188
|
});
|
|
198
189
|
}
|
|
@@ -203,29 +194,26 @@ export class SdNgBundler {
|
|
|
203
194
|
char: undefined,
|
|
204
195
|
code: undefined,
|
|
205
196
|
severity: "error",
|
|
206
|
-
message: error
|
|
197
|
+
message: `(gen-index) ${error}`,
|
|
207
198
|
type: "build",
|
|
208
199
|
});
|
|
209
200
|
}
|
|
210
|
-
|
|
201
|
+
outputFiles.push(createOutputFileFromText("index.html", genIndexHtmlResult.content));
|
|
211
202
|
|
|
212
203
|
//-- copy assets
|
|
213
|
-
|
|
204
|
+
assetFiles.push(...(await this._copyAssetsAsync()));
|
|
214
205
|
|
|
215
206
|
//-- extract 3rdpartylicenses
|
|
216
207
|
if (!this._opt.dev) {
|
|
217
|
-
|
|
208
|
+
outputFiles.push(createOutputFileFromText('3rdpartylicenses.txt', await extractLicenses(metafile, this._opt.pkgPath)));
|
|
218
209
|
}
|
|
219
210
|
|
|
220
211
|
//-- service worker
|
|
221
212
|
if (FsUtil.exists(this._swConfFilePath)) {
|
|
222
213
|
try {
|
|
223
|
-
const serviceWorkerResult = await this._genServiceWorkerAsync(
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
);
|
|
227
|
-
executionResult.addOutputFile('ngsw.json', serviceWorkerResult.manifest);
|
|
228
|
-
executionResult.assetFiles.push(...serviceWorkerResult.assetFiles);
|
|
214
|
+
const serviceWorkerResult = await this._genServiceWorkerAsync(outputFiles, assetFiles);
|
|
215
|
+
outputFiles.push(createOutputFileFromText('ngsw.json', serviceWorkerResult.manifest));
|
|
216
|
+
assetFiles.push(...serviceWorkerResult.assetFiles);
|
|
229
217
|
}
|
|
230
218
|
catch (err) {
|
|
231
219
|
results.push({
|
|
@@ -234,14 +222,14 @@ export class SdNgBundler {
|
|
|
234
222
|
char: undefined,
|
|
235
223
|
code: undefined,
|
|
236
224
|
severity: "error",
|
|
237
|
-
message: err.toString()
|
|
225
|
+
message: `(gen-sw) ${err.toString()}`,
|
|
238
226
|
type: "build",
|
|
239
227
|
});
|
|
240
228
|
}
|
|
241
229
|
}
|
|
242
230
|
|
|
243
231
|
//-- write
|
|
244
|
-
for (const outputFile of
|
|
232
|
+
for (const outputFile of outputFiles) {
|
|
245
233
|
const distFilePath = path.resolve(this._opt.outputPath, outputFile.path);
|
|
246
234
|
|
|
247
235
|
const prev = this._outputCache.get(distFilePath);
|
|
@@ -250,7 +238,7 @@ export class SdNgBundler {
|
|
|
250
238
|
this._outputCache.set(distFilePath, Buffer.from(outputFile.contents).toString("base64"));
|
|
251
239
|
}
|
|
252
240
|
}
|
|
253
|
-
for (const assetFile of
|
|
241
|
+
for (const assetFile of assetFiles) {
|
|
254
242
|
const prev = this._outputCache.get(assetFile.source);
|
|
255
243
|
const curr = FsUtil.lstat(assetFile.source).mtime.getTime();
|
|
256
244
|
if (prev !== curr) {
|
|
@@ -361,7 +349,7 @@ export class SdNgBundler {
|
|
|
361
349
|
{input: 'src', glob: 'favicon.ico', output: ''},
|
|
362
350
|
{input: 'src', glob: 'manifest.webmanifest', output: ''},
|
|
363
351
|
{input: 'src/assets', glob: '**/*', output: 'assets'},
|
|
364
|
-
...this._opt.dev && this._opt.
|
|
352
|
+
...this._opt.dev && this._opt.builderType === "cordova" ? Object.keys(this._opt.cordovaConfig?.platform ?? {browser: {}}).mapMany((platform) => [
|
|
365
353
|
{
|
|
366
354
|
input: `.cordova/platforms/${platform}/platform_www/plugins`,
|
|
367
355
|
glob: '**/*',
|
|
@@ -408,122 +396,120 @@ export class SdNgBundler {
|
|
|
408
396
|
);
|
|
409
397
|
}
|
|
410
398
|
|
|
411
|
-
private async _getAppContextAsync(): Promise<
|
|
412
|
-
return new
|
|
413
|
-
this._opt.pkgPath,
|
|
414
|
-
true,
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
}
|
|
523
|
-
);
|
|
399
|
+
private async _getAppContextAsync(): Promise<SdNgBundlerContext> {
|
|
400
|
+
return new SdNgBundlerContext(this._opt.pkgPath, {
|
|
401
|
+
absWorkingDir: this._opt.pkgPath,
|
|
402
|
+
bundle: true,
|
|
403
|
+
keepNames: true,
|
|
404
|
+
format: 'esm',
|
|
405
|
+
assetNames: 'media/[name]',
|
|
406
|
+
conditions: ['es2020', 'es2015', 'module'],
|
|
407
|
+
resolveExtensions: ['.ts', '.tsx', '.mjs', '.js'],
|
|
408
|
+
metafile: true,
|
|
409
|
+
legalComments: this._opt.dev ? 'eof' : 'none',
|
|
410
|
+
logLevel: 'silent',
|
|
411
|
+
minifyIdentifiers: !this._opt.dev,
|
|
412
|
+
minifySyntax: !this._opt.dev,
|
|
413
|
+
minifyWhitespace: !this._opt.dev,
|
|
414
|
+
pure: ['forwardRef'],
|
|
415
|
+
outdir: this._opt.pkgPath,
|
|
416
|
+
outExtension: undefined,
|
|
417
|
+
sourcemap: this._opt.dev,
|
|
418
|
+
splitting: true,
|
|
419
|
+
chunkNames: 'chunk-[hash]',
|
|
420
|
+
tsconfig: this._tsConfigFilePath,
|
|
421
|
+
external: [
|
|
422
|
+
...this._opt.cordovaConfig?.plugins ?? []
|
|
423
|
+
],
|
|
424
|
+
write: false,
|
|
425
|
+
preserveSymlinks: false,
|
|
426
|
+
define: {
|
|
427
|
+
...!this._opt.dev ? {ngDevMode: 'false'} : {},
|
|
428
|
+
ngJitMode: 'false',
|
|
429
|
+
global: 'global',
|
|
430
|
+
process: 'process',
|
|
431
|
+
Buffer: 'Buffer',
|
|
432
|
+
'process.env.SD_VERSION': JSON.stringify(this._pkgNpmConf.version),
|
|
433
|
+
"process.env.NODE_ENV": JSON.stringify(this._opt.dev ? "development" : "production"),
|
|
434
|
+
...this._opt.env ? Object.keys(this._opt.env).toObject(
|
|
435
|
+
key => `process.env.${key}`,
|
|
436
|
+
key => JSON.stringify(this._opt.env![key])
|
|
437
|
+
) : {}
|
|
438
|
+
},
|
|
439
|
+
platform: 'browser',
|
|
440
|
+
mainFields: ['es2020', 'es2015', 'browser', 'module', 'main'],
|
|
441
|
+
entryNames: '[name]',
|
|
442
|
+
entryPoints: {
|
|
443
|
+
main: this._mainFilePath,
|
|
444
|
+
polyfills: 'angular:polyfills',
|
|
445
|
+
...this._opt.builderType === "cordova" ? {
|
|
446
|
+
"cordova-entry": path.resolve(path.dirname(fileURLToPath(import.meta.url)), `../../lib/cordova-entry.js`)
|
|
447
|
+
} : {}
|
|
448
|
+
},
|
|
449
|
+
target: this._browserTarget,
|
|
450
|
+
supported: {'async-await': false, 'object-rest-spread': false},
|
|
451
|
+
loader: {
|
|
452
|
+
".png": "file",
|
|
453
|
+
".jpeg": "file",
|
|
454
|
+
".jpg": "file",
|
|
455
|
+
".jfif": "file",
|
|
456
|
+
".gif": "file",
|
|
457
|
+
".svg": "file",
|
|
458
|
+
".woff": "file",
|
|
459
|
+
".woff2": "file",
|
|
460
|
+
".ttf": "file",
|
|
461
|
+
".eot": "file",
|
|
462
|
+
".ico": "file",
|
|
463
|
+
".otf": "file",
|
|
464
|
+
".csv": "file",
|
|
465
|
+
".xlsx": "file",
|
|
466
|
+
".xls": "file",
|
|
467
|
+
".pptx": "file",
|
|
468
|
+
".ppt": "file",
|
|
469
|
+
".docx": "file",
|
|
470
|
+
".doc": "file",
|
|
471
|
+
".zip": "file",
|
|
472
|
+
".pfx": "file",
|
|
473
|
+
".pkl": "file"
|
|
474
|
+
},
|
|
475
|
+
inject: [PathUtil.posix(fileURLToPath(await import.meta.resolve!("node-stdlib-browser/helpers/esbuild/shim")))],
|
|
476
|
+
plugins: [
|
|
477
|
+
createVirtualModulePlugin({
|
|
478
|
+
namespace: "angular:polyfills",
|
|
479
|
+
loadContent: () => ({
|
|
480
|
+
contents: `import "./src/polyfills.ts";`,
|
|
481
|
+
loader: 'js',
|
|
482
|
+
resolveDir: this._opt.pkgPath
|
|
483
|
+
})
|
|
484
|
+
}) as esbuild.Plugin,
|
|
485
|
+
createSourcemapIgnorelistPlugin(),
|
|
486
|
+
createCompilerPlugin({
|
|
487
|
+
sourcemap: this._opt.dev,
|
|
488
|
+
thirdPartySourcemaps: false,
|
|
489
|
+
tsconfig: this._tsConfigFilePath,
|
|
490
|
+
jit: false,
|
|
491
|
+
advancedOptimizations: true,
|
|
492
|
+
fileReplacements: undefined,
|
|
493
|
+
sourceFileCache: this._sourceFileCache,
|
|
494
|
+
loadResultCache: this._sourceFileCache.loadResultCache
|
|
495
|
+
}, {
|
|
496
|
+
workspaceRoot: this._opt.pkgPath,
|
|
497
|
+
optimization: !this._opt.dev,
|
|
498
|
+
sourcemap: this._opt.dev ? 'inline' : false,
|
|
499
|
+
outputNames: {bundles: '[name]', media: 'media/[name]'},
|
|
500
|
+
includePaths: [],
|
|
501
|
+
externalDependencies: [],
|
|
502
|
+
target: this._browserTarget,
|
|
503
|
+
inlineStyleLanguage: 'scss',
|
|
504
|
+
preserveSymlinks: false,
|
|
505
|
+
tailwindConfiguration: undefined
|
|
506
|
+
}) as esbuild.Plugin,
|
|
507
|
+
nodeStdLibBrowserPlugin(nodeStdLibBrowser)
|
|
508
|
+
]
|
|
509
|
+
});
|
|
524
510
|
}
|
|
525
511
|
|
|
526
|
-
private _getStyleContext():
|
|
512
|
+
private _getStyleContext(): SdNgBundlerContext {
|
|
527
513
|
const browserTarget = transformSupportedBrowsersToTargets(browserslist("defaults and fully supports es6-module"));
|
|
528
514
|
|
|
529
515
|
const pluginFactory = new StylesheetPluginFactory(
|
|
@@ -534,44 +520,39 @@ export class SdNgBundler {
|
|
|
534
520
|
this._sourceFileCache.loadResultCache,
|
|
535
521
|
);
|
|
536
522
|
|
|
537
|
-
return new
|
|
538
|
-
this._opt.pkgPath,
|
|
539
|
-
true,
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
contents: `@import 'src/styles.scss';`,
|
|
565
|
-
loader: 'css',
|
|
566
|
-
resolveDir: this._opt.pkgPath
|
|
567
|
-
}),
|
|
523
|
+
return new SdNgBundlerContext(this._opt.pkgPath, {
|
|
524
|
+
absWorkingDir: this._opt.pkgPath,
|
|
525
|
+
bundle: true,
|
|
526
|
+
entryNames: '[name]',
|
|
527
|
+
assetNames: 'media/[name]',
|
|
528
|
+
logLevel: 'silent',
|
|
529
|
+
minify: !this._opt.dev,
|
|
530
|
+
metafile: true,
|
|
531
|
+
sourcemap: this._opt.dev,
|
|
532
|
+
outdir: this._opt.pkgPath,
|
|
533
|
+
write: false,
|
|
534
|
+
platform: 'browser',
|
|
535
|
+
target: browserTarget,
|
|
536
|
+
preserveSymlinks: false,
|
|
537
|
+
external: [],
|
|
538
|
+
conditions: ['style', 'sass'],
|
|
539
|
+
mainFields: ['style', 'sass'],
|
|
540
|
+
legalComments: !this._opt.dev ? "none" : "eof",
|
|
541
|
+
entryPoints: {styles: 'angular:styles/global;styles'},
|
|
542
|
+
plugins: [
|
|
543
|
+
createVirtualModulePlugin({
|
|
544
|
+
namespace: "angular:styles/global",
|
|
545
|
+
transformPath: (currPath) => currPath.split(';', 2)[1],
|
|
546
|
+
loadContent: () => ({
|
|
547
|
+
contents: `@import 'src/styles.scss';`,
|
|
548
|
+
loader: 'css',
|
|
549
|
+
resolveDir: this._opt.pkgPath
|
|
568
550
|
}),
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
);
|
|
551
|
+
}),
|
|
552
|
+
pluginFactory.create(SassStylesheetLanguage),
|
|
553
|
+
pluginFactory.create(CssStylesheetLanguage),
|
|
554
|
+
createCssResourcePlugin(this._sourceFileCache.loadResultCache),
|
|
555
|
+
],
|
|
556
|
+
});
|
|
576
557
|
}
|
|
577
558
|
}
|