This repository has been archived by the owner on Sep 29, 2022. It is now read-only.
generated from alexk111/node-red-node-typescript-starter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.editor.js
62 lines (54 loc) · 1.79 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
import fs from 'fs';
import glob from 'glob';
import packageJson from './package.json';
import path from 'path';
import typescript from '@rollup/plugin-typescript';
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').replace(/\\/g, '/'));
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/${nodeType}/${nodeType}.html/**/*.ts`, `src/${nodeType}/shared/**/*.ts`, 'src/shared/**/*.ts'],
target: 'ES2019',
tsconfig: false,
noEmitOnError: process.env.ROLLUP_WATCH ? false : true,
}),
htmlBundle(),
];
const makeConfigItem = (nodeType) => ({
input: `src/${nodeType}/${nodeType}.html/index.ts`,
output: {
file: `dist/${nodeType}/${nodeType}.html`,
format: 'iife',
},
plugins: makePlugins(nodeType),
watch: {
clearScreen: false,
},
});
export default allNodeTypes.map((nodeType) => makeConfigItem(nodeType));