forked from sticker0ne/vue3-rich-accordion
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuildLibrary.ts
67 lines (59 loc) · 1.68 KB
/
buildLibrary.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
66
67
import path from "path";
import { fileURLToPath, URL } from "url";
import vue from "@vitejs/plugin-vue";
import * as fs from "fs";
import { build } from "vite";
import { exec } from "child_process";
import { compile } from "sass";
const envDir = "./env";
const envPrefix = "APP";
function clearDistFolder() {
fs.rmdirSync("./dist", { recursive: true });
}
async function buildLibrary() {
await build({
root: path.resolve(__dirname, "./src"),
base: "/foo/",
build: {
outDir: "../dist",
lib: {
entry: path.resolve(__dirname, "src/library/index.ts"),
name: "MyComponentLib",
fileName: format => `accordion-library.${format}.js`,
},
reportCompressedSize: true,
rollupOptions: {
external: ["vue", "./public/*"],
output: {
globals: {
vue: "Vue",
},
},
},
},
plugins: [vue({ reactivityTransform: true })],
resolve: {
alias: {
"@": fileURLToPath(new URL("./src", "file://" + __dirname)),
"~": fileURLToPath(new URL(".", "file://" + __dirname)),
},
},
envDir,
envPrefix,
});
}
function buildTypesDeclaration() {
exec("vue-tsc -p tsconfig.build-lib.json --declaration --emitDeclarationOnly");
}
function processStyles() {
fs.copyFileSync("./src/library/accordion/accordion-styles.scss", "./dist/accordion-library-styles.scss");
const compileResult = compile("./dist/accordion-library-styles.scss", { sourceMap: false });
fs.writeFileSync("./dist/accordion-library-styles.css", compileResult.css);
}
async function main() {
clearDistFolder();
buildTypesDeclaration();
await buildLibrary();
processStyles();
}
main();