@simplysm/sd-cli 10.0.65 → 11.0.3

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.
Files changed (74) hide show
  1. package/dist/build-cluster.js +15 -14
  2. package/dist/build-cluster.js.map +1 -1
  3. package/dist/build-tools/SdTsIncrementalBuilder.d.ts +2 -0
  4. package/dist/build-tools/SdTsIncrementalBuilder.js +60 -9
  5. package/dist/build-tools/SdTsIncrementalBuilder.js.map +1 -1
  6. package/dist/builders/SdCliClientBuilder.d.ts +6 -7
  7. package/dist/builders/SdCliClientBuilder.js +281 -245
  8. package/dist/builders/SdCliClientBuilder.js.map +1 -1
  9. package/dist/builders/SdCliServerBuilder.d.ts +4 -3
  10. package/dist/builders/SdCliServerBuilder.js +3 -2
  11. package/dist/builders/SdCliServerBuilder.js.map +1 -1
  12. package/dist/builders/SdCliTsLibBuilder.d.ts +4 -4
  13. package/dist/builders/SdCliTsLibBuilder.js +9 -61
  14. package/dist/builders/SdCliTsLibBuilder.js.map +1 -1
  15. package/dist/commons.d.ts +4 -5
  16. package/dist/entry/SdCliProject.js +13 -12
  17. package/dist/entry/SdCliProject.js.map +1 -1
  18. package/dist/index.d.ts +0 -10
  19. package/dist/index.js +0 -10
  20. package/dist/index.js.map +1 -1
  21. package/dist/sd-cli.js +0 -19
  22. package/dist/sd-cli.js.map +1 -1
  23. package/package.json +14 -18
  24. package/src/build-cluster.ts +15 -14
  25. package/src/build-tools/SdTsIncrementalBuilder.ts +92 -10
  26. package/src/builders/SdCliClientBuilder.ts +310 -285
  27. package/src/builders/SdCliServerBuilder.ts +12 -7
  28. package/src/builders/SdCliTsLibBuilder.ts +11 -80
  29. package/src/commons.ts +5 -5
  30. package/src/entry/SdCliElectron.ts +3 -3
  31. package/src/entry/SdCliLocalUpdate.ts +3 -3
  32. package/src/entry/SdCliProject.ts +20 -18
  33. package/src/index.ts +0 -10
  34. package/src/sd-cli.ts +0 -23
  35. package/dist/entry/SdCliPwaAssets.d.ts +0 -6
  36. package/dist/entry/SdCliPwaAssets.js +0 -39
  37. package/dist/entry/SdCliPwaAssets.js.map +0 -1
  38. package/dist/utils/SdCliViteElectronMainPlugin.d.ts +0 -6
  39. package/dist/utils/SdCliViteElectronMainPlugin.js +0 -96
  40. package/dist/utils/SdCliViteElectronMainPlugin.js.map +0 -1
  41. package/dist/utils/SdCliViteExternalPlugin.d.ts +0 -6
  42. package/dist/utils/SdCliViteExternalPlugin.js +0 -85
  43. package/dist/utils/SdCliViteExternalPlugin.js.map +0 -1
  44. package/dist/utils/SdCliViteLazyImportPlugin.d.ts +0 -2
  45. package/dist/utils/SdCliViteLazyImportPlugin.js +0 -23
  46. package/dist/utils/SdCliViteLazyImportPlugin.js.map +0 -1
  47. package/dist/utils/SdCliViteLoggerPlugin.d.ts +0 -6
  48. package/dist/utils/SdCliViteLoggerPlugin.js +0 -24
  49. package/dist/utils/SdCliViteLoggerPlugin.js.map +0 -1
  50. package/dist/utils/SdCliViteNodeGlobalPlugin.d.ts +0 -2
  51. package/dist/utils/SdCliViteNodeGlobalPlugin.js +0 -29
  52. package/dist/utils/SdCliViteNodeGlobalPlugin.js.map +0 -1
  53. package/dist/utils/SdCliViteReactSwcPlugin.d.ts +0 -2
  54. package/dist/utils/SdCliViteReactSwcPlugin.js +0 -139
  55. package/dist/utils/SdCliViteReactSwcPlugin.js.map +0 -1
  56. package/dist/utils/SdCliViteServeOptimizeExcludePlugin.d.ts +0 -2
  57. package/dist/utils/SdCliViteServeOptimizeExcludePlugin.js +0 -36
  58. package/dist/utils/SdCliViteServeOptimizeExcludePlugin.js.map +0 -1
  59. package/dist/utils/getElectronReactExternals.d.ts +0 -1
  60. package/dist/utils/getElectronReactExternals.js +0 -17
  61. package/dist/utils/getElectronReactExternals.js.map +0 -1
  62. package/dist/utils/sdCliTsDefineTransformer.d.ts +0 -4
  63. package/dist/utils/sdCliTsDefineTransformer.js +0 -26
  64. package/dist/utils/sdCliTsDefineTransformer.js.map +0 -1
  65. package/src/entry/SdCliPwaAssets.ts +0 -50
  66. package/src/utils/SdCliViteElectronMainPlugin.ts +0 -102
  67. package/src/utils/SdCliViteExternalPlugin.ts +0 -98
  68. package/src/utils/SdCliViteLazyImportPlugin.ts +0 -26
  69. package/src/utils/SdCliViteLoggerPlugin.ts +0 -29
  70. package/src/utils/SdCliViteNodeGlobalPlugin.ts +0 -31
  71. package/src/utils/SdCliViteReactSwcPlugin.ts +0 -153
  72. package/src/utils/SdCliViteServeOptimizeExcludePlugin.ts +0 -42
  73. package/src/utils/getElectronReactExternals.ts +0 -19
  74. package/src/utils/sdCliTsDefineTransformer.ts +0 -33
@@ -1,31 +1,34 @@
1
1
  import {EventEmitter} from "events";
2
- import {FsUtil, Logger, SdFsWatcher, SdProcess} from "@simplysm/sd-core-node";
3
- import {INpmConfig, ISdCliBuilderResult, ISdCliClientPackageConfig, ISdCliPackageBuildResult} from "../commons";
4
- import {FunctionQueue, MathUtil} from "@simplysm/sd-core-common";
5
- import * as vite from "vite";
6
- import {defineConfig, InlineConfig} from "vite";
7
- import vitePluginPaths from "vite-tsconfig-paths";
2
+ import {FsUtil, Logger, PathUtil, SdFsWatcher} from "@simplysm/sd-core-node";
3
+ import {ISdCliBuilderResult, ISdCliClientPackageConfig, ISdCliConfig, ISdCliPackageBuildResult} from "../commons";
4
+ import {FunctionQueue, NotImplementError} from "@simplysm/sd-core-common";
8
5
  import path from "path";
6
+ import esbuild from "esbuild";
7
+ import {createVirtualModulePlugin} from "@angular-devkit/build-angular/src/tools/esbuild/virtual-module-plugin";
8
+ import {
9
+ createSourcemapIgnorelistPlugin
10
+ } from "@angular-devkit/build-angular/src/tools/esbuild/sourcemap-ignorelist-plugin";
11
+ import {
12
+ createCompilerPlugin,
13
+ SourceFileCache
14
+ } from "@angular-devkit/build-angular/src/tools/esbuild/angular/compiler-plugin";
15
+ import {createCompilerPluginOptions} from "@angular-devkit/build-angular/src/tools/esbuild/compiler-plugin-options";
16
+ import {CrossOrigin} from "@angular-devkit/build-angular/src/builders/application/schema";
17
+
18
+ import nodeStdLibBrowserPlugin from "node-stdlib-browser/helpers/esbuild/plugin";
19
+ import nodeStdLibBrowser from "node-stdlib-browser";
20
+ import {fileURLToPath} from "url";
9
21
  import {SdTsIncrementalBuilder} from "../build-tools/SdTsIncrementalBuilder";
10
22
  import {SdLinter} from "../build-tools/SdLinter";
11
- import {VitePWA} from 'vite-plugin-pwa';
12
- import {SdCliViteNodeGlobalPlugin} from "../utils/SdCliViteNodeGlobalPlugin";
13
- import {SdCliViteLoggerPlugin} from "../utils/SdCliViteLoggerPlugin";
14
- import {SdCliViteReactSwcPlugin} from "../utils/SdCliViteReactSwcPlugin";
15
- import {SdCliViteExternalPlugin} from "../utils/SdCliViteExternalPlugin";
16
- import {SdCliViteElectronMainPlugin} from "../utils/SdCliViteElectronMainPlugin";
17
- import electronBuilder from "electron-builder";
18
- import {SdCliViteServeOptimizeExcludePlugin} from "../utils/SdCliViteServeOptimizeExcludePlugin";
19
- import {SdCliViteLazyImportPlugin} from "../utils/SdCliViteLazyImportPlugin";
20
23
 
21
24
  export class SdCliClientBuilder extends EventEmitter {
22
25
  private readonly _logger = Logger.get(["simplysm", "sd-cli", "SdCliClientBuilder"]);
26
+ private readonly _pkgConf: ISdCliClientPackageConfig;
23
27
 
24
- public constructor(private readonly _pkgPath: string,
25
- private readonly _pkgConf: ISdCliClientPackageConfig,
26
- private readonly _builderKey: "web" | "electron",
27
- private readonly _withLint: boolean) {
28
+ public constructor(private readonly _projConf: ISdCliConfig,
29
+ private readonly _pkgPath: string) {
28
30
  super();
31
+ this._pkgConf = this._projConf.packages[path.basename(_pkgPath)] as ISdCliClientPackageConfig;
29
32
  }
30
33
 
31
34
  public override on(event: "change", listener: () => void): this;
@@ -35,27 +38,77 @@ export class SdCliClientBuilder extends EventEmitter {
35
38
  return this;
36
39
  }
37
40
 
38
- public async watchAsync(): Promise<number> {
39
- const cachePath = path.resolve(this._pkgPath, ".cache", "dev", ...this._builderKey !== "web" ? [this._builderKey] : []);
41
+ public async watchAsync(): Promise<void> {
42
+ this._debug("빌드 준비...");
43
+ const sdTsProgram = await SdTsIncrementalBuilder.createAsync(this._pkgPath, () => ({emitJs: false}));
44
+
45
+ this._debug("dist 초기화...");
46
+ await FsUtil.removeAsync(path.resolve(this._pkgPath, "dist"));
40
47
 
41
48
  this.emit("change");
42
49
 
50
+ if (this._pkgConf.server !== undefined) {
51
+ this._debug("GEN .config...");
52
+ const confDistPath = path.resolve(this._pkgPath, "../../packages", this._pkgConf.server, "dist/www", path.basename(this._pkgPath), ".config.json");
53
+ await FsUtil.writeFileAsync(confDistPath, JSON.stringify(this._pkgConf.configs ?? {}, undefined, 2));
54
+ }
55
+
43
56
  this._debug("BUILD...");
44
- const viteServerPort = this._pkgConf.builder?.[this._builderKey]?.["devServerPort"] ?? MathUtil.getRandomInt(60000, 65535);
45
- const viteServer = await vite.createServer(this._getViteConfig({
57
+ const builderTypes = (Object.keys(this._pkgConf.builder ?? {web: {}}) as ("web")[]);
58
+ const cache = new SourceFileCache();
59
+ const options = await Promise.all(builderTypes.map((builderType) => this._getEsBuildOptionsAsync({
46
60
  dev: true,
47
- pkgConf: this._pkgConf,
48
- cachePath: cachePath,
49
- port: viteServerPort,
61
+ builderType,
62
+ cache
63
+ })));
64
+ const contexts = await Promise.all(options.map((esbuildOption) => esbuild.context(esbuildOption)));
65
+ const results = await Promise.all(contexts.map(async (ctx) => {
66
+ try {
67
+ return await ctx.rebuild();
68
+ }
69
+ catch (err) {
70
+ if (typeof err === "object" && "errors" in err && "warnings" in err) {
71
+ return {
72
+ errors: err.errors,
73
+ warnings: err.warnings
74
+ };
75
+ }
76
+ throw new err;
77
+ }
50
78
  }));
51
- await viteServer.listen(viteServerPort);
79
+
80
+ const buildResults: ISdCliPackageBuildResult[] = results.mapMany((esbuildResult) => [
81
+ ...esbuildResult.warnings.map((warn) => ({
82
+ filePath: warn.location?.file !== undefined ? path.resolve(warn.location.file) : undefined,
83
+ line: warn.location?.line,
84
+ char: warn.location?.column,
85
+ code: undefined,
86
+ severity: "warning" as const,
87
+ message: warn.text,
88
+ type: "build" as const
89
+ })),
90
+ ...esbuildResult.errors.map((err) => ({
91
+ filePath: err.location?.file !== undefined ? path.resolve(err.location.file) : undefined,
92
+ line: err.location?.line,
93
+ char: err.location?.column !== undefined ? err.location.column + 1 : undefined,
94
+ code: undefined,
95
+ severity: "warning" as const,
96
+ message: err.text,
97
+ type: "build" as const
98
+ }))
99
+ ]);
52
100
 
53
101
  this._debug("CHECK...");
54
- const sdTsProgram = await SdTsIncrementalBuilder.createAsync(this._pkgPath, () => ({emitJs: false}));
55
102
  const checkResult = await sdTsProgram.buildAsync();
56
103
 
57
104
  this._debug("LINT...");
58
- const lintResults = !this._withLint ? [] : await SdLinter.lintAsync(checkResult.affectedFilePaths, sdTsProgram.builderProgram!.getProgram());
105
+ const lintResults = await SdLinter.lintAsync(checkResult.affectedFilePaths, sdTsProgram.builderProgram!.getProgram());
106
+
107
+ this._debug(`빌드 완료`);
108
+ this.emit("complete", {
109
+ affectedFilePaths: checkResult.affectedFilePaths,
110
+ buildResults: [...buildResults, ...checkResult.results, ...lintResults]
111
+ });
59
112
 
60
113
  this._debug("WATCH...");
61
114
  const fnQ = new FunctionQueue();
@@ -66,285 +119,257 @@ export class SdCliClientBuilder extends EventEmitter {
66
119
  ])
67
120
  .onChange({
68
121
  delay: 100
69
- }, () => {
122
+ }, (changeInfos) => {
123
+ for (const changeInfo of changeInfos) {
124
+ cache.delete(PathUtil.posix(changeInfo.path));
125
+ }
126
+
70
127
  fnQ.runLast(async () => {
71
128
  this.emit("change");
72
129
 
73
- this._debug(`CHECK...`);
130
+ this._debug(`BUILD...`);
131
+ const watchResults = await Promise.all(contexts.map(async (ctx) => {
132
+ try {
133
+ return await ctx.rebuild();
134
+ }
135
+ catch (err) {
136
+ if (typeof err === "object" && "errors" in err && "warnings" in err) {
137
+ return {
138
+ errors: err.errors,
139
+ warnings: err.warnings
140
+ };
141
+ }
142
+ throw new err;
143
+ }
144
+ }));
145
+
146
+ const watchBuildResults: ISdCliPackageBuildResult[] = watchResults.mapMany((esbuildResult) => [
147
+ ...esbuildResult.warnings.map((warn) => ({
148
+ filePath: warn.location?.file !== undefined ? path.resolve(warn.location.file) : undefined,
149
+ line: warn.location?.line,
150
+ char: warn.location?.column,
151
+ code: undefined,
152
+ severity: "warning" as const,
153
+ message: warn.text,
154
+ type: "build" as const
155
+ })),
156
+ ...esbuildResult.errors.map((err) => ({
157
+ filePath: err.location?.file !== undefined ? path.resolve(err.location.file) : undefined,
158
+ line: err.location?.line,
159
+ char: err.location?.column !== undefined ? err.location.column + 1 : undefined,
160
+ code: undefined,
161
+ severity: "warning" as const,
162
+ message: err.text,
163
+ type: "build" as const
164
+ }))
165
+ ]);
166
+
167
+ this._debug("CHECK...");
74
168
  const watchCheckResult = await sdTsProgram.buildAsync();
75
169
 
76
170
  this._debug(`LINT...`);
77
- const watchLintResults = !this._withLint ? [] : await SdLinter.lintAsync(watchCheckResult.affectedFilePaths, sdTsProgram.builderProgram!.getProgram());
171
+ const watchLintResults = await SdLinter.lintAsync(watchCheckResult.affectedFilePaths, sdTsProgram.builderProgram!.getProgram());
78
172
 
79
173
  this._debug(`빌드 완료`);
80
174
  this.emit("complete", {
81
- port: viteServerPort,
82
175
  affectedFilePaths: watchCheckResult.affectedFilePaths,
83
- buildResults: [...watchCheckResult.results, ...watchLintResults]
176
+ buildResults: [...watchBuildResults, ...watchCheckResult.results, ...watchLintResults]
84
177
  });
85
178
  });
86
179
  });
87
-
88
- if (this._pkgConf.server !== undefined) {
89
- this._debug("GEN .config...");
90
- const confDistPath = path.resolve(this._pkgPath, "../../packages", this._pkgConf.server, "dist/www", path.basename(this._pkgPath), ".config.json");
91
- await FsUtil.writeFileAsync(confDistPath, JSON.stringify(this._pkgConf.configs ?? {}, undefined, 2));
92
- }
93
-
94
- this._debug(`빌드 완료`);
95
- this.emit("complete", {
96
- port: viteServerPort,
97
- affectedFilePaths: checkResult.affectedFilePaths,
98
- buildResults: [...checkResult.results, ...lintResults]
99
- });
100
-
101
- return viteServerPort;
102
180
  }
103
181
 
182
+ // eslint-disable-next-line @typescript-eslint/require-await
104
183
  public async buildAsync(): Promise<ISdCliBuilderResult> {
105
- this._debug("dist 초기화...");
106
- const cachePath = path.resolve(this._pkgPath, ".cache", "prod", ...this._builderKey !== "web" ? [this._builderKey] : []);
107
- const distPath = path.resolve(this._pkgPath, "dist", ...this._builderKey !== "web" ? [this._builderKey] : []);
108
- await FsUtil.removeAsync(cachePath);
109
- await FsUtil.removeAsync(distPath);
110
-
111
- this._debug("BUILD...");
112
- const buildResults: ISdCliPackageBuildResult[] = [];
113
- try {
114
- await vite.build(this._getViteConfig({
115
- dev: false,
116
- pkgConf: this._pkgConf,
117
- cachePath: cachePath,
118
- distPath: distPath,
119
- }));
120
- }
121
- catch (err) {
122
- if ("errors" in err && err.errors instanceof Array) {
123
- buildResults.push(...err.errors.map((item: any) => ({
124
- filePath: item.location.file,
125
- line: item.location.line,
126
- char: item.location.column,
127
- code: undefined,
128
- severity: "error" as const,
129
- message: item.text
130
- })));
131
- }
132
- if ("warnings" in err && err.warnings instanceof Array) {
133
- buildResults.push(...err.warnings.map((item: any) => ({
134
- filePath: item.location.file,
135
- line: item.location.line,
136
- char: item.location.column,
137
- code: undefined,
138
- severity: "warning" as const,
139
- message: item.text
140
- })));
141
- }
142
- }
143
-
144
- this._debug("CHECK...");
145
- const sdTsProgram = await SdTsIncrementalBuilder.createAsync(this._pkgPath, () => ({emitJs: false}));
146
- const checkResult = await sdTsProgram.buildAsync();
147
-
148
- this._debug("LINT...");
149
- const lintResults = !this._withLint ? [] : await SdLinter.lintAsync(checkResult.affectedFilePaths, sdTsProgram.builderProgram!.getProgram());
150
-
151
- if (this._pkgConf.server !== undefined) {
152
- const confDistPath = path.resolve(this._pkgPath, "dist/.config.json");
153
- this._debug("GEN .config...");
154
- await FsUtil.writeFileAsync(confDistPath, JSON.stringify(this._pkgConf.configs ?? {}, undefined, 2));
155
- }
156
-
157
- if (this._builderKey === "electron") {
158
- const electronSrcPath = path.resolve(this._pkgPath, ".cache/prod/electron/src");
159
- const electronDistPath = path.resolve(this._pkgPath, ".cache/prod/electron/dist");
160
- const pkgNpmConfig = (await FsUtil.readJsonAsync(path.resolve(this._pkgPath, `package.json`))) as INpmConfig;
161
-
162
- this._debug("package.json 파일 쓰기...");
163
- const externalPkgNames = this._pkgConf.builder!.electron!.reinstallDependencies ?? [];
164
-
165
- await FsUtil.writeJsonAsync(path.resolve(electronSrcPath, `package.json`), {
166
- name: pkgNpmConfig.name,
167
- version: pkgNpmConfig.version,
168
- description: pkgNpmConfig.description,
169
- main: "electron-main.js",
170
- ...this._pkgConf.builder!.electron!.postInstallScript !== undefined ? {
171
- scripts: {
172
- "postinstall": this._pkgConf.builder!.electron!.postInstallScript
173
- },
174
- } : {},
175
- dependencies: externalPkgNames.toObject((item) => item, (item) => pkgNpmConfig.dependencies![item] ?? "*")
176
- });
177
-
178
- this._debug("npm install...");
179
- await SdProcess.spawnAsync(`npm install`, {cwd: electronSrcPath}, true);
180
-
181
- for (const externalPkgName of externalPkgNames) {
182
- if (FsUtil.exists(path.resolve(electronSrcPath, "node_modules", externalPkgName, "binding.gyp"))) {
183
- this._debug(`electron rebuild (${externalPkgName})...`);
184
- await SdProcess.spawnAsync(`electron-rebuild -m ./node_modules/${externalPkgName}`, {cwd: electronSrcPath}, true);
185
- }
186
- }
187
-
188
- await electronBuilder.build({
189
- targets: electronBuilder.Platform.WINDOWS.createTarget(),
190
- config: {
191
- appId: this._pkgConf.builder!.electron!.appId,
192
- productName: pkgNpmConfig.description,
193
- // asar: false,
194
- win: {
195
- target: "nsis"
196
- },
197
- nsis: {},
198
- directories: {
199
- app: electronSrcPath,
200
- output: electronDistPath
201
- },
202
- ...this._pkgConf.builder!.electron!.installerIcon !== undefined ? {
203
- icon: path.resolve(this._pkgPath, "src", this._pkgConf.builder!.electron!.installerIcon)
204
- } : {},
205
- removePackageScripts: false
206
- }
207
- });
208
-
209
- await FsUtil.copyAsync(
210
- path.resolve(electronDistPath, `${pkgNpmConfig.description} Setup ${pkgNpmConfig.version}.exe`),
211
- path.resolve(distPath, `electron/${pkgNpmConfig.description}-latest.exe`)
212
- );
213
-
214
- await FsUtil.copyAsync(
215
- path.resolve(electronDistPath, `${pkgNpmConfig.description} Setup ${pkgNpmConfig.version}.exe`),
216
- path.resolve(distPath, `electron/updates/${pkgNpmConfig.version}.exe`)
217
- );
218
- }
219
-
220
-
221
- this._debug(`빌드 완료`);
222
- return {
223
- affectedFilePaths: checkResult.affectedFilePaths,
224
- buildResults: [...buildResults, ...checkResult.results, ...lintResults]
225
- };
184
+ throw new NotImplementError();
226
185
  }
227
186
 
228
- private _getViteConfig(opt: {
229
- dev: boolean,
230
- cachePath: string,
231
- distPath?: string,
232
- port?: number,
233
- pkgConf: ISdCliClientPackageConfig
234
- }): InlineConfig {
235
- const pkgNpmConf: INpmConfig = FsUtil.readJson(path.resolve(this._pkgPath, "package.json"));
236
-
237
- const basePath = this._builderKey === "electron" ? "" : (!opt.dev || this._pkgConf.server !== undefined) ? ("/" + path.basename(this._pkgPath) + "/") : "/";
238
-
239
- const serverHost = this._pkgConf.builder?.[this._builderKey]?.devServerHost ?? "localhost";
240
-
241
- const define = {
242
- ...opt.dev ? {
243
- "import.meta.env.SD_SERVER_URL": JSON.stringify(`http://${serverHost}:${opt.port}` + basePath)
244
- } : {},
245
- "import.meta.env.SD_VERSION": JSON.stringify(pkgNpmConf.version),
246
- ...this._pkgConf.env
247
- ? Object.keys(this._pkgConf.env)
248
- .toObject(
249
- (key) => "import.meta.env." + key,
250
- (key) => JSON.stringify(this._pkgConf.env![key])
251
- )
252
- : {},
253
- ...this._pkgConf.builder?.[this._builderKey]?.env
254
- ? Object.keys(this._pkgConf.builder[this._builderKey]!.env!)
255
- .toObject(
256
- (key) => "import.meta.env." + key,
257
- (key) => JSON.stringify(this._pkgConf.builder![this._builderKey]!.env![key])
258
- )
259
- : {}
260
- };
187
+ private async _getEsBuildOptionsAsync(opt: {
188
+ dev: boolean;
189
+ builderType: "web",
190
+ cache: SourceFileCache
191
+ }): Promise<esbuild.BuildOptions> {
192
+ // const projPath = path.resolve(this._pkgPath, "../../");
193
+ const tsconfigFilePath = path.resolve(this._pkgPath, "tsconfig.json");
194
+ const mainFilePath = path.resolve(this._pkgPath, "src/main.ts");
195
+ const indexHtmlFilePath = path.resolve(this._pkgPath, "src/index.html");
196
+
197
+ const cacheBasePath = path.resolve(this._pkgPath, ".cache");
198
+ const distBasePath = path.resolve(this._pkgPath, "dist");
199
+
200
+ const {pluginOptions, styleOptions} = createCompilerPluginOptions(
201
+ {
202
+ advancedOptimizations: true,
203
+ allowedCommonJsDependencies: [],
204
+ baseHref: undefined,
205
+ cacheOptions: {
206
+ enabled: true,
207
+ basePath: cacheBasePath,
208
+ path: path.resolve(cacheBasePath, opt.builderType)
209
+ },
210
+ crossOrigin: CrossOrigin.None,
211
+ deleteOutputPath: true,
212
+ externalDependencies: [],
213
+ extractLicenses: false,
214
+ inlineStyleLanguage: 'scss',
215
+ jit: false,
216
+ stats: false,
217
+ polyfills: ["./src/polyfills.ts"],
218
+ poll: undefined,
219
+ progress: true,
220
+ externalPackages: true,
221
+ preserveSymlinks: true,
222
+ stylePreprocessorOptions: {includePaths: []},
223
+ subresourceIntegrity: false,
224
+ serverEntryPoint: undefined,
225
+ prerenderOptions: undefined,
226
+ appShellOptions: undefined,
227
+ ssrOptions: undefined,
228
+ verbose: false,
229
+ watch: true,
230
+ workspaceRoot: this._pkgPath,
231
+ entryPoints: {main: mainFilePath},
232
+ optimizationOptions: {
233
+ scripts: false,
234
+ styles: {minify: false, inlineCritical: false},
235
+ fonts: {inline: false}
236
+ },
237
+ outputPath: distBasePath,
238
+ outExtension: undefined,
239
+ sourcemapOptions: {vendor: false, hidden: false, scripts: true, styles: true},
240
+ tsconfig: tsconfigFilePath,
241
+ projectRoot: this._pkgPath,
242
+ assets: [
243
+ {glob: 'favicon.ico', input: 'src', output: ''},
244
+ {glob: '**/*', input: 'src\\assets', output: 'assets'}
245
+ ],
246
+ outputNames: {bundles: '[name]', media: 'media/[name]'},
247
+ fileReplacements: undefined,
248
+ globalStyles: [{name: 'styles', files: ["src/styles.scss"], initial: true}],
249
+ globalScripts: [],
250
+ serviceWorker: undefined,
251
+ indexHtmlOptions: {
252
+ input: indexHtmlFilePath,
253
+ output: 'index.html',
254
+ insertionOrder: [
255
+ ['runtime', true],
256
+ ['polyfills', true],
257
+ ['styles', false],
258
+ ['vendor', true],
259
+ ['main', true]
260
+ ]
261
+ },
262
+ tailwindConfiguration: undefined
263
+ },
264
+ [
265
+ 'chrome117.0', 'chrome116.0',
266
+ 'edge117.0', 'edge116.0',
267
+ 'firefox118.0', 'firefox115.0',
268
+ 'ios17.0', 'ios16.6',
269
+ 'ios16.5', 'ios16.4',
270
+ 'ios16.3', 'ios16.2',
271
+ 'ios16.1', 'ios16.0',
272
+ 'safari17.0', 'safari16.6',
273
+ 'safari16.5', 'safari16.4',
274
+ 'safari16.3', 'safari16.2',
275
+ 'safari16.1', 'safari16.0'
276
+ ],
277
+ opt.cache,
278
+ );
261
279
 
262
- return defineConfig({
263
- mode: opt.dev ? "development" : "production",
264
- root: path.resolve(this._pkgPath, "src"),
265
- cacheDir: path.resolve(opt.cachePath, "vite"),
266
- base: basePath,
267
- assetsInclude: [
268
- "**/*.xlsx",
269
- "**/*.xls",
270
- "**/*.docx",
271
- "**/*.doc",
272
- "**/*.pptx",
273
- "**/*.ppt",
274
- "**/*.woff",
275
- "**/*.woff2",
276
- "**/*.ttf",
277
- "**/*.eot",
278
- "**/*.otf",
279
- "**/*.csv",
280
- "**/*.zip",
281
- "**/*.pfx",
282
- "**/*.pkl"
280
+ return {
281
+ absWorkingDir: this._pkgPath,
282
+ bundle: true,
283
+ format: 'esm',
284
+ assetNames: 'media/[name]',
285
+ conditions: ['es2020', 'es2015', 'module'],
286
+ resolveExtensions: ['.ts', '.tsx', '.mjs', '.js'],
287
+ metafile: true,
288
+ legalComments: 'eof',
289
+ logLevel: 'silent',
290
+ minifyIdentifiers: false,
291
+ minifySyntax: false,
292
+ minifyWhitespace: false,
293
+ pure: ['forwardRef'],
294
+ outdir: distBasePath,
295
+ outExtension: undefined,
296
+ sourcemap: true,
297
+ splitting: true,
298
+ chunkNames: 'chunk-[hash]',
299
+ tsconfig: tsconfigFilePath,
300
+ external: [],
301
+ write: true,
302
+ preserveSymlinks: true,
303
+ define: {
304
+ ngJitMode: 'false',
305
+ global: 'global',
306
+ process: 'process',
307
+ Buffer: 'Buffer'
308
+ },
309
+ platform: 'browser',
310
+ mainFields: ['es2020', 'es2015', 'browser', 'module', 'main'],
311
+ entryNames: '[name]',
312
+ entryPoints: {
313
+ main: mainFilePath,
314
+ polyfills: 'angular:polyfills'
315
+ },
316
+ target: [
317
+ 'chrome117.0', 'chrome116.0',
318
+ 'edge117.0', 'edge116.0',
319
+ 'firefox118.0', 'firefox115.0',
320
+ 'ios17.0', 'ios16.6',
321
+ 'ios16.5', 'ios16.4',
322
+ 'ios16.3', 'ios16.2',
323
+ 'ios16.1', 'ios16.0',
324
+ 'safari17.0', 'safari16.6',
325
+ 'safari16.5', 'safari16.4',
326
+ 'safari16.3', 'safari16.2',
327
+ 'safari16.1', 'safari16.0'
283
328
  ],
284
- define: define,
285
- ...opt.dev ? {
286
- server: {
287
- host: serverHost,
288
- port: opt.port,
289
- hmr: {
290
- host: serverHost,
291
- port: opt.port
292
- }
293
- },
294
- } : {},
295
- optimizeDeps: {
296
- force: true
329
+ supported: {'async-await': false, 'object-rest-spread': false},
330
+ loader: {
331
+ ".png": "file",
332
+ ".jpeg": "file",
333
+ ".jpg": "file",
334
+ ".jfif": "file",
335
+ ".gif": "file",
336
+ ".svg": "file",
337
+ ".woff": "file",
338
+ ".woff2": "file",
339
+ ".ttf": "file",
340
+ ".eot": "file",
341
+ ".ico": "file",
342
+ ".otf": "file",
343
+ ".csv": "file",
344
+ ".xlsx": "file",
345
+ ".xls": "file",
346
+ ".pptx": "file",
347
+ ".ppt": "file",
348
+ ".docx": "file",
349
+ ".doc": "file",
350
+ ".zip": "file",
351
+ ".pfx": "file",
352
+ ".pkl": "file"
297
353
  },
298
- ...!opt.dev ? {
299
- build: {
300
- outDir: this._builderKey === "electron" ? path.resolve(opt.cachePath, "src") : opt.distPath,
301
- rollupOptions: {
302
- output: {
303
- entryFileNames: `assets/[name].js`,
304
- chunkFileNames: `assets/[name].js`,
305
- assetFileNames: `assets/[name].[ext]`
306
- }
307
- }
308
- }
309
- } : {},
354
+ inject: [PathUtil.posix(fileURLToPath(await import.meta.resolve!("node-stdlib-browser/helpers/esbuild/shim")))],
310
355
  plugins: [
311
- SdCliViteReactSwcPlugin(),
312
- SdCliViteLoggerPlugin({
313
- logger: this._logger,
314
- name: path.basename(this._pkgPath)
315
- }),
316
- vitePluginPaths(),
317
- ...opt.dev ? [
318
- SdCliViteLazyImportPlugin()
319
- ] : [],
320
- ...opt.dev ? [
321
- SdCliViteServeOptimizeExcludePlugin([
322
- "@simplysm/*"
323
- ])
324
- ] : [],
325
- ...!opt.dev && this._builderKey === "web" ? [
326
- VitePWA({
327
- registerType: 'autoUpdate',
328
- manifest: FsUtil.readJson(path.resolve(this._pkgPath, "src/manifest.json"))
329
- }),
330
- ] : [],
331
- ...this._builderKey === "web" ? [
332
- SdCliViteNodeGlobalPlugin()
333
- ] : [],
334
- ...this._builderKey === "electron" ? [
335
- SdCliViteElectronMainPlugin({
336
- entry: path.resolve(this._pkgPath, "src/electron-main.ts"),
337
- distPath: path.resolve(opt.cachePath, "src"),
338
- cachePath: path.resolve(opt.cachePath, "electron-main")
339
- }),
340
- SdCliViteExternalPlugin({
341
- target: "browser",
342
- cachePath: path.resolve(opt.cachePath, "external"),
343
- includes: opt.pkgConf.builder?.electron?.reinstallDependencies
356
+ createVirtualModulePlugin({
357
+ namespace: "angular:polyfills",
358
+ loadContent: () => ({
359
+ contents: `import "./src/polyfills.ts";`,
360
+ loader: 'js',
361
+ resolveDir: this._pkgPath
344
362
  })
345
- ] : [],
346
- ],
347
- });
363
+ }) as esbuild.Plugin,
364
+ createSourcemapIgnorelistPlugin() as esbuild.Plugin,
365
+ createCompilerPlugin(
366
+ pluginOptions,
367
+ styleOptions
368
+ ) as esbuild.Plugin,
369
+ // createExternalPackagesPlugin() as esbuild.Plugin,
370
+ nodeStdLibBrowserPlugin(nodeStdLibBrowser)
371
+ ]
372
+ };
348
373
  }
349
374
 
350
375
  private _debug(msg: string): void {