Skip to content

Commit 30cb2b9

Browse files
committed
added: more builds
1 parent 13f6cb3 commit 30cb2b9

File tree

1 file changed

+93
-45
lines changed

1 file changed

+93
-45
lines changed

rollup.config.js

Lines changed: 93 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,101 @@
1+
/* eslint-disable import/no-extraneous-dependencies */
12
import typescript from '@rollup/plugin-typescript';
2-
import { terser } from 'rollup-plugin-terser';
33
import resolve from '@rollup/plugin-node-resolve';
44
import cleanup from 'rollup-plugin-cleanup';
5+
import sourcemaps from 'rollup-plugin-sourcemaps';
56
import copy from 'rollup-plugin-copy';
7+
import { terser } from 'rollup-plugin-terser';
8+
9+
import { omit } from 'lodash';
610

711
import pkg from './package.json';
812

9-
export default {
10-
input: './src/index.ts',
11-
output: [
12-
{
13-
name: 'tryCatch',
14-
exports: 'named',
15-
file: pkg.module,
16-
format: 'es',
17-
sourcemap: true,
18-
},
19-
{
20-
name: 'tryCatch',
21-
exports: 'named',
22-
file: pkg.main,
23-
format: 'cjs',
24-
sourcemap: true,
25-
},
26-
{
27-
name: 'tryCatch',
28-
exports: 'named',
29-
file: pkg.browser,
30-
format: 'umd',
31-
sourcemap: true,
13+
const name = 'tryCatch';
14+
15+
const options = [
16+
{
17+
name,
18+
exports: 'named',
19+
file: pkg.module,
20+
format: 'es',
21+
env: 'production',
22+
sourcemap: true,
23+
},
24+
{
25+
name,
26+
exports: 'named',
27+
file: pkg.module,
28+
format: 'es',
29+
env: 'development',
30+
sourcemap: true,
31+
},
32+
{
33+
name,
34+
exports: 'named',
35+
file: pkg.main,
36+
format: 'cjs',
37+
env: 'production',
38+
sourcemap: true,
39+
},
40+
{
41+
name,
42+
exports: 'named',
43+
file: pkg.main,
44+
format: 'cjs',
45+
env: 'development',
46+
sourcemap: true,
47+
},
48+
{
49+
name,
50+
exports: 'named',
51+
file: pkg.browser,
52+
format: 'umd',
53+
env: 'production',
54+
sourcemap: true,
55+
},
56+
{
57+
name,
58+
exports: 'named',
59+
file: pkg.browser,
60+
format: 'umd',
61+
env: 'development',
62+
sourcemap: true,
63+
},
64+
];
65+
66+
function createRollupConfig(option) {
67+
const file = option.env
68+
? `${option.file.replace('.js', '')}.${option.env}.js`
69+
: option.file;
70+
const fileDt = option.env
71+
? `${option.file.replace('.js', '')}.${option.env}.d.ts`
72+
: option.file;
73+
74+
return {
75+
input: './src/index.ts',
76+
output: {
77+
...omit(option, ['env']),
78+
file,
3279
},
33-
],
34-
plugins: [
35-
typescript(),
36-
resolve(),
37-
terser(),
38-
cleanup({
39-
comments: 'none',
40-
}),
41-
copy({
42-
targets: [
43-
'try-catch.es.d.ts',
44-
'try-catch.cjs.d.ts',
45-
'try-catch.umd.d.ts',
46-
].map((typeDef) => ({
47-
src: './lib/try-catch.d.ts',
48-
dest: './lib',
49-
rename: typeDef,
50-
})),
51-
}),
52-
],
53-
};
80+
plugins: [
81+
typescript(),
82+
resolve(),
83+
cleanup({
84+
comments: 'none',
85+
}),
86+
sourcemaps(),
87+
option.env === 'production' && terser(),
88+
copy({
89+
targets: [
90+
{
91+
src: './lib/try-catch.d.ts',
92+
dest: '.',
93+
rename: fileDt,
94+
},
95+
],
96+
}),
97+
],
98+
};
99+
}
100+
101+
export default options.map((option) => createRollupConfig(option));

0 commit comments

Comments
 (0)