This repository was archived by the owner on Oct 27, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrollup.config.js
130 lines (116 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
import commonjs from '@rollup/plugin-commonjs';
import resolve from '@rollup/plugin-node-resolve';
import command from 'rollup-plugin-command';
import typescript from 'rollup-plugin-typescript';
import globFiles from 'rollup-plugin-glob-files';
import nodePath from 'path';
import { readdirSync } from 'fs';
import { string } from 'rollup-plugin-string';
import image from '@rollup/plugin-image';
import json from '@rollup/plugin-json';
const sourcemap = false;
const prod = process.env.NODE_ENV === 'production';
const watching = process.env.ROLLUP_WATCH;
const testDir = process.env.VERSATILE_FILTER || ``;
const testPattern = nodePath.resolve(testDir, `**/*.test.ts`);
const sharedOutputOptions = (dir = null) => {
const paths = id => id.startsWith(`driza`) && id.replace('driza', '..');
if (dir === `compiler`) paths = undefined;
return {
paths,
sourcemap,
};
};
const external = (runtime = false) => id => (runtime ? false : id[0] !== '.' && !nodePath.isAbsolute(id));
const globalPlugins = (dir, oldDir, disable) => [
resolve({
preferBuiltins: true,
browser: dir !== `compiler`,
}),
commonjs(),
typescript({
typescript: require('typescript'),
}),
image(),
json(),
string({ include: [`**/*txt`, `**/*.xml`, `**/*.html`, `./dist/index.js`] }),
prod &&
!disable &&
command([`node scripts/add-package-json.js "${dir}"`, `node scripts/add-ts-definition.js "${dir}" "${oldDir || dir}"`], {
exitOnFail: !watching,
}),
];
const generateOutputOptions = options => [
{
...options,
file: options.file + `.js`,
format: `cjs`,
},
{
...options,
file: options.file + `.mjs`,
format: `esm`,
},
];
const testRound = {
input: `globbed-tests.ts`,
output: { file: `dist/build.js`, format: 'cjs' },
plugins: [
globFiles({
file: `globbed-tests.ts`,
include: testPattern,
justImport: true,
}),
...globalPlugins(),
command(`zip-tap-reporter node dist/build.js`, { exitOnFail: !watching }),
],
external: external(),
};
const compiler = {
input: `src/compiler/index.ts`,
output: generateOutputOptions({
file: `compiler/index`,
...sharedOutputOptions(),
}),
plugins: globalPlugins(`compiler`),
external: external(),
};
const platforms = {
input: `src/platforms/index.ts`,
output: generateOutputOptions({
file: `platforms/index`,
...sharedOutputOptions(),
}),
plugins: globalPlugins(`platforms`),
external: external(),
};
const cli = {
input: `cli/index.ts`,
output: generateOutputOptions({
file: `dist/cli`,
...sharedOutputOptions(),
}),
plugins: globalPlugins(null, null, true),
external: external(),
};
const index = {
input: `src/runtime/index.ts`,
output: generateOutputOptions({
file: `dist/index`,
...sharedOutputOptions(`index`),
}),
plugins: globalPlugins(null, null, true),
external: external(true),
};
const runtimes = readdirSync(`src/runtime`, 'utf-8')
.filter(dir => dir.indexOf(`.`) === -1 && dir !== `index`)
.map(dir => ({
input: `src/runtime/${dir}/index.ts`,
output: generateOutputOptions({
file: `${dir}/index`,
...sharedOutputOptions(dir),
}),
plugins: globalPlugins(dir, `runtime/${dir}`),
external: external(true),
}));
export default prod ? [index, compiler, cli, platforms, ...runtimes] : [index, cli, platforms, testRound];