generated from alexk111/node-red-node-typescript-starter
-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
rollup.config.editor.js
71 lines (62 loc) · 1.68 KB
/
rollup.config.editor.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
import fs from "fs";
import glob from "glob";
import path from "path";
import typescript from "@rollup/plugin-typescript";
import packageJson from "./package.json";
const allNodeTypes = Object.keys(packageJson["node-red"].nodes);
const htmlWatch = () => {
return {
name: "htmlWatch",
load(id) {
const editorDir = path.dirname(id);
const htmlFiles = glob.sync(path.join(editorDir, "*.html"));
htmlFiles.map((file) => this.addWatchFile(file));
},
};
};
const htmlBundle = () => {
return {
name: "htmlBundle",
renderChunk(code, chunk, _options) {
const editorDir = path.dirname(chunk.facadeModuleId);
const htmlFiles = glob.sync(path.join(editorDir, "*.html"));
const htmlContents = htmlFiles.map((fPath) => fs.readFileSync(fPath));
code =
'<script type="text/javascript">\n' +
code +
"\n" +
"</script>\n" +
htmlContents.join("\n");
return {
code,
map: { mappings: "" },
};
},
};
};
const makePlugins = (nodeType) => [
htmlWatch(),
typescript({
lib: ["es5", "es6", "dom"],
include: [
`src/nodes/${nodeType}/${nodeType}.html/**/*.ts`,
`src/nodes/${nodeType}/shared/**/*.ts`,
],
target: "es5",
tsconfig: false,
noEmitOnError: process.env.ROLLUP_WATCH ? false : true,
}),
htmlBundle(),
];
const makeConfigItem = (nodeType) => ({
input: `src/nodes/${nodeType}/${nodeType}.html/index.ts`,
output: {
file: `dist/nodes/${nodeType}/${nodeType}.html`,
format: "iife",
},
plugins: makePlugins(nodeType),
watch: {
clearScreen: false,
},
});
export default allNodeTypes.map((nodeType) => makeConfigItem(nodeType));