/
build.ts
115 lines (107 loc) · 2.7 KB
/
build.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import json from "@rollup/plugin-json";
import typescript from "@wessberg/rollup-plugin-ts";
import path from "path";
import { rollup } from "rollup";
import { terser } from "rollup-plugin-terser";
const packagesDirectory = path.resolve(__dirname, "./../packages");
const packages = [
{
name: "purgecss",
external: [
"postcss",
"postcss-selector-parser",
"glob",
"path",
"fs",
"util",
],
},
{
name: "postcss-purgecss",
external: ["postcss", "purgecss"],
},
{
name: "purgecss-webpack-plugin",
external: ["fs", "path", "purgecss", "webpack", "webpack-sources"],
},
{
name: "rollup-plugin-purgecss",
external: ["fs", "rollup-pluginutils", "purgecss"],
},
{
name: "gulp-purgecss",
external: ["through2", "plugin-error", "purgecss", "glob"],
},
{
name: "purgecss-from-html",
external: ["parse5", "parse5-htmlparser2-tree-adapter"],
},
{
name: "purgecss-from-pug",
external: ["pug-lexer"],
},
{
name: "purgecss-from-jsx",
external: ["acorn", "acorn-walk", "acorn-jsx", "acorn-jsx-walk"],
},
{
name: "purgecss-from-tsx",
external: ["acorn", "purgecss-from-jsx", "typescript"],
}
];
async function build(): Promise<void> {
for (const pkg of packages) {
const bundle = await rollup({
input: path.resolve(packagesDirectory, `./${pkg.name}/src/index.ts`),
plugins: [typescript({}), terser()],
external: pkg.external,
});
await bundle.write({
file: path.resolve(
packagesDirectory,
pkg.name,
`./lib/${pkg.name}.esm.js`
),
format: "esm",
});
await bundle.write({
exports: "auto",
file: path.resolve(packagesDirectory, pkg.name, `./lib/${pkg.name}.js`),
format: "cjs",
});
}
// grunt plugin
const gruntBundle = await rollup({
input: path.resolve(packagesDirectory, "./grunt-purgecss/src/index.ts"),
plugins: [typescript({}), terser()],
external: ["purgecss"],
});
await gruntBundle.write({
exports: "auto",
file: path.resolve(
packagesDirectory,
"grunt-purgecss",
"./tasks/purgecss.js"
),
format: "cjs",
});
// command line interface
const cliBundle = await rollup({
input: path.resolve(packagesDirectory, "./purgecss/src/bin.ts"),
plugins: [json(), typescript({ transpileOnly: true }), terser()],
external: [...packages[0].external, "commander"]
});
await cliBundle.write({
banner: "#!/usr/bin/env node",
exports: "auto",
file: path.resolve(packagesDirectory, "purgecss", "./bin/purgecss.js"),
format: "cjs"
})
}
(async (): Promise<void> => {
try {
await build();
} catch (e) {
console.error(e);
}
})();