-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy pathrollup.config.ts
More file actions
68 lines (62 loc) · 2.44 KB
/
rollup.config.ts
File metadata and controls
68 lines (62 loc) · 2.44 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
import alias from '@rollup/plugin-alias';
import esbuild from 'rollup-plugin-esbuild';
import terser from '@rollup/plugin-terser';
import { dts } from 'rollup-plugin-dts';
import { globSync } from 'glob';
import { dirname, resolve } from 'node:path';
import { fileURLToPath } from 'node:url';
const outputDir = (input: string) => input.replace(/^src/g, 'dist').replace(/\/[^/]*$/g, '');
const replacePath = (input: string) => input.replace(/(^src\/|\.ts$)/g, '');
const ts = () => {
const plugins = [
alias({ entries: [{ find: '@', replacement: resolve(dirname(fileURLToPath(import.meta.url)), 'src') }] }),
esbuild({ minify: false, target: 'es2021' }),
terser()
];
const config = (input: string | Record<string, string>, outputDir: string) => ({
input,
output: [
{ dir: outputDir, format: 'es' },
{ dir: outputDir, format: 'cjs', entryFileNames: '[name].cjs' }
],
plugins
});
return [
config('src/index.ts', 'dist'),
config('src/plugin.ts', 'dist'),
config('src/timezone.ts', 'dist'),
config(Object.fromEntries(globSync('src/numerals/**/*.ts').map(input => [replacePath(input), input])), 'dist'),
globSync('src/locales/**/*.ts').map(input => config(input, outputDir(input))),
globSync('src/plugins/**/*.ts').map(input => config(input, outputDir(input))),
config(Object.fromEntries(globSync('src/timezones/**/*.ts').map(input => [replacePath(input), input])), 'dist')
].flat();
};
const types = () => {
const plugins = [
alias({ entries: [{ find: '@', replacement: resolve(dirname(fileURLToPath(import.meta.url)), 'src') }] }),
dts()
];
const config = (input: string | Record<string, string>, outputDir: string) => ({
input,
output: { dir: outputDir },
plugins
});
return [
config('src/index.ts', 'dist'),
config('src/plugin.ts', 'dist'),
config('src/timezone.ts', 'dist'),
config(Object.fromEntries(globSync('src/numerals/**/*.ts').map(input => [replacePath(input), input])), 'dist'),
globSync('src/locales/**/*.ts').map(input => config(input, outputDir(input))),
globSync('src/plugins/**/*.ts').map(input => config(input, outputDir(input))),
config(Object.fromEntries(globSync('src/timezones/**/*.ts').map(input => [replacePath(input), input])), 'dist')
].flat();
};
export default (args: Record<string, string>) => {
if (args['config-ts']) {
return ts();
}
if (args['config-types']) {
return types();
}
return [...ts(), ...types()];
};