@hpcc-js/esbuild-plugins 1.8.3 → 1.8.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +43 -43
- package/README.md +45 -45
- package/dist/index.js.map +1 -1
- package/dist/sfx-wrapper.js +23 -23
- package/dist/sfx-wrapper.js.map +4 -4
- package/package.json +5 -5
- package/src/build.ts +177 -177
- package/src/exclude-sourcemap.ts +20 -20
- package/src/index.ts +8 -8
- package/src/inline-css.ts +44 -44
- package/src/package-version-plugin.ts +87 -87
- package/src/problem-matcher.ts +24 -24
- package/src/rebuild-logger.ts +24 -24
- package/src/remove-strict.ts +21 -21
- package/src/sfx-wrapper.ts +152 -152
- package/src/vite-utils.ts +259 -259
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hpcc-js/esbuild-plugins",
|
|
3
|
-
"version": "1.8.
|
|
3
|
+
"version": "1.8.4",
|
|
4
4
|
"description": "Various esbuild plugins",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"update-major": "npx --yes npm-check-updates -u"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"esbuild": "0.27.
|
|
41
|
+
"esbuild": "0.27.3",
|
|
42
42
|
"esbuild-copy-static-files": "0.1.0",
|
|
43
43
|
"esbuild-plugin-inline-css": "0.0.1",
|
|
44
44
|
"esbuild-plugin-umd-wrapper": "3.0.0",
|
|
@@ -47,8 +47,8 @@
|
|
|
47
47
|
"vite-plugin-static-copy": "3.2.0"
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
|
-
"@hpcc-js/wasm-base91": "1.
|
|
51
|
-
"@hpcc-js/wasm-zstd": "1.
|
|
50
|
+
"@hpcc-js/wasm-base91": "1.13.1",
|
|
51
|
+
"@hpcc-js/wasm-zstd": "1.12.1"
|
|
52
52
|
},
|
|
53
53
|
"keywords": [
|
|
54
54
|
"esbuild",
|
|
@@ -64,5 +64,5 @@
|
|
|
64
64
|
},
|
|
65
65
|
"homepage": "https://hpcc-systems.github.io/hpcc-js-wasm/",
|
|
66
66
|
"license": "Apache-2.0",
|
|
67
|
-
"gitHead": "
|
|
67
|
+
"gitHead": "04460c76008934053c9957c361693aac862ca7dc"
|
|
68
68
|
}
|
package/src/build.ts
CHANGED
|
@@ -1,177 +1,177 @@
|
|
|
1
|
-
import * as process from "process";
|
|
2
|
-
import { readFileSync } from "fs";
|
|
3
|
-
import * as path from "path";
|
|
4
|
-
import * as esbuild from "esbuild";
|
|
5
|
-
import type { BuildOptions, Format, Loader, Plugin } from "esbuild";
|
|
6
|
-
import { umdWrapper } from "esbuild-plugin-umd-wrapper";
|
|
7
|
-
import * as copyStaticFiles from "esbuild-copy-static-files";
|
|
8
|
-
import { inlineCSS } from "./inline-css.ts";
|
|
9
|
-
import { rebuildLogger } from "./rebuild-logger.ts";
|
|
10
|
-
|
|
11
|
-
export { copyStaticFiles };
|
|
12
|
-
|
|
13
|
-
export const pkg = JSON.parse(readFileSync(path.join(process.cwd(), "./package.json"), "utf8"));
|
|
14
|
-
export const NODE_MJS = pkg.type === "module" ? "js" : "mjs";
|
|
15
|
-
export const NODE_CJS = pkg.type === "module" ? "cjs" : "js";
|
|
16
|
-
|
|
17
|
-
interface BuildOptionsEx extends Omit<BuildOptions, "format"> {
|
|
18
|
-
format?: Format | "umd";
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export async function buildWatch(inputs: string[] | Record<string, string> | { in: string, out: string }[], config: BuildOptionsEx): Promise<void> {
|
|
22
|
-
const isDevelopment = process.argv.includes("--development");
|
|
23
|
-
const isWatch = process.argv.includes("--watch");
|
|
24
|
-
const isProduction = !isDevelopment;
|
|
25
|
-
|
|
26
|
-
config = {
|
|
27
|
-
entryPoints: inputs,
|
|
28
|
-
format: config.format ?? "esm",
|
|
29
|
-
bundle: true,
|
|
30
|
-
minify: isProduction,
|
|
31
|
-
sourcemap: true,
|
|
32
|
-
external: [
|
|
33
|
-
...config.external ?? []
|
|
34
|
-
],
|
|
35
|
-
...config,
|
|
36
|
-
loader: {
|
|
37
|
-
...config.loader
|
|
38
|
-
},
|
|
39
|
-
outExtension: {
|
|
40
|
-
...config.outExtension
|
|
41
|
-
},
|
|
42
|
-
banner: {
|
|
43
|
-
...config.banner
|
|
44
|
-
},
|
|
45
|
-
footer: {
|
|
46
|
-
...config.footer
|
|
47
|
-
},
|
|
48
|
-
plugins: [
|
|
49
|
-
...(isWatch ? [rebuildLogger(config)] : []),
|
|
50
|
-
...config.plugins ?? [],
|
|
51
|
-
inlineCSS()
|
|
52
|
-
],
|
|
53
|
-
nodePaths: [
|
|
54
|
-
...config.nodePaths ?? []
|
|
55
|
-
]
|
|
56
|
-
};
|
|
57
|
-
const ctx = await esbuild.context(config as BuildOptions);
|
|
58
|
-
|
|
59
|
-
if (isWatch) {
|
|
60
|
-
await ctx.watch();
|
|
61
|
-
} else {
|
|
62
|
-
if (isDevelopment && Array.isArray(config.entryPoints)) {
|
|
63
|
-
// eslint-disable-next-line no-console
|
|
64
|
-
console.log("Start: ", config.entryPoints[0], config.outfile);
|
|
65
|
-
}
|
|
66
|
-
await ctx.rebuild();
|
|
67
|
-
await ctx.dispose();
|
|
68
|
-
if (isDevelopment && Array.isArray(config.entryPoints)) {
|
|
69
|
-
// eslint-disable-next-line no-console
|
|
70
|
-
console.log("Stop: ", config.entryPoints[0], config.outfile);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
export type TplOptions = {
|
|
76
|
-
format?: Format | "umd";
|
|
77
|
-
globalName?: string;
|
|
78
|
-
libraryName?: string;
|
|
79
|
-
keepNames?: boolean;
|
|
80
|
-
external?: string[];
|
|
81
|
-
plugins?: Plugin[];
|
|
82
|
-
loader?: { [ext: string]: Loader };
|
|
83
|
-
supported?: Record<string, boolean>;
|
|
84
|
-
alias?: Record<string, string>;
|
|
85
|
-
define?: { [key: string]: string };
|
|
86
|
-
packages?: "bundle" | "external" | "auto";
|
|
87
|
-
};
|
|
88
|
-
|
|
89
|
-
function autoExternal(external?: string[]): string[] {
|
|
90
|
-
return [
|
|
91
|
-
...pkg.dependencies ? Object.keys(pkg.dependencies) : [], ...pkg.peerDependencies ? Object.keys(pkg.peerDependencies) : [],
|
|
92
|
-
...external ?? []
|
|
93
|
-
];
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
export function browserTpl(input: string, output: string, options: TplOptions = {}) {
|
|
97
|
-
options.format = options.format ?? "esm";
|
|
98
|
-
|
|
99
|
-
return buildWatch([input], {
|
|
100
|
-
format: options.format,
|
|
101
|
-
external: options.external ?? [],
|
|
102
|
-
outfile: `${output}.${options.format === "esm" ? "js" : `${options.format}.js`}`,
|
|
103
|
-
platform: "browser",
|
|
104
|
-
target: "es2022",
|
|
105
|
-
globalName: options.globalName,
|
|
106
|
-
keepNames: options.keepNames,
|
|
107
|
-
plugins: options.format === "umd" ? [umdWrapper({ libraryName: options.libraryName }) as Plugin, ...options.plugins ?? []] : options.plugins,
|
|
108
|
-
alias: options.alias,
|
|
109
|
-
define: options.define,
|
|
110
|
-
loader: options.loader,
|
|
111
|
-
supported: options.supported,
|
|
112
|
-
});
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
export function nodeTpl(input: string, output: string, options: TplOptions = {}) {
|
|
116
|
-
options.format = options.format ?? "esm";
|
|
117
|
-
options.packages = options.packages ?? "external";
|
|
118
|
-
if (options.packages === "auto") {
|
|
119
|
-
options.external = autoExternal(options.external);
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
return buildWatch([input], {
|
|
123
|
-
format: options.format,
|
|
124
|
-
external: options.external ?? [],
|
|
125
|
-
outfile: `${output}.${options.format === "esm" ? NODE_MJS : NODE_CJS}`,
|
|
126
|
-
platform: "node",
|
|
127
|
-
target: "node22",
|
|
128
|
-
packages: options.packages === "auto" ? "bundle" : options.packages,
|
|
129
|
-
globalName: options.globalName,
|
|
130
|
-
keepNames: options.keepNames,
|
|
131
|
-
plugins: options.plugins,
|
|
132
|
-
alias: options.alias,
|
|
133
|
-
define: options.define,
|
|
134
|
-
loader: options.loader,
|
|
135
|
-
supported: options.supported,
|
|
136
|
-
});
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
export function neutralTpl(input: string, output: string, options: TplOptions = {}) {
|
|
140
|
-
options.format = options.format ?? "esm";
|
|
141
|
-
|
|
142
|
-
return buildWatch([input], {
|
|
143
|
-
format: options.format,
|
|
144
|
-
external: options.external ?? [],
|
|
145
|
-
outfile: `${output}.${options.format === "esm" ? "js" : `${options.format}.js`}`,
|
|
146
|
-
platform: "neutral",
|
|
147
|
-
target: "es2022",
|
|
148
|
-
globalName: options.globalName,
|
|
149
|
-
keepNames: options.keepNames,
|
|
150
|
-
plugins: options.format === "umd" ? [umdWrapper({ libraryName: options.libraryName }) as Plugin, ...options.plugins ?? []] : options.plugins,
|
|
151
|
-
alias: options.alias,
|
|
152
|
-
define: options.define,
|
|
153
|
-
loader: options.loader,
|
|
154
|
-
supported: options.supported,
|
|
155
|
-
});
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
export function browserBoth(input: string, output: string, options: TplOptions = {}) {
|
|
159
|
-
return Promise.all([
|
|
160
|
-
browserTpl(input, output, { format: "esm", ...options }),
|
|
161
|
-
browserTpl(input, output, { format: "umd", ...options })
|
|
162
|
-
]);
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
export function nodeBoth(input: string, output: string, options: TplOptions = {}) {
|
|
166
|
-
return Promise.all([
|
|
167
|
-
nodeTpl(input, output, { format: "esm", ...options }),
|
|
168
|
-
nodeTpl(input, output, { format: "cjs", ...options })
|
|
169
|
-
]);
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
export function bothTpl(input: string, output: string, options: TplOptions = {}) {
|
|
173
|
-
return Promise.all([
|
|
174
|
-
browserBoth(input, output, { ...options }),
|
|
175
|
-
nodeTpl(input, output, { format: "cjs", ...options })
|
|
176
|
-
]);
|
|
177
|
-
}
|
|
1
|
+
import * as process from "process";
|
|
2
|
+
import { readFileSync } from "fs";
|
|
3
|
+
import * as path from "path";
|
|
4
|
+
import * as esbuild from "esbuild";
|
|
5
|
+
import type { BuildOptions, Format, Loader, Plugin } from "esbuild";
|
|
6
|
+
import { umdWrapper } from "esbuild-plugin-umd-wrapper";
|
|
7
|
+
import * as copyStaticFiles from "esbuild-copy-static-files";
|
|
8
|
+
import { inlineCSS } from "./inline-css.ts";
|
|
9
|
+
import { rebuildLogger } from "./rebuild-logger.ts";
|
|
10
|
+
|
|
11
|
+
export { copyStaticFiles };
|
|
12
|
+
|
|
13
|
+
export const pkg = JSON.parse(readFileSync(path.join(process.cwd(), "./package.json"), "utf8"));
|
|
14
|
+
export const NODE_MJS = pkg.type === "module" ? "js" : "mjs";
|
|
15
|
+
export const NODE_CJS = pkg.type === "module" ? "cjs" : "js";
|
|
16
|
+
|
|
17
|
+
interface BuildOptionsEx extends Omit<BuildOptions, "format"> {
|
|
18
|
+
format?: Format | "umd";
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export async function buildWatch(inputs: string[] | Record<string, string> | { in: string, out: string }[], config: BuildOptionsEx): Promise<void> {
|
|
22
|
+
const isDevelopment = process.argv.includes("--development");
|
|
23
|
+
const isWatch = process.argv.includes("--watch");
|
|
24
|
+
const isProduction = !isDevelopment;
|
|
25
|
+
|
|
26
|
+
config = {
|
|
27
|
+
entryPoints: inputs,
|
|
28
|
+
format: config.format ?? "esm",
|
|
29
|
+
bundle: true,
|
|
30
|
+
minify: isProduction,
|
|
31
|
+
sourcemap: true,
|
|
32
|
+
external: [
|
|
33
|
+
...config.external ?? []
|
|
34
|
+
],
|
|
35
|
+
...config,
|
|
36
|
+
loader: {
|
|
37
|
+
...config.loader
|
|
38
|
+
},
|
|
39
|
+
outExtension: {
|
|
40
|
+
...config.outExtension
|
|
41
|
+
},
|
|
42
|
+
banner: {
|
|
43
|
+
...config.banner
|
|
44
|
+
},
|
|
45
|
+
footer: {
|
|
46
|
+
...config.footer
|
|
47
|
+
},
|
|
48
|
+
plugins: [
|
|
49
|
+
...(isWatch ? [rebuildLogger(config)] : []),
|
|
50
|
+
...config.plugins ?? [],
|
|
51
|
+
inlineCSS()
|
|
52
|
+
],
|
|
53
|
+
nodePaths: [
|
|
54
|
+
...config.nodePaths ?? []
|
|
55
|
+
]
|
|
56
|
+
};
|
|
57
|
+
const ctx = await esbuild.context(config as BuildOptions);
|
|
58
|
+
|
|
59
|
+
if (isWatch) {
|
|
60
|
+
await ctx.watch();
|
|
61
|
+
} else {
|
|
62
|
+
if (isDevelopment && Array.isArray(config.entryPoints)) {
|
|
63
|
+
// eslint-disable-next-line no-console
|
|
64
|
+
console.log("Start: ", config.entryPoints[0], config.outfile);
|
|
65
|
+
}
|
|
66
|
+
await ctx.rebuild();
|
|
67
|
+
await ctx.dispose();
|
|
68
|
+
if (isDevelopment && Array.isArray(config.entryPoints)) {
|
|
69
|
+
// eslint-disable-next-line no-console
|
|
70
|
+
console.log("Stop: ", config.entryPoints[0], config.outfile);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export type TplOptions = {
|
|
76
|
+
format?: Format | "umd";
|
|
77
|
+
globalName?: string;
|
|
78
|
+
libraryName?: string;
|
|
79
|
+
keepNames?: boolean;
|
|
80
|
+
external?: string[];
|
|
81
|
+
plugins?: Plugin[];
|
|
82
|
+
loader?: { [ext: string]: Loader };
|
|
83
|
+
supported?: Record<string, boolean>;
|
|
84
|
+
alias?: Record<string, string>;
|
|
85
|
+
define?: { [key: string]: string };
|
|
86
|
+
packages?: "bundle" | "external" | "auto";
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
function autoExternal(external?: string[]): string[] {
|
|
90
|
+
return [
|
|
91
|
+
...pkg.dependencies ? Object.keys(pkg.dependencies) : [], ...pkg.peerDependencies ? Object.keys(pkg.peerDependencies) : [],
|
|
92
|
+
...external ?? []
|
|
93
|
+
];
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export function browserTpl(input: string, output: string, options: TplOptions = {}) {
|
|
97
|
+
options.format = options.format ?? "esm";
|
|
98
|
+
|
|
99
|
+
return buildWatch([input], {
|
|
100
|
+
format: options.format,
|
|
101
|
+
external: options.external ?? [],
|
|
102
|
+
outfile: `${output}.${options.format === "esm" ? "js" : `${options.format}.js`}`,
|
|
103
|
+
platform: "browser",
|
|
104
|
+
target: "es2022",
|
|
105
|
+
globalName: options.globalName,
|
|
106
|
+
keepNames: options.keepNames,
|
|
107
|
+
plugins: options.format === "umd" ? [umdWrapper({ libraryName: options.libraryName }) as Plugin, ...options.plugins ?? []] : options.plugins,
|
|
108
|
+
alias: options.alias,
|
|
109
|
+
define: options.define,
|
|
110
|
+
loader: options.loader,
|
|
111
|
+
supported: options.supported,
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export function nodeTpl(input: string, output: string, options: TplOptions = {}) {
|
|
116
|
+
options.format = options.format ?? "esm";
|
|
117
|
+
options.packages = options.packages ?? "external";
|
|
118
|
+
if (options.packages === "auto") {
|
|
119
|
+
options.external = autoExternal(options.external);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
return buildWatch([input], {
|
|
123
|
+
format: options.format,
|
|
124
|
+
external: options.external ?? [],
|
|
125
|
+
outfile: `${output}.${options.format === "esm" ? NODE_MJS : NODE_CJS}`,
|
|
126
|
+
platform: "node",
|
|
127
|
+
target: "node22",
|
|
128
|
+
packages: options.packages === "auto" ? "bundle" : options.packages,
|
|
129
|
+
globalName: options.globalName,
|
|
130
|
+
keepNames: options.keepNames,
|
|
131
|
+
plugins: options.plugins,
|
|
132
|
+
alias: options.alias,
|
|
133
|
+
define: options.define,
|
|
134
|
+
loader: options.loader,
|
|
135
|
+
supported: options.supported,
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
export function neutralTpl(input: string, output: string, options: TplOptions = {}) {
|
|
140
|
+
options.format = options.format ?? "esm";
|
|
141
|
+
|
|
142
|
+
return buildWatch([input], {
|
|
143
|
+
format: options.format,
|
|
144
|
+
external: options.external ?? [],
|
|
145
|
+
outfile: `${output}.${options.format === "esm" ? "js" : `${options.format}.js`}`,
|
|
146
|
+
platform: "neutral",
|
|
147
|
+
target: "es2022",
|
|
148
|
+
globalName: options.globalName,
|
|
149
|
+
keepNames: options.keepNames,
|
|
150
|
+
plugins: options.format === "umd" ? [umdWrapper({ libraryName: options.libraryName }) as Plugin, ...options.plugins ?? []] : options.plugins,
|
|
151
|
+
alias: options.alias,
|
|
152
|
+
define: options.define,
|
|
153
|
+
loader: options.loader,
|
|
154
|
+
supported: options.supported,
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
export function browserBoth(input: string, output: string, options: TplOptions = {}) {
|
|
159
|
+
return Promise.all([
|
|
160
|
+
browserTpl(input, output, { format: "esm", ...options }),
|
|
161
|
+
browserTpl(input, output, { format: "umd", ...options })
|
|
162
|
+
]);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
export function nodeBoth(input: string, output: string, options: TplOptions = {}) {
|
|
166
|
+
return Promise.all([
|
|
167
|
+
nodeTpl(input, output, { format: "esm", ...options }),
|
|
168
|
+
nodeTpl(input, output, { format: "cjs", ...options })
|
|
169
|
+
]);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
export function bothTpl(input: string, output: string, options: TplOptions = {}) {
|
|
173
|
+
return Promise.all([
|
|
174
|
+
browserBoth(input, output, { ...options }),
|
|
175
|
+
nodeTpl(input, output, { format: "cjs", ...options })
|
|
176
|
+
]);
|
|
177
|
+
}
|
package/src/exclude-sourcemap.ts
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
import { readFile } from "fs/promises";
|
|
2
|
-
import type { PluginBuild, Plugin } from "esbuild";
|
|
3
|
-
|
|
4
|
-
export interface ExcludeSourcemapOptions {
|
|
5
|
-
filter: RegExp;
|
|
6
|
-
}
|
|
7
|
-
export function excludeSourcemap(opts: ExcludeSourcemapOptions): Plugin {
|
|
8
|
-
return {
|
|
9
|
-
name: "exclude-sourcemap",
|
|
10
|
-
|
|
11
|
-
setup(build: PluginBuild) {
|
|
12
|
-
build.onLoad({ filter: opts.filter }, async args => {
|
|
13
|
-
return {
|
|
14
|
-
contents: await readFile(args.path, "utf8") + "\n//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIiJdLCJtYXBwaW5ncyI6IkEifQ==",
|
|
15
|
-
loader: "default",
|
|
16
|
-
};
|
|
17
|
-
});
|
|
18
|
-
},
|
|
19
|
-
};
|
|
20
|
-
}
|
|
1
|
+
import { readFile } from "fs/promises";
|
|
2
|
+
import type { PluginBuild, Plugin } from "esbuild";
|
|
3
|
+
|
|
4
|
+
export interface ExcludeSourcemapOptions {
|
|
5
|
+
filter: RegExp;
|
|
6
|
+
}
|
|
7
|
+
export function excludeSourcemap(opts: ExcludeSourcemapOptions): Plugin {
|
|
8
|
+
return {
|
|
9
|
+
name: "exclude-sourcemap",
|
|
10
|
+
|
|
11
|
+
setup(build: PluginBuild) {
|
|
12
|
+
build.onLoad({ filter: opts.filter }, async args => {
|
|
13
|
+
return {
|
|
14
|
+
contents: await readFile(args.path, "utf8") + "\n//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIiJdLCJtYXBwaW5ncyI6IkEifQ==",
|
|
15
|
+
loader: "default",
|
|
16
|
+
};
|
|
17
|
+
});
|
|
18
|
+
},
|
|
19
|
+
};
|
|
20
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
export * from "./build.ts";
|
|
2
|
-
export * from "./exclude-sourcemap.ts";
|
|
3
|
-
export * from "./problem-matcher.ts";
|
|
4
|
-
export * from "./rebuild-logger.ts";
|
|
5
|
-
export * from "./remove-strict.ts";
|
|
6
|
-
export * from "./inline-css.ts";
|
|
7
|
-
export * from "./vite-utils.ts";
|
|
8
|
-
export * from "./package-version-plugin.ts";
|
|
1
|
+
export * from "./build.ts";
|
|
2
|
+
export * from "./exclude-sourcemap.ts";
|
|
3
|
+
export * from "./problem-matcher.ts";
|
|
4
|
+
export * from "./rebuild-logger.ts";
|
|
5
|
+
export * from "./remove-strict.ts";
|
|
6
|
+
export * from "./inline-css.ts";
|
|
7
|
+
export * from "./vite-utils.ts";
|
|
8
|
+
export * from "./package-version-plugin.ts";
|
package/src/inline-css.ts
CHANGED
|
@@ -1,44 +1,44 @@
|
|
|
1
|
-
import type { PluginBuild, Plugin } from "esbuild";
|
|
2
|
-
import path from "path";
|
|
3
|
-
import crypto from "crypto";
|
|
4
|
-
import { readFile } from "fs/promises";
|
|
5
|
-
|
|
6
|
-
export function inlineCSS(options = {}) {
|
|
7
|
-
return {
|
|
8
|
-
name: "inline-css",
|
|
9
|
-
|
|
10
|
-
setup(build: PluginBuild) {
|
|
11
|
-
|
|
12
|
-
build.onLoad({ filter: /\.(css)$/ }, async (args) => {
|
|
13
|
-
if (build.initialOptions.platform === "browser") {
|
|
14
|
-
const sourcePath = path.resolve(args.path);
|
|
15
|
-
const sourceJS = await generateInjectCSS(sourcePath);
|
|
16
|
-
return {
|
|
17
|
-
contents: sourceJS,
|
|
18
|
-
loader: "js"
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
});
|
|
22
|
-
},
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
async function generateInjectCSS(sourcePath: string) {
|
|
27
|
-
const styleID = sha256(sourcePath);
|
|
28
|
-
const sourceCSS = await readFile(sourcePath, "utf8");
|
|
29
|
-
|
|
30
|
-
return `(function(){
|
|
31
|
-
if (!document.getElementById('${styleID}')) {
|
|
32
|
-
var e = document.createElement('style');
|
|
33
|
-
e.id = '${styleID}';
|
|
34
|
-
e.textContent = \`${sourceCSS.split("\\25").join("\\x15")}\`;
|
|
35
|
-
document.head.appendChild(e);
|
|
36
|
-
}
|
|
37
|
-
})();`;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
function sha256(sourcePath: string) {
|
|
41
|
-
const hash = crypto.createHash("sha256").update(sourcePath).digest("hex");
|
|
42
|
-
return hash.slice(0, 8); // Use the first 8 characters of the hash
|
|
43
|
-
}
|
|
44
|
-
|
|
1
|
+
import type { PluginBuild, Plugin } from "esbuild";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import crypto from "crypto";
|
|
4
|
+
import { readFile } from "fs/promises";
|
|
5
|
+
|
|
6
|
+
export function inlineCSS(options = {}) {
|
|
7
|
+
return {
|
|
8
|
+
name: "inline-css",
|
|
9
|
+
|
|
10
|
+
setup(build: PluginBuild) {
|
|
11
|
+
|
|
12
|
+
build.onLoad({ filter: /\.(css)$/ }, async (args) => {
|
|
13
|
+
if (build.initialOptions.platform === "browser") {
|
|
14
|
+
const sourcePath = path.resolve(args.path);
|
|
15
|
+
const sourceJS = await generateInjectCSS(sourcePath);
|
|
16
|
+
return {
|
|
17
|
+
contents: sourceJS,
|
|
18
|
+
loader: "js"
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
async function generateInjectCSS(sourcePath: string) {
|
|
27
|
+
const styleID = sha256(sourcePath);
|
|
28
|
+
const sourceCSS = await readFile(sourcePath, "utf8");
|
|
29
|
+
|
|
30
|
+
return `(function(){
|
|
31
|
+
if (!document.getElementById('${styleID}')) {
|
|
32
|
+
var e = document.createElement('style');
|
|
33
|
+
e.id = '${styleID}';
|
|
34
|
+
e.textContent = \`${sourceCSS.split("\\25").join("\\x15")}\`;
|
|
35
|
+
document.head.appendChild(e);
|
|
36
|
+
}
|
|
37
|
+
})();`;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function sha256(sourcePath: string) {
|
|
41
|
+
const hash = crypto.createHash("sha256").update(sourcePath).digest("hex");
|
|
42
|
+
return hash.slice(0, 8); // Use the first 8 characters of the hash
|
|
43
|
+
}
|
|
44
|
+
|