-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.ts
65 lines (60 loc) · 1.51 KB
/
vite.config.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import { defineConfig } from "vite";
import { svelte } from "@sveltejs/vite-plugin-svelte";
import { transform } from "esbuild";
import pkg from "./package.json";
export default defineConfig({
plugins: [
svelte({
compilerOptions: {
customElement: true,
},
}),
copyrightNotice(),
minifyEs(),
],
build: {
outDir: "dist",
emptyOutDir: true,
lib: {
entry: "src/components/index.ts",
formats: ["es", "esm", "umd"] as any,
name: pkg.name.replace(/-./g, (char) => char[1].toUpperCase()),
fileName: (format) =>
({
es: `${pkg.name}.js`,
esm: `${pkg.name}.min.js`,
umd: `${pkg.name}.umd.js`,
}[format]),
},
},
});
function minifyEs() {
return {
name: "minifyEs",
renderChunk: {
order: "post" as const,
async handler(code, chunk, outputOptions) {
if (
outputOptions.format === "es" &&
chunk.fileName.endsWith(".min.js")
) {
return await transform(code, { minify: true });
}
return code;
},
},
};
}
function copyrightNotice() {
return {
name: "copyright-notice",
renderChunk(code) {
const copyright = `/*!
Copyright (c) 2023 sjquant. All rights reserved.
This software is part of the adsense-popover project: https://github.com/sjquant/adsense-popover
Licensed under the MIT License. See the LICENSE file in the project root for full license information.
*/\n`;
return `${copyright}${code}`;
},
};
}