@simplysm/sd-cli 12.5.12 → 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 +125 -110
- 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/dist/entry/SdCliProject.js +1 -1
- package/dist/entry/SdCliProject.js.map +1 -1
- package/package.json +11 -11
- package/src/build-tools/SdNgBundler.ts +185 -160
- package/src/build-tools/SdTsCompiler.ts +23 -15
- package/src/commons.ts +11 -8
- package/src/entry/SdCliProject.ts +1 -1
|
@@ -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,56 +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
|
-
|
|
319
|
-
|
|
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
|
-
|
|
320
|
+
//TODO: index.html 파일에 manifest.json 정보 추가? manifest.webmanifest ? PWA?
|
|
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
|
+
);
|
|
349
360
|
}
|
|
350
361
|
|
|
351
362
|
private async _genServiceWorkerAsync(
|
|
@@ -353,7 +364,7 @@ export class SdNgBundler {
|
|
|
353
364
|
assetFiles: {
|
|
354
365
|
source: string;
|
|
355
366
|
destination: string;
|
|
356
|
-
}[]
|
|
367
|
+
}[],
|
|
357
368
|
): Promise<{
|
|
358
369
|
manifest: string;
|
|
359
370
|
assetFiles: {
|
|
@@ -367,61 +378,70 @@ export class SdNgBundler {
|
|
|
367
378
|
this.#baseHref,
|
|
368
379
|
"index.html",
|
|
369
380
|
outputFiles,
|
|
370
|
-
assetFiles
|
|
381
|
+
assetFiles,
|
|
371
382
|
);
|
|
372
383
|
}
|
|
373
384
|
|
|
374
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
|
+
|
|
375
390
|
return new SdNgBundlerContext(this.#opt.pkgPath, {
|
|
376
391
|
absWorkingDir: this.#opt.pkgPath,
|
|
377
392
|
bundle: true,
|
|
378
393
|
keepNames: true,
|
|
379
|
-
format:
|
|
380
|
-
assetNames:
|
|
381
|
-
conditions: [
|
|
394
|
+
format: "esm",
|
|
395
|
+
assetNames: "media/[name]",
|
|
396
|
+
conditions: ["es2020", "es2015", "module"],
|
|
382
397
|
resolveExtensions: [".js", ".mjs", ".cjs", ".ts"],
|
|
383
398
|
metafile: true,
|
|
384
|
-
legalComments: this.#opt.dev ?
|
|
385
|
-
logLevel:
|
|
399
|
+
legalComments: this.#opt.dev ? "eof" : "none",
|
|
400
|
+
logLevel: "silent",
|
|
386
401
|
minifyIdentifiers: !this.#opt.dev,
|
|
387
402
|
minifySyntax: !this.#opt.dev,
|
|
388
403
|
minifyWhitespace: !this.#opt.dev,
|
|
389
|
-
pure: [
|
|
404
|
+
pure: ["forwardRef"],
|
|
390
405
|
outdir: this.#opt.pkgPath,
|
|
391
406
|
outExtension: undefined,
|
|
392
407
|
sourcemap: true, //this.#opt.dev,
|
|
393
408
|
splitting: true,
|
|
394
|
-
chunkNames:
|
|
409
|
+
chunkNames: "[name]-[hash]",
|
|
395
410
|
tsconfig: this.#tsConfigFilePath,
|
|
396
411
|
write: false,
|
|
397
412
|
preserveSymlinks: false,
|
|
398
413
|
define: {
|
|
399
|
-
|
|
400
|
-
ngJitMode:
|
|
401
|
-
global:
|
|
402
|
-
process:
|
|
403
|
-
Buffer:
|
|
404
|
-
|
|
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),
|
|
405
420
|
"process.env.NODE_ENV": JSON.stringify(this.#opt.dev ? "development" : "production"),
|
|
406
|
-
...
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
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
|
+
: {}),
|
|
410
427
|
},
|
|
411
|
-
platform:
|
|
412
|
-
mainFields: [
|
|
413
|
-
entryNames:
|
|
428
|
+
platform: "browser",
|
|
429
|
+
mainFields: ["es2020", "es2015", "browser", "module", "main"],
|
|
430
|
+
entryNames: "[name]",
|
|
414
431
|
entryPoints: {
|
|
415
432
|
main: this.#mainFilePath,
|
|
416
433
|
// polyfills: 'angular:polyfills',
|
|
417
434
|
polyfills: path.resolve(this.#opt.pkgPath, "src/polyfills.ts"),
|
|
418
|
-
...this.#opt.builderType === "cordova"
|
|
419
|
-
|
|
420
|
-
|
|
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,
|
|
421
441
|
},
|
|
422
442
|
external: ["electron"],
|
|
423
443
|
target: this.#browserTarget,
|
|
424
|
-
supported: {
|
|
444
|
+
supported: { "async-await": false, "object-rest-spread": false },
|
|
425
445
|
loader: {
|
|
426
446
|
".png": "file",
|
|
427
447
|
".jpeg": "file",
|
|
@@ -447,21 +467,25 @@ export class SdNgBundler {
|
|
|
447
467
|
".pfx": "file",
|
|
448
468
|
".pkl": "file",
|
|
449
469
|
".mp3": "file",
|
|
450
|
-
".ogg": "file"
|
|
470
|
+
".ogg": "file",
|
|
451
471
|
},
|
|
452
472
|
inject: [PathUtil.posix(fileURLToPath(import.meta.resolve("node-stdlib-browser/helpers/esbuild/shim")))],
|
|
453
473
|
plugins: [
|
|
454
|
-
...this.#opt.builderType === "cordova" && this.#opt.cordovaConfig?.plugins
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
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
|
+
: []),
|
|
465
489
|
// createVirtualModulePlugin({
|
|
466
490
|
// namespace: "angular:polyfills",
|
|
467
491
|
// loadContent: () => ({
|
|
@@ -475,7 +499,7 @@ export class SdNgBundler {
|
|
|
475
499
|
modifiedFileSet: this.#modifiedFileSet,
|
|
476
500
|
dev: this.#opt.dev,
|
|
477
501
|
pkgPath: this.#opt.pkgPath,
|
|
478
|
-
result: this.#ngResultCache
|
|
502
|
+
result: this.#ngResultCache,
|
|
479
503
|
}),
|
|
480
504
|
// createCompilerPlugin({
|
|
481
505
|
// sourcemap: this.#opt.dev,
|
|
@@ -499,7 +523,7 @@ export class SdNgBundler {
|
|
|
499
523
|
// preserveSymlinks: false,
|
|
500
524
|
// tailwindConfiguration: undefined
|
|
501
525
|
// }) as esbuild.Plugin,
|
|
502
|
-
nodeStdLibBrowserPlugin(nodeStdLibBrowser)
|
|
526
|
+
nodeStdLibBrowserPlugin(nodeStdLibBrowser),
|
|
503
527
|
// {
|
|
504
528
|
// name: "sd-load-file",
|
|
505
529
|
// setup: ({onLoad}) => {
|
|
@@ -509,7 +533,7 @@ export class SdNgBundler {
|
|
|
509
533
|
// });
|
|
510
534
|
// }
|
|
511
535
|
// }
|
|
512
|
-
]
|
|
536
|
+
],
|
|
513
537
|
});
|
|
514
538
|
}
|
|
515
539
|
|
|
@@ -517,7 +541,7 @@ export class SdNgBundler {
|
|
|
517
541
|
const pluginFactory = new StylesheetPluginFactory(
|
|
518
542
|
{
|
|
519
543
|
sourcemap: true, //this.#opt.dev,
|
|
520
|
-
includePaths: []
|
|
544
|
+
includePaths: [],
|
|
521
545
|
},
|
|
522
546
|
this.#styleLoadResultCache,
|
|
523
547
|
);
|
|
@@ -525,24 +549,24 @@ export class SdNgBundler {
|
|
|
525
549
|
return new SdNgBundlerContext(this.#opt.pkgPath, {
|
|
526
550
|
absWorkingDir: this.#opt.pkgPath,
|
|
527
551
|
bundle: true,
|
|
528
|
-
entryNames:
|
|
529
|
-
assetNames:
|
|
530
|
-
logLevel:
|
|
552
|
+
entryNames: "[name]",
|
|
553
|
+
assetNames: "media/[name]",
|
|
554
|
+
logLevel: "silent",
|
|
531
555
|
minify: !this.#opt.dev,
|
|
532
556
|
metafile: true,
|
|
533
557
|
sourcemap: true, //this.#opt.dev,
|
|
534
558
|
outdir: this.#opt.pkgPath,
|
|
535
559
|
write: false,
|
|
536
|
-
platform:
|
|
560
|
+
platform: "browser",
|
|
537
561
|
target: this.#browserTarget,
|
|
538
562
|
preserveSymlinks: false,
|
|
539
563
|
external: [],
|
|
540
|
-
conditions: [
|
|
541
|
-
mainFields: [
|
|
564
|
+
conditions: ["style", "sass"],
|
|
565
|
+
mainFields: ["style", "sass"],
|
|
542
566
|
legalComments: !this.#opt.dev ? "none" : "eof",
|
|
543
567
|
entryPoints: {
|
|
544
568
|
// styles: 'angular:styles/global;styles'
|
|
545
|
-
styles: path.resolve(this.#opt.pkgPath, "src/styles.scss")
|
|
569
|
+
styles: path.resolve(this.#opt.pkgPath, "src/styles.scss"),
|
|
546
570
|
},
|
|
547
571
|
plugins: [
|
|
548
572
|
// createVirtualModulePlugin({
|
|
@@ -565,13 +589,13 @@ export class SdNgBundler {
|
|
|
565
589
|
return new SdNgBundlerContext(this.#opt.pkgPath, {
|
|
566
590
|
absWorkingDir: this.#opt.pkgPath,
|
|
567
591
|
bundle: true,
|
|
568
|
-
entryNames:
|
|
569
|
-
assetNames:
|
|
570
|
-
conditions: [
|
|
592
|
+
entryNames: "[name]",
|
|
593
|
+
assetNames: "media/[name]",
|
|
594
|
+
conditions: ["es2020", "es2015", "module"],
|
|
571
595
|
resolveExtensions: [".js", ".mjs", ".cjs", ".ts"],
|
|
572
596
|
metafile: true,
|
|
573
|
-
legalComments: this.#opt.dev ?
|
|
574
|
-
logLevel:
|
|
597
|
+
legalComments: this.#opt.dev ? "eof" : "none",
|
|
598
|
+
logLevel: "silent",
|
|
575
599
|
minify: !this.#opt.dev,
|
|
576
600
|
outdir: this.#opt.pkgPath,
|
|
577
601
|
sourcemap: true, //this.#opt.dev,
|
|
@@ -580,22 +604,23 @@ export class SdNgBundler {
|
|
|
580
604
|
preserveSymlinks: false,
|
|
581
605
|
external: ["electron"],
|
|
582
606
|
define: {
|
|
583
|
-
|
|
584
|
-
|
|
607
|
+
...(!this.#opt.dev ? { ngDevMode: "false" } : {}),
|
|
608
|
+
"process.env.SD_VERSION": JSON.stringify(this.#pkgNpmConf.version),
|
|
585
609
|
"process.env.NODE_ENV": JSON.stringify(this.#opt.dev ? "development" : "production"),
|
|
586
|
-
...
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
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
|
+
: {}),
|
|
590
616
|
},
|
|
591
|
-
platform:
|
|
617
|
+
platform: "node",
|
|
592
618
|
entryPoints: {
|
|
593
619
|
"electron-main": path.resolve(this.#opt.pkgPath, "src/electron-main.ts"),
|
|
594
|
-
}
|
|
620
|
+
},
|
|
595
621
|
});
|
|
596
622
|
}
|
|
597
623
|
|
|
598
|
-
|
|
599
624
|
#debug(...msg: any[]): void {
|
|
600
625
|
this.#logger.debug(`[${path.basename(this.#opt.pkgPath)}]`, ...msg);
|
|
601
626
|
}
|
|
@@ -608,4 +633,4 @@ interface IOptions {
|
|
|
608
633
|
builderType: string;
|
|
609
634
|
env: Record<string, string> | undefined;
|
|
610
635
|
cordovaConfig: ISdCliClientBuilderCordovaConfig | undefined;
|
|
611
|
-
}
|
|
636
|
+
}
|