-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathrollup.config.js
More file actions
99 lines (95 loc) · 2.45 KB
/
rollup.config.js
File metadata and controls
99 lines (95 loc) · 2.45 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
88
89
90
91
92
93
94
95
96
97
98
99
const ts = require('typescript');
const terser = require('@rollup/plugin-terser');
const dts = require('rollup-plugin-dts').default;
function transpileTypeScript() {
return {
name: 'transpile-typescript',
transform(code, id) {
if (!id.endsWith('.ts')) return null;
const result = ts.transpileModule(code, {
fileName: id,
compilerOptions: {
target: ts.ScriptTarget.ES2019,
module: ts.ModuleKind.ESNext,
esModuleInterop: true,
sourceMap: true
}
});
return {
code: result.outputText,
map: result.sourceMapText ? JSON.parse(result.sourceMapText) : null
};
}
};
}
function moduleBuild(name, input, external = []) {
const isCoreExternal = (id) => id === './Ity' || /[/\\]Ity(\.ts)?$/.test(id);
return {
input,
external(id) {
return isCoreExternal(id) || external.includes(id);
},
plugins: [transpileTypeScript()],
output: [
{
file: `dist/${name}.cjs.js`,
format: 'cjs',
exports: 'named',
sourcemap: true,
paths(id) {
if (isCoreExternal(id)) return './ity.cjs.js';
return id;
}
},
{
file: `dist/${name}.esm.mjs`,
format: 'es',
sourcemap: true,
paths(id) {
if (isCoreExternal(id)) return './ity.esm.mjs';
return id;
}
}
]
};
}
function dtsBuild(name, outputName = name) {
return {
input: `types/${name}.d.ts`,
plugins: [dts()],
output: {
file: `dist/${outputName}.d.ts`,
format: 'es'
}
};
}
module.exports = [
{
input: 'Ity.ts',
plugins: [transpileTypeScript()],
output: [
{ file: 'dist/ity.js', format: 'iife', name: 'Ity', exports: 'named', sourcemap: true },
{ file: 'dist/ity.cjs.js', format: 'cjs', exports: 'named', sourcemap: true },
{ file: 'dist/ity.esm.js', format: 'es', sourcemap: true },
{ file: 'dist/ity.esm.mjs', format: 'es', sourcemap: true }
]
},
{
input: 'Ity.ts',
plugins: [transpileTypeScript(), terser()],
output: {
file: 'dist/ity.min.js',
format: 'iife',
name: 'Ity',
exports: 'named',
sourcemap: true
}
},
moduleBuild('query', 'query.ts', ['./Ity']),
moduleBuild('forms', 'forms.ts', ['./Ity']),
moduleBuild('react', 'react.ts', ['./Ity', 'react']),
dtsBuild('Ity', 'ity'),
dtsBuild('query'),
dtsBuild('forms'),
dtsBuild('react')
];