-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.ts
59 lines (53 loc) · 1.58 KB
/
rollup.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
import { nodeResolve } from "@rollup/plugin-node-resolve";
import commonjs from "@rollup/plugin-commonjs";
import esbuild from "rollup-plugin-esbuild";
import json from "@rollup/plugin-json";
import { defineConfig } from "rollup";
import manifest from "./manifest.json"
import crypto from 'crypto';
import path from 'path';
import fs from "fs"
const hash = crypto.createHash('sha256');
async function calculateHash(folderPath: string) {
const files = await readDirRecursive(folderPath);
for (const file of files) {
const content = await fs.promises.readFile(file);
hash.update(content);
}
return hash.digest('hex').substring(0, 8);
}
async function readDirRecursive(folderPath: string): Promise<string[]> {
const files: string[] = [];
const dirents = await fs.promises.readdir(folderPath, { withFileTypes: true });
for (const dirent of dirents) {
const fullPath = path.join(folderPath, dirent.name);
if (dirent.isDirectory()) {
files.push(...await readDirRecursive(fullPath));
} else {
files.push(fullPath);
}
}
return files;
}
(async function main() {
manifest.plugin.hash = `${await calculateHash("src")}`
fs.writeFileSync("./manifest.json", JSON.stringify(manifest, null, 2))
})()
export default () => {
return defineConfig({
input: `src/index.tsx`,
output: [
{
file: `dist/${manifest.name}.js`,
format: "cjs",
strict: false,
},
],
plugins: [
nodeResolve(),
commonjs(),
json(),
esbuild({ minify: true, target: "ES2020" }),
],
});
};