-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathrollup.config.js
142 lines (117 loc) · 3.19 KB
/
rollup.config.js
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
132
133
134
135
136
137
138
139
140
141
142
import resolve from "@rollup/plugin-node-resolve";
import commonjs from "@rollup/plugin-commonjs";
import livereload from "rollup-plugin-livereload";
import node from "@rollup/plugin-node-resolve";
// Svelte related
import svelte from "rollup-plugin-svelte";
import autoPreprocess from "svelte-preprocess";
// Minifier
import { terser } from "rollup-plugin-terser";
// Post CSS
import postcss from "rollup-plugin-postcss";
// Inline to single html
import htmlBundle from "rollup-plugin-html-bundle";
// Typescript
import typescript from "rollup-plugin-typescript";
//Image
import image from "@rollup/plugin-image";
//Rollup json plugin to use JSON packages
import json from '@rollup/plugin-json';
const production = !process.env.ROLLUP_WATCH;
export default [
// MAIN.JS
// The main JS for the UI, will built and then injected
// into the template as inline JS for compatibility reasons
{
input: "src/main.js",
output: {
format: "umd",
name: "ui",
file: "public/bundle.js",
},
plugins: [
// Svelte plugin
svelte({
// enable run-time checks when not in production
dev: !production,
preprocess: autoPreprocess(),
onwarn: (warning, handler) => {
const { code, frame } = warning;
if (code === "css-unused-selector" && frame.includes("shape")) return;
handler(warning);
},
}),
//Node
node(),
//dd
// Handle external dependencies and prepare
// the terrain for svelte later on
resolve({
browser: true,
dedupe: (importee) =>
importee === "svelte" || importee.startsWith("svelte/"),
extensions: [".svelte", ".mjs", ".js", ".json", ".node", ".ts"],
}),
// Typescript
typescript({ sourceMap: !production }),
// Post CSS config
postcss({
extensions: [".css"],
}),
//Image plugin
image(),
//JSON plugin
json(),
//Common JS plugin to import stuff that don't have default export
commonjs({
transformMixedEsModules: true
}),
// This inject the bundled version of main.js
// into the the template
htmlBundle({
template: "src/template.html",
target: "public/index.html",
inline: true,
}),
// If dev mode, serve and livereload
!production && serve(),
!production && livereload("public"),
// If prod mode, we minify
production && terser(),
],
watch: {
clearScreen: true,
},
},
// CODE.JS
// The part that communicate with Figma directly
// Communicate with main.js via event send/binding
{
input: "src/code.ts",
output: {
file: "public/code.js",
format: "iife",
name: "code",
},
plugins: [
typescript(),
resolve(),
commonjs({ transformMixedEsModules: true }),
production && terser(),
],
},
];
function serve() {
let started = false;
return {
writeBundle() {
if (!started) {
started = true;
require("child_process").spawn("npm", ["run", "start", "--", "--dev"], {
stdio: ["ignore", "inherit", "inherit"],
shell: true,
});
}
},
};
}