-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrollup.config.js
More file actions
87 lines (76 loc) · 3.16 KB
/
Copy pathrollup.config.js
File metadata and controls
87 lines (76 loc) · 3.16 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
import babel from 'rollup-plugin-babel';
import node_resolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs'
import typescript from 'rollup-plugin-typescript2';
import root_import from 'rollup-plugin-root-import';
import polyfill from 'rollup-plugin-polyfill';
import real_transform from './rollup-plugin-real-transform';
import fs from 'fs';
const extensions = ['.js', '.ts'];
const ENTRY_POINTS_IN_DIR = './src/entry_points';
const ENTRY_POINTS_REAL_OUT_DIR = 'bin/real';
const ENTRY_POINTS_SIM_OUT_DIR = 'bin/sim';
function* findEntryPoints(dir) {
const subfiles = fs.readdirSync(dir, { withFileTypes: true });
const child_dirs = subfiles
.filter((x) => x.isDirectory())
.map((x) => dir + '/' + x.name);
for (const child_dir of child_dirs) {
yield* findEntryPoints(child_dir);
}
const child_files = subfiles
.filter((x) => x.name.endsWith('.ts'))
.map((x) => dir + '/' + x.name)
.map((x) => x.replace(ENTRY_POINTS_IN_DIR, ''));
yield* child_files;
}
const entry_points = [...findEntryPoints(ENTRY_POINTS_IN_DIR)]
.map(x => [x, x.includes("real")]);
/* uncomment this if you want to compile only some entry points */
// .filter(x => x.includes('sim'));
const external = ['trik_brick', 'trik_script', 'trik_mailbox', 'trik_threading'];
const globals = {
'trik_brick': 'brick',
'trik_script': 'script',
'trik_mailbox': 'mailbox',
'trik_threading': 'Threading' /* capital T? trik, are you serious? */
}
const config = [];
config.push(...entry_points.map(entry => {
const [name, is_real_bundle] = entry;
return {
input: ENTRY_POINTS_IN_DIR + name,
external,
output: [
{
file: (is_real_bundle ? ENTRY_POINTS_REAL_OUT_DIR : ENTRY_POINTS_SIM_OUT_DIR) + name.replace('.ts', '.js'),
format: 'iife',
globals
},
],
plugins: [
root_import({ root: 'src' }), /* used only for importing polyfills.
Typescript has it's own complicated module resolution mechanism and can't be tweaked much */
/* Polyfills are to be imported in each entry point. This convienment plugin does it */
polyfill(['/polyfills/index.js']),
commonjs(), /* needed for some libraries (for example cojejs) that are written in commonjs style */
node_resolve(),
typescript(),
babel({
exclude: 'node_modules/core-js/**',
extensions: extensions,
runtimeHelpers: true
}),
/* this will end code that prints stop marker so that remote-run.py would be able to detect script sucsessful termination */
real_transform({is_real_bundle})
],
onwarn: (warning, handeWarning) => {
// overwite the default warning function
const str = warning.toString();
/* This is used to trick babel and rollup, so eval usage is _kind_of_ justified. */
if (/Use of eval is strongly discouraged/.test(str)) return;
handeWarning(warning);
},
}
}));
export default config;