forked from poirazis/bb-component-SuperTabs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrollup.config.mjs
More file actions
131 lines (123 loc) · 3.48 KB
/
Copy pathrollup.config.mjs
File metadata and controls
131 lines (123 loc) · 3.48 KB
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
import commonjs from "@rollup/plugin-commonjs"
import resolve from "@rollup/plugin-node-resolve"
import svelte from "rollup-plugin-svelte"
import { terser } from "rollup-plugin-terser"
import postcss from "rollup-plugin-postcss"
import svg from "rollup-plugin-svg"
import json from "rollup-plugin-json"
import nodePolyfills from "rollup-plugin-polyfill-node"
import copy2 from "rollup-plugin-copy2"
import tar from "tar"
import fs from "fs"
const pkg = JSON.parse(fs.readFileSync(new URL('./package.json', import.meta.url), 'utf8'))
import crypto from "crypto"
import { validate } from "@budibase/backend-core/plugins"
const ignoredWarnings = [
"unused-export-let",
"css-unused-selector",
"module-script-reactive-declaration",
"a11y-no-onchange",
]
// Custom plugin to clean the dist folder before building
const clean = () => ({
buildStart() {
const dist = "./dist/"
if (fs.existsSync(dist)) {
fs.readdirSync(dist).forEach(path => {
if (path.endsWith(".tar.gz")) {
fs.unlinkSync(dist + path)
}
})
}
},
})
// Custom plugin to hash the JS bundle and write it in the schema
const hash = () => ({
writeBundle() {
// Generate JS hash
const fileBuffer = fs.readFileSync("dist/plugin.min.js")
const hashSum = crypto.createHash("sha1")
hashSum.update(fileBuffer)
const hex = hashSum.digest("hex")
// Read and parse existing schema from dist folder
const schema = JSON.parse(fs.readFileSync("./dist/schema.json", "utf8"))
// Write updated schema to dist folder, pretty printed as JSON again
const newSchema = {
...schema,
hash: hex,
version: pkg.version,
}
fs.writeFileSync("./dist/schema.json", JSON.stringify(newSchema, null, 2))
},
})
// Custom plugin to bundle up our files after building
const bundle = () => ({
async writeBundle() {
const bundleName = `${pkg.name}-${pkg.version}.tar.gz`
return tar
.c({ gzip: true, cwd: "dist" }, [
"plugin.min.js",
"schema.json",
"package.json",
])
.pipe(fs.createWriteStream(`dist/${bundleName}`))
},
})
const validateSchema = () => ({
buildStart() {
const schema = fs.readFileSync("schema.json", "utf8")
validate(JSON.parse(schema))
}
})
export default {
input: "index.js",
external: (id) => id === "svelte" || id.startsWith("svelte/"),
output: {
sourcemap: process.env.ROLLUP_WATCH ? "inline" : false,
format: "iife",
file: "dist/plugin.min.js",
name: "plugin",
globals: (id) => {
if (id === "svelte/store") return "svelteStore"
if (id === "svelte/transition") return "svelteTransition"
if (id === "svelte/animate") return "svelteAnimate"
if (id === "svelte/motion") return "svelteMotion"
if (id === "svelte/easing") return "svelteEasing"
if (id.includes("/internal")) return "svelteInternal"
return "svelte"
},
},
plugins: [
validateSchema(),
clean(),
svelte({
emitCss: true,
compilerOptions: {
compatibility: {
componentApi: 4,
},
},
onwarn: (warning, handler) => {
// Ignore some warnings
if (!ignoredWarnings.includes(warning.code)) {
handler(warning)
}
},
}),
postcss(),
commonjs(),
nodePolyfills(),
resolve({
preferBuiltins: true,
browser: true,
}),
svg(),
json(),
terser(),
copy2.default({
assets: ["schema.json", "package.json"],
}),
hash(),
bundle(),
],
}