@simplysm/sd-cli 12.5.13 → 12.5.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/SdNgBundler.js +124 -111
- package/dist/build-tools/SdNgBundler.js.map +1 -1
- package/dist/build-tools/SdTsCompiler.js +20 -15
- package/dist/build-tools/SdTsCompiler.js.map +1 -1
- package/package.json +7 -7
- package/src/build-tools/SdNgBundler.ts +184 -161
- package/src/build-tools/SdTsCompiler.ts +23 -15
|
@@ -1,41 +1,41 @@
|
|
|
1
1
|
import path from "path";
|
|
2
|
-
import esbuild, {Metafile} from "esbuild";
|
|
3
|
-
import {FsUtil, Logger, PathUtil} from "@simplysm/sd-core-node";
|
|
4
|
-
import {fileURLToPath} from "url";
|
|
2
|
+
import esbuild, { Metafile } from "esbuild";
|
|
3
|
+
import { FsUtil, Logger, PathUtil } from "@simplysm/sd-core-node";
|
|
4
|
+
import { fileURLToPath } from "url";
|
|
5
5
|
import nodeStdLibBrowser from "node-stdlib-browser";
|
|
6
6
|
import nodeStdLibBrowserPlugin from "node-stdlib-browser/helpers/esbuild/plugin";
|
|
7
|
-
import {INpmConfig, ISdCliClientBuilderCordovaConfig, ISdCliPackageBuildResult} from "../commons";
|
|
7
|
+
import { INpmConfig, ISdCliClientBuilderCordovaConfig, ISdCliPackageBuildResult } from "../commons";
|
|
8
8
|
import browserslist from "browserslist";
|
|
9
|
-
import {SdNgBundlerContext} from "./SdNgBundlerContext";
|
|
10
|
-
import {INgPluginResultCache, sdNgPlugin} from "../bundle-plugins/sdNgPlugin";
|
|
9
|
+
import { SdNgBundlerContext } from "./SdNgBundlerContext";
|
|
10
|
+
import { INgPluginResultCache, sdNgPlugin } from "../bundle-plugins/sdNgPlugin";
|
|
11
11
|
import ts from "typescript";
|
|
12
|
-
import {MemoryLoadResultCache} from "@angular/build/src/tools/esbuild/load-result-cache";
|
|
12
|
+
import { MemoryLoadResultCache } from "@angular/build/src/tools/esbuild/load-result-cache";
|
|
13
13
|
import {
|
|
14
14
|
convertOutputFile,
|
|
15
15
|
createOutputFile,
|
|
16
|
-
transformSupportedBrowsersToTargets
|
|
16
|
+
transformSupportedBrowsersToTargets,
|
|
17
17
|
} from "@angular/build/src/tools/esbuild/utils";
|
|
18
18
|
import {
|
|
19
19
|
BuildOutputFile,
|
|
20
20
|
BuildOutputFileType,
|
|
21
|
-
InitialFileRecord
|
|
21
|
+
InitialFileRecord,
|
|
22
22
|
} from "@angular/build/src/tools/esbuild/bundler-context";
|
|
23
|
-
import {extractLicenses} from "@angular/build/src/tools/esbuild/license-extractor";
|
|
23
|
+
import { extractLicenses } from "@angular/build/src/tools/esbuild/license-extractor";
|
|
24
24
|
import {
|
|
25
25
|
HintMode,
|
|
26
26
|
IndexHtmlGenerator,
|
|
27
|
-
IndexHtmlProcessResult
|
|
27
|
+
IndexHtmlProcessResult,
|
|
28
28
|
} from "@angular/build/src/utils/index-file/index-html-generator";
|
|
29
|
-
import {Entrypoint} from "@angular/build/src/utils/index-file/augment-index-html";
|
|
30
|
-
import {CrossOrigin} from "@angular/build/src/builders/application/schema";
|
|
31
|
-
import {InlineCriticalCssProcessor} from "@angular/build/src/utils/index-file/inline-critical-css";
|
|
32
|
-
import {augmentAppWithServiceWorkerEsbuild} from "@angular/build/src/utils/service-worker";
|
|
33
|
-
import {createSourcemapIgnorelistPlugin} from "@angular/build/src/tools/esbuild/sourcemap-ignorelist-plugin";
|
|
34
|
-
import {StylesheetPluginFactory} from "@angular/build/src/tools/esbuild/stylesheets/stylesheet-plugin-factory";
|
|
35
|
-
import {SassStylesheetLanguage} from "@angular/build/src/tools/esbuild/stylesheets/sass-language";
|
|
36
|
-
import {CssStylesheetLanguage} from "@angular/build/src/tools/esbuild/stylesheets/css-language";
|
|
37
|
-
import {createCssResourcePlugin} from "@angular/build/src/tools/esbuild/stylesheets/css-resource-plugin";
|
|
38
|
-
import {resolveAssets} from "@angular/build/src/utils/resolve-assets";
|
|
29
|
+
import { Entrypoint } from "@angular/build/src/utils/index-file/augment-index-html";
|
|
30
|
+
import { CrossOrigin } from "@angular/build/src/builders/application/schema";
|
|
31
|
+
import { InlineCriticalCssProcessor } from "@angular/build/src/utils/index-file/inline-critical-css";
|
|
32
|
+
import { augmentAppWithServiceWorkerEsbuild } from "@angular/build/src/utils/service-worker";
|
|
33
|
+
import { createSourcemapIgnorelistPlugin } from "@angular/build/src/tools/esbuild/sourcemap-ignorelist-plugin";
|
|
34
|
+
import { StylesheetPluginFactory } from "@angular/build/src/tools/esbuild/stylesheets/stylesheet-plugin-factory";
|
|
35
|
+
import { SassStylesheetLanguage } from "@angular/build/src/tools/esbuild/stylesheets/sass-language";
|
|
36
|
+
import { CssStylesheetLanguage } from "@angular/build/src/tools/esbuild/stylesheets/css-language";
|
|
37
|
+
import { createCssResourcePlugin } from "@angular/build/src/tools/esbuild/stylesheets/css-resource-plugin";
|
|
38
|
+
import { resolveAssets } from "@angular/build/src/utils/resolve-assets";
|
|
39
39
|
|
|
40
40
|
export class SdNgBundler {
|
|
41
41
|
readonly #logger = Logger.get(["simplysm", "sd-cli", "SdNgBundler"]);
|
|
@@ -47,7 +47,7 @@ export class SdNgBundler {
|
|
|
47
47
|
readonly #modifiedFileSet = new Set<string>();
|
|
48
48
|
readonly #ngResultCache: INgPluginResultCache = {
|
|
49
49
|
affectedFileSet: new Set<string>(),
|
|
50
|
-
watchFileSet: new Set<string>()
|
|
50
|
+
watchFileSet: new Set<string>(),
|
|
51
51
|
};
|
|
52
52
|
readonly #styleLoadResultCache = new MemoryLoadResultCache();
|
|
53
53
|
|
|
@@ -77,7 +77,8 @@ export class SdNgBundler {
|
|
|
77
77
|
this.#browserTarget = transformSupportedBrowsersToTargets(browserslist(["Chrome > 78"]));
|
|
78
78
|
this.#indexHtmlFilePath = path.resolve(opt.pkgPath, "src/index.html");
|
|
79
79
|
this.#pkgName = path.basename(opt.pkgPath);
|
|
80
|
-
this.#baseHref =
|
|
80
|
+
this.#baseHref =
|
|
81
|
+
opt.builderType === "web" ? `/${this.#pkgName}/` : opt.dev ? `/${this.#pkgName}/${opt.builderType}/` : ``;
|
|
81
82
|
}
|
|
82
83
|
|
|
83
84
|
public markForChanges(filePaths: string[]): void {
|
|
@@ -90,9 +91,9 @@ export class SdNgBundler {
|
|
|
90
91
|
|
|
91
92
|
public async bundleAsync(): Promise<{
|
|
92
93
|
program?: ts.Program;
|
|
93
|
-
watchFileSet: Set<string
|
|
94
|
-
affectedFileSet: Set<string
|
|
95
|
-
results: ISdCliPackageBuildResult[]
|
|
94
|
+
watchFileSet: Set<string>;
|
|
95
|
+
affectedFileSet: Set<string>;
|
|
96
|
+
results: ISdCliPackageBuildResult[];
|
|
96
97
|
}> {
|
|
97
98
|
this.#debug(`get contexts...`);
|
|
98
99
|
|
|
@@ -100,9 +101,7 @@ export class SdNgBundler {
|
|
|
100
101
|
this.#contexts = [
|
|
101
102
|
this._getAppContext(),
|
|
102
103
|
this._getStyleContext(),
|
|
103
|
-
...this.#opt.builderType === "electron" ? [
|
|
104
|
-
this._getElectronMainContext()
|
|
105
|
-
] : []
|
|
104
|
+
...(this.#opt.builderType === "electron" ? [this._getElectronMainContext()] : []),
|
|
106
105
|
];
|
|
107
106
|
}
|
|
108
107
|
|
|
@@ -111,23 +110,25 @@ export class SdNgBundler {
|
|
|
111
110
|
const bundlingResults = await this.#contexts.mapAsync(async (ctx, i) => await ctx.bundleAsync());
|
|
112
111
|
|
|
113
112
|
//-- results
|
|
114
|
-
const results = bundlingResults.mapMany(bundlingResult => bundlingResult.results);
|
|
113
|
+
const results = bundlingResults.mapMany((bundlingResult) => bundlingResult.results);
|
|
115
114
|
|
|
116
115
|
this.#debug(`convert result...`);
|
|
117
116
|
|
|
118
|
-
const outputFiles: BuildOutputFile[] = bundlingResults.mapMany(
|
|
117
|
+
const outputFiles: BuildOutputFile[] = bundlingResults.mapMany(
|
|
118
|
+
(item) => item.outputFiles?.map((file) => convertOutputFile(file, BuildOutputFileType.Root)) ?? [],
|
|
119
|
+
);
|
|
119
120
|
const initialFiles = new Map<string, InitialFileRecord>();
|
|
120
121
|
const metafile: {
|
|
121
|
-
inputs: Metafile["inputs"]
|
|
122
|
-
outputs: Metafile["outputs"]
|
|
122
|
+
inputs: Metafile["inputs"];
|
|
123
|
+
outputs: Metafile["outputs"];
|
|
123
124
|
} = {
|
|
124
125
|
inputs: {},
|
|
125
|
-
outputs: {}
|
|
126
|
+
outputs: {},
|
|
126
127
|
};
|
|
127
128
|
for (const bundlingResult of bundlingResults) {
|
|
128
129
|
bundlingResult.initialFiles.forEach((v, k) => initialFiles.set(k, v));
|
|
129
|
-
metafile.inputs = {...metafile.inputs, ...bundlingResult.metafile?.inputs};
|
|
130
|
-
metafile.outputs = {...metafile.outputs, ...bundlingResult.metafile?.outputs};
|
|
130
|
+
metafile.inputs = { ...metafile.inputs, ...bundlingResult.metafile?.inputs };
|
|
131
|
+
metafile.outputs = { ...metafile.outputs, ...bundlingResult.metafile?.outputs };
|
|
131
132
|
}
|
|
132
133
|
const assetFiles: { source: string; destination: string }[] = [];
|
|
133
134
|
|
|
@@ -168,7 +169,13 @@ export class SdNgBundler {
|
|
|
168
169
|
|
|
169
170
|
//-- extract 3rdpartylicenses
|
|
170
171
|
if (!this.#opt.dev) {
|
|
171
|
-
outputFiles.push(
|
|
172
|
+
outputFiles.push(
|
|
173
|
+
createOutputFile(
|
|
174
|
+
"3rdpartylicenses.txt",
|
|
175
|
+
await extractLicenses(metafile, this.#opt.pkgPath),
|
|
176
|
+
BuildOutputFileType.Root,
|
|
177
|
+
),
|
|
178
|
+
);
|
|
172
179
|
}
|
|
173
180
|
|
|
174
181
|
//-- service worker
|
|
@@ -177,10 +184,9 @@ export class SdNgBundler {
|
|
|
177
184
|
|
|
178
185
|
try {
|
|
179
186
|
const serviceWorkerResult = await this._genServiceWorkerAsync(outputFiles, assetFiles);
|
|
180
|
-
outputFiles.push(createOutputFile(
|
|
187
|
+
outputFiles.push(createOutputFile("ngsw.json", serviceWorkerResult.manifest, BuildOutputFileType.Root));
|
|
181
188
|
assetFiles.push(...serviceWorkerResult.assetFiles);
|
|
182
|
-
}
|
|
183
|
-
catch (err) {
|
|
189
|
+
} catch (err) {
|
|
184
190
|
results.push({
|
|
185
191
|
filePath: undefined,
|
|
186
192
|
line: undefined,
|
|
@@ -220,10 +226,10 @@ export class SdNgBundler {
|
|
|
220
226
|
watchFileSet: new Set([
|
|
221
227
|
...this.#ngResultCache.watchFileSet!,
|
|
222
228
|
...this.#styleLoadResultCache.watchFiles,
|
|
223
|
-
this.#indexHtmlFilePath
|
|
229
|
+
this.#indexHtmlFilePath,
|
|
224
230
|
]),
|
|
225
231
|
affectedFileSet: this.#ngResultCache.affectedFileSet!,
|
|
226
|
-
results
|
|
232
|
+
results,
|
|
227
233
|
};
|
|
228
234
|
}
|
|
229
235
|
|
|
@@ -244,40 +250,38 @@ export class SdNgBundler {
|
|
|
244
250
|
const indexHtmlGenerator = new IndexHtmlGenerator({
|
|
245
251
|
indexPath: this.#indexHtmlFilePath,
|
|
246
252
|
entrypoints: [
|
|
247
|
-
[
|
|
248
|
-
[
|
|
249
|
-
[
|
|
250
|
-
[
|
|
251
|
-
[
|
|
252
|
-
...this.#opt.builderType === "cordova" ? [
|
|
253
|
-
["cordova-entry", true] as Entrypoint
|
|
254
|
-
] : []
|
|
253
|
+
["runtime", true],
|
|
254
|
+
["polyfills", true],
|
|
255
|
+
["styles", false],
|
|
256
|
+
["vendor", true],
|
|
257
|
+
["main", true],
|
|
258
|
+
...(this.#opt.builderType === "cordova" ? [["cordova-entry", true] as Entrypoint] : []),
|
|
255
259
|
],
|
|
256
260
|
optimization: {
|
|
257
261
|
scripts: !this.#opt.dev,
|
|
258
|
-
fonts: {inline: !this.#opt.dev},
|
|
262
|
+
fonts: { inline: !this.#opt.dev },
|
|
259
263
|
styles: {
|
|
260
264
|
minify: !this.#opt.dev,
|
|
261
|
-
inlineCritical: false
|
|
265
|
+
inlineCritical: false,
|
|
262
266
|
},
|
|
263
267
|
},
|
|
264
268
|
crossOrigin: CrossOrigin.None,
|
|
265
269
|
});
|
|
266
270
|
indexHtmlGenerator.readAsset = readAsset;
|
|
267
271
|
|
|
268
|
-
const hints: { url: string; mode: HintMode; as?: string
|
|
272
|
+
const hints: { url: string; mode: HintMode; as?: string }[] = [];
|
|
269
273
|
if (!this.#opt.dev) {
|
|
270
274
|
for (const [key, value] of initialFiles) {
|
|
271
275
|
if (value.entrypoint) {
|
|
272
276
|
continue;
|
|
273
277
|
}
|
|
274
278
|
|
|
275
|
-
if (value.type ===
|
|
276
|
-
hints.push({url: key, mode:
|
|
279
|
+
if (value.type === "script") {
|
|
280
|
+
hints.push({ url: key, mode: "modulepreload" as const });
|
|
277
281
|
}
|
|
278
282
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
279
|
-
else if (value.type ===
|
|
280
|
-
hints.push({url: key, mode:
|
|
283
|
+
else if (value.type === "style") {
|
|
284
|
+
hints.push({ url: key, mode: "preload" as const, as: "style" });
|
|
281
285
|
}
|
|
282
286
|
}
|
|
283
287
|
}
|
|
@@ -287,7 +291,7 @@ export class SdNgBundler {
|
|
|
287
291
|
lang: undefined,
|
|
288
292
|
outputPath: "/",
|
|
289
293
|
files: [...initialFiles].map(([file, record]) => ({
|
|
290
|
-
name: record.name ??
|
|
294
|
+
name: record.name ?? "",
|
|
291
295
|
file,
|
|
292
296
|
extension: path.extname(file),
|
|
293
297
|
})),
|
|
@@ -296,58 +300,63 @@ export class SdNgBundler {
|
|
|
296
300
|
|
|
297
301
|
if (this.#opt.dev) {
|
|
298
302
|
return transformResult;
|
|
299
|
-
}
|
|
300
|
-
else {
|
|
303
|
+
} else {
|
|
301
304
|
const inlineCriticalCssProcessor = new InlineCriticalCssProcessor({
|
|
302
305
|
minify: false,
|
|
303
306
|
readAsset,
|
|
304
307
|
});
|
|
305
|
-
const {content, errors, warnings} = await inlineCriticalCssProcessor.process(
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
);
|
|
308
|
+
const { content, errors, warnings } = await inlineCriticalCssProcessor.process(transformResult.csrContent, {
|
|
309
|
+
outputPath: "/",
|
|
310
|
+
});
|
|
309
311
|
|
|
310
312
|
return {
|
|
311
313
|
warnings: [...transformResult.warnings, ...warnings],
|
|
312
314
|
errors: [...transformResult.errors, ...errors],
|
|
313
|
-
csrContent: content
|
|
315
|
+
csrContent: content,
|
|
314
316
|
};
|
|
315
317
|
}
|
|
316
318
|
}
|
|
317
319
|
|
|
318
320
|
//TODO: index.html 파일에 manifest.json 정보 추가? manifest.webmanifest ? PWA?
|
|
319
|
-
private async _copyAssetsAsync(): Promise<
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
{
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
321
|
+
private async _copyAssetsAsync(): Promise<
|
|
322
|
+
{
|
|
323
|
+
source: string;
|
|
324
|
+
destination: string;
|
|
325
|
+
}[]
|
|
326
|
+
> {
|
|
327
|
+
return await resolveAssets(
|
|
328
|
+
[
|
|
329
|
+
{ input: "src", glob: "favicon.ico", output: "" },
|
|
330
|
+
{ input: "src", glob: "manifest.webmanifest", output: "" },
|
|
331
|
+
{ input: "src", glob: "manifest.json", output: "" },
|
|
332
|
+
{ input: "src/assets", glob: "**/*", output: "assets" },
|
|
333
|
+
...(this.#opt.dev && this.#opt.builderType === "cordova"
|
|
334
|
+
? Object.keys(this.#opt.cordovaConfig?.platform ?? { browser: {} }).mapMany((platform) => [
|
|
335
|
+
{
|
|
336
|
+
input: `.cordova/platforms/${platform}/platform_www/plugins`,
|
|
337
|
+
glob: "**/*",
|
|
338
|
+
output: `cordova-${platform}/plugins`,
|
|
339
|
+
},
|
|
340
|
+
{
|
|
341
|
+
input: `.cordova/platforms/${platform}/platform_www`,
|
|
342
|
+
glob: "cordova.js",
|
|
343
|
+
output: `cordova-${platform}`,
|
|
344
|
+
},
|
|
345
|
+
{
|
|
346
|
+
input: `.cordova/platforms/${platform}/platform_www`,
|
|
347
|
+
glob: "cordova_plugins.js",
|
|
348
|
+
output: `cordova-${platform}`,
|
|
349
|
+
},
|
|
350
|
+
{
|
|
351
|
+
input: `.cordova/platforms/${platform}/www`,
|
|
352
|
+
glob: "config.xml",
|
|
353
|
+
output: `cordova-${platform}`,
|
|
354
|
+
},
|
|
355
|
+
])
|
|
356
|
+
: []),
|
|
357
|
+
],
|
|
358
|
+
this.#opt.pkgPath,
|
|
359
|
+
);
|
|
351
360
|
}
|
|
352
361
|
|
|
353
362
|
private async _genServiceWorkerAsync(
|
|
@@ -355,7 +364,7 @@ export class SdNgBundler {
|
|
|
355
364
|
assetFiles: {
|
|
356
365
|
source: string;
|
|
357
366
|
destination: string;
|
|
358
|
-
}[]
|
|
367
|
+
}[],
|
|
359
368
|
): Promise<{
|
|
360
369
|
manifest: string;
|
|
361
370
|
assetFiles: {
|
|
@@ -369,61 +378,70 @@ export class SdNgBundler {
|
|
|
369
378
|
this.#baseHref,
|
|
370
379
|
"index.html",
|
|
371
380
|
outputFiles,
|
|
372
|
-
assetFiles
|
|
381
|
+
assetFiles,
|
|
373
382
|
);
|
|
374
383
|
}
|
|
375
384
|
|
|
376
385
|
private _getAppContext() {
|
|
386
|
+
const workerEntries = FsUtil.glob(path.resolve(this.#opt.pkgPath, "src/workers/*.ts")).toObject(
|
|
387
|
+
(p) => "worker/" + path.basename(p, path.extname(p)),
|
|
388
|
+
);
|
|
389
|
+
|
|
377
390
|
return new SdNgBundlerContext(this.#opt.pkgPath, {
|
|
378
391
|
absWorkingDir: this.#opt.pkgPath,
|
|
379
392
|
bundle: true,
|
|
380
393
|
keepNames: true,
|
|
381
|
-
format:
|
|
382
|
-
assetNames:
|
|
383
|
-
conditions: [
|
|
394
|
+
format: "esm",
|
|
395
|
+
assetNames: "media/[name]",
|
|
396
|
+
conditions: ["es2020", "es2015", "module"],
|
|
384
397
|
resolveExtensions: [".js", ".mjs", ".cjs", ".ts"],
|
|
385
398
|
metafile: true,
|
|
386
|
-
legalComments: this.#opt.dev ?
|
|
387
|
-
logLevel:
|
|
399
|
+
legalComments: this.#opt.dev ? "eof" : "none",
|
|
400
|
+
logLevel: "silent",
|
|
388
401
|
minifyIdentifiers: !this.#opt.dev,
|
|
389
402
|
minifySyntax: !this.#opt.dev,
|
|
390
403
|
minifyWhitespace: !this.#opt.dev,
|
|
391
|
-
pure: [
|
|
404
|
+
pure: ["forwardRef"],
|
|
392
405
|
outdir: this.#opt.pkgPath,
|
|
393
406
|
outExtension: undefined,
|
|
394
407
|
sourcemap: true, //this.#opt.dev,
|
|
395
408
|
splitting: true,
|
|
396
|
-
chunkNames:
|
|
409
|
+
chunkNames: "[name]-[hash]",
|
|
397
410
|
tsconfig: this.#tsConfigFilePath,
|
|
398
411
|
write: false,
|
|
399
412
|
preserveSymlinks: false,
|
|
400
413
|
define: {
|
|
401
|
-
|
|
402
|
-
ngJitMode:
|
|
403
|
-
global:
|
|
404
|
-
process:
|
|
405
|
-
Buffer:
|
|
406
|
-
|
|
414
|
+
...(!this.#opt.dev ? { ngDevMode: "false" } : {}),
|
|
415
|
+
"ngJitMode": "false",
|
|
416
|
+
"global": "global",
|
|
417
|
+
"process": "process",
|
|
418
|
+
"Buffer": "Buffer",
|
|
419
|
+
"process.env.SD_VERSION": JSON.stringify(this.#pkgNpmConf.version),
|
|
407
420
|
"process.env.NODE_ENV": JSON.stringify(this.#opt.dev ? "development" : "production"),
|
|
408
|
-
...
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
421
|
+
...(this.#opt.env
|
|
422
|
+
? Object.keys(this.#opt.env).toObject(
|
|
423
|
+
(key) => `process.env.${key}`,
|
|
424
|
+
(key) => JSON.stringify(this.#opt.env![key]),
|
|
425
|
+
)
|
|
426
|
+
: {}),
|
|
412
427
|
},
|
|
413
|
-
platform:
|
|
414
|
-
mainFields: [
|
|
415
|
-
entryNames:
|
|
428
|
+
platform: "browser",
|
|
429
|
+
mainFields: ["es2020", "es2015", "browser", "module", "main"],
|
|
430
|
+
entryNames: "[name]",
|
|
416
431
|
entryPoints: {
|
|
417
432
|
main: this.#mainFilePath,
|
|
418
433
|
// polyfills: 'angular:polyfills',
|
|
419
434
|
polyfills: path.resolve(this.#opt.pkgPath, "src/polyfills.ts"),
|
|
420
|
-
...this.#opt.builderType === "cordova"
|
|
421
|
-
|
|
422
|
-
|
|
435
|
+
...(this.#opt.builderType === "cordova"
|
|
436
|
+
? {
|
|
437
|
+
"cordova-entry": path.resolve(path.dirname(fileURLToPath(import.meta.url)), `../../lib/cordova-entry.js`),
|
|
438
|
+
}
|
|
439
|
+
: {}),
|
|
440
|
+
...workerEntries,
|
|
423
441
|
},
|
|
424
442
|
external: ["electron"],
|
|
425
443
|
target: this.#browserTarget,
|
|
426
|
-
supported: {
|
|
444
|
+
supported: { "async-await": false, "object-rest-spread": false },
|
|
427
445
|
loader: {
|
|
428
446
|
".png": "file",
|
|
429
447
|
".jpeg": "file",
|
|
@@ -449,21 +467,25 @@ export class SdNgBundler {
|
|
|
449
467
|
".pfx": "file",
|
|
450
468
|
".pkl": "file",
|
|
451
469
|
".mp3": "file",
|
|
452
|
-
".ogg": "file"
|
|
470
|
+
".ogg": "file",
|
|
453
471
|
},
|
|
454
472
|
inject: [PathUtil.posix(fileURLToPath(import.meta.resolve("node-stdlib-browser/helpers/esbuild/shim")))],
|
|
455
473
|
plugins: [
|
|
456
|
-
...this.#opt.builderType === "cordova" && this.#opt.cordovaConfig?.plugins
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
474
|
+
...(this.#opt.builderType === "cordova" && this.#opt.cordovaConfig?.plugins
|
|
475
|
+
? [
|
|
476
|
+
{
|
|
477
|
+
name: "cordova:plugin-empty",
|
|
478
|
+
setup: ({ onResolve }) => {
|
|
479
|
+
onResolve({ filter: new RegExp("(" + this.#opt.cordovaConfig!.plugins!.join("|") + ")") }, () => {
|
|
480
|
+
return {
|
|
481
|
+
path: `./cordova-empty.js`,
|
|
482
|
+
external: true,
|
|
483
|
+
};
|
|
484
|
+
});
|
|
485
|
+
},
|
|
486
|
+
},
|
|
487
|
+
]
|
|
488
|
+
: []),
|
|
467
489
|
// createVirtualModulePlugin({
|
|
468
490
|
// namespace: "angular:polyfills",
|
|
469
491
|
// loadContent: () => ({
|
|
@@ -477,7 +499,7 @@ export class SdNgBundler {
|
|
|
477
499
|
modifiedFileSet: this.#modifiedFileSet,
|
|
478
500
|
dev: this.#opt.dev,
|
|
479
501
|
pkgPath: this.#opt.pkgPath,
|
|
480
|
-
result: this.#ngResultCache
|
|
502
|
+
result: this.#ngResultCache,
|
|
481
503
|
}),
|
|
482
504
|
// createCompilerPlugin({
|
|
483
505
|
// sourcemap: this.#opt.dev,
|
|
@@ -501,7 +523,7 @@ export class SdNgBundler {
|
|
|
501
523
|
// preserveSymlinks: false,
|
|
502
524
|
// tailwindConfiguration: undefined
|
|
503
525
|
// }) as esbuild.Plugin,
|
|
504
|
-
nodeStdLibBrowserPlugin(nodeStdLibBrowser)
|
|
526
|
+
nodeStdLibBrowserPlugin(nodeStdLibBrowser),
|
|
505
527
|
// {
|
|
506
528
|
// name: "sd-load-file",
|
|
507
529
|
// setup: ({onLoad}) => {
|
|
@@ -511,7 +533,7 @@ export class SdNgBundler {
|
|
|
511
533
|
// });
|
|
512
534
|
// }
|
|
513
535
|
// }
|
|
514
|
-
]
|
|
536
|
+
],
|
|
515
537
|
});
|
|
516
538
|
}
|
|
517
539
|
|
|
@@ -519,7 +541,7 @@ export class SdNgBundler {
|
|
|
519
541
|
const pluginFactory = new StylesheetPluginFactory(
|
|
520
542
|
{
|
|
521
543
|
sourcemap: true, //this.#opt.dev,
|
|
522
|
-
includePaths: []
|
|
544
|
+
includePaths: [],
|
|
523
545
|
},
|
|
524
546
|
this.#styleLoadResultCache,
|
|
525
547
|
);
|
|
@@ -527,24 +549,24 @@ export class SdNgBundler {
|
|
|
527
549
|
return new SdNgBundlerContext(this.#opt.pkgPath, {
|
|
528
550
|
absWorkingDir: this.#opt.pkgPath,
|
|
529
551
|
bundle: true,
|
|
530
|
-
entryNames:
|
|
531
|
-
assetNames:
|
|
532
|
-
logLevel:
|
|
552
|
+
entryNames: "[name]",
|
|
553
|
+
assetNames: "media/[name]",
|
|
554
|
+
logLevel: "silent",
|
|
533
555
|
minify: !this.#opt.dev,
|
|
534
556
|
metafile: true,
|
|
535
557
|
sourcemap: true, //this.#opt.dev,
|
|
536
558
|
outdir: this.#opt.pkgPath,
|
|
537
559
|
write: false,
|
|
538
|
-
platform:
|
|
560
|
+
platform: "browser",
|
|
539
561
|
target: this.#browserTarget,
|
|
540
562
|
preserveSymlinks: false,
|
|
541
563
|
external: [],
|
|
542
|
-
conditions: [
|
|
543
|
-
mainFields: [
|
|
564
|
+
conditions: ["style", "sass"],
|
|
565
|
+
mainFields: ["style", "sass"],
|
|
544
566
|
legalComments: !this.#opt.dev ? "none" : "eof",
|
|
545
567
|
entryPoints: {
|
|
546
568
|
// styles: 'angular:styles/global;styles'
|
|
547
|
-
styles: path.resolve(this.#opt.pkgPath, "src/styles.scss")
|
|
569
|
+
styles: path.resolve(this.#opt.pkgPath, "src/styles.scss"),
|
|
548
570
|
},
|
|
549
571
|
plugins: [
|
|
550
572
|
// createVirtualModulePlugin({
|
|
@@ -567,13 +589,13 @@ export class SdNgBundler {
|
|
|
567
589
|
return new SdNgBundlerContext(this.#opt.pkgPath, {
|
|
568
590
|
absWorkingDir: this.#opt.pkgPath,
|
|
569
591
|
bundle: true,
|
|
570
|
-
entryNames:
|
|
571
|
-
assetNames:
|
|
572
|
-
conditions: [
|
|
592
|
+
entryNames: "[name]",
|
|
593
|
+
assetNames: "media/[name]",
|
|
594
|
+
conditions: ["es2020", "es2015", "module"],
|
|
573
595
|
resolveExtensions: [".js", ".mjs", ".cjs", ".ts"],
|
|
574
596
|
metafile: true,
|
|
575
|
-
legalComments: this.#opt.dev ?
|
|
576
|
-
logLevel:
|
|
597
|
+
legalComments: this.#opt.dev ? "eof" : "none",
|
|
598
|
+
logLevel: "silent",
|
|
577
599
|
minify: !this.#opt.dev,
|
|
578
600
|
outdir: this.#opt.pkgPath,
|
|
579
601
|
sourcemap: true, //this.#opt.dev,
|
|
@@ -582,22 +604,23 @@ export class SdNgBundler {
|
|
|
582
604
|
preserveSymlinks: false,
|
|
583
605
|
external: ["electron"],
|
|
584
606
|
define: {
|
|
585
|
-
|
|
586
|
-
|
|
607
|
+
...(!this.#opt.dev ? { ngDevMode: "false" } : {}),
|
|
608
|
+
"process.env.SD_VERSION": JSON.stringify(this.#pkgNpmConf.version),
|
|
587
609
|
"process.env.NODE_ENV": JSON.stringify(this.#opt.dev ? "development" : "production"),
|
|
588
|
-
...
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
610
|
+
...(this.#opt.env
|
|
611
|
+
? Object.keys(this.#opt.env).toObject(
|
|
612
|
+
(key) => `process.env.${key}`,
|
|
613
|
+
(key) => JSON.stringify(this.#opt.env![key]),
|
|
614
|
+
)
|
|
615
|
+
: {}),
|
|
592
616
|
},
|
|
593
|
-
platform:
|
|
617
|
+
platform: "node",
|
|
594
618
|
entryPoints: {
|
|
595
619
|
"electron-main": path.resolve(this.#opt.pkgPath, "src/electron-main.ts"),
|
|
596
|
-
}
|
|
620
|
+
},
|
|
597
621
|
});
|
|
598
622
|
}
|
|
599
623
|
|
|
600
|
-
|
|
601
624
|
#debug(...msg: any[]): void {
|
|
602
625
|
this.#logger.debug(`[${path.basename(this.#opt.pkgPath)}]`, ...msg);
|
|
603
626
|
}
|
|
@@ -610,4 +633,4 @@ interface IOptions {
|
|
|
610
633
|
builderType: string;
|
|
611
634
|
env: Record<string, string> | undefined;
|
|
612
635
|
cordovaConfig: ISdCliClientBuilderCordovaConfig | undefined;
|
|
613
|
-
}
|
|
636
|
+
}
|