@@ -5,117 +5,125 @@ import replace from 'rollup-plugin-replace'
5
5
import commonjs from 'rollup-plugin-commonjs'
6
6
import { terser } from 'rollup-plugin-terser'
7
7
import { sizeSnapshot } from 'rollup-plugin-size-snapshot'
8
+ import esbuild from 'rollup-plugin-esbuild' // Used for TS transpiling
8
9
9
10
// get the package.json for the current package
10
11
const packageDir = path . join ( __filename , '..' )
11
12
const pkg = require ( `${ packageDir } /package.json` )
12
13
const external = [ ...Object . keys ( pkg . peerDependencies || { } ) ]
13
14
14
15
// name will be used as the global name exposed in the UMD bundles
15
- const generateRollupConfig = ( name , overrides = { } ) => [
16
+ const generateRollupConfig = ( { name, overrides, entryPoint } ) => {
17
+ overrides = overrides || { }
18
+ entryPoint = entryPoint || 'src/index.js'
16
19
// CommonJS
17
- {
18
- input : 'src/index.js' ,
19
- output : { file : `lib/${ pkg . name } .js` , format : 'cjs' , indent : false } ,
20
- external,
21
- plugins : [ babel ( ) , sizeSnapshot ( ) ] ,
22
- ...overrides
23
- } ,
24
-
25
- // ES
26
- {
27
- input : 'src/index.js' ,
28
- output : { file : `es/${ pkg . name } .js` , format : 'es' , indent : false } ,
29
- external,
30
- plugins : [ babel ( ) , sizeSnapshot ( ) ] ,
31
- ...overrides
32
- } ,
20
+ return [
21
+ {
22
+ input : entryPoint ,
23
+ output : { file : `lib/${ pkg . name } .js` , format : 'cjs' , indent : false } ,
24
+ external,
25
+ plugins : [ commonjs ( ) , esbuild ( ) , babel ( ) , sizeSnapshot ( ) ] ,
26
+ ...overrides
27
+ } ,
33
28
34
- // ES for Browsers
35
- {
36
- input : 'src/index.js' ,
37
- output : { file : `es/${ pkg . name } .mjs` , format : 'es' , indent : false } ,
38
- external,
39
- plugins : [
40
- commonjs ( ) ,
41
- nodeResolve ( {
42
- jsnext : true
43
- } ) ,
44
- replace ( {
45
- 'process.env.NODE_ENV' : JSON . stringify ( 'production' )
46
- } ) ,
47
- terser ( {
48
- compress : {
49
- pure_getters : true ,
50
- unsafe : true ,
51
- unsafe_comps : true ,
52
- warnings : false
53
- }
54
- } ) ,
55
- sizeSnapshot ( )
56
- ] ,
57
- ...overrides
58
- } ,
29
+ // ES
30
+ {
31
+ input : entryPoint ,
32
+ output : { file : `es/${ pkg . name } .js` , format : 'es' , indent : false } ,
33
+ external,
34
+ plugins : [ commonjs ( ) , esbuild ( ) , babel ( ) , sizeSnapshot ( ) ] ,
35
+ ...overrides
36
+ } ,
59
37
60
- // UMD Development
61
- {
62
- input : 'src/index.js' ,
63
- output : {
64
- file : `dist/${ pkg . name } .js` ,
65
- format : 'umd' ,
66
- name,
67
- indent : false
38
+ // ES for Browsers
39
+ {
40
+ input : entryPoint ,
41
+ output : { file : `es/${ pkg . name } .mjs` , format : 'es' , indent : false } ,
42
+ external,
43
+ plugins : [
44
+ commonjs ( ) ,
45
+ nodeResolve ( {
46
+ jsnext : true
47
+ } ) ,
48
+ esbuild ( ) ,
49
+ replace ( {
50
+ 'process.env.NODE_ENV' : JSON . stringify ( 'production' )
51
+ } ) ,
52
+ terser ( {
53
+ compress : {
54
+ pure_getters : true ,
55
+ unsafe : true ,
56
+ unsafe_comps : true ,
57
+ warnings : false
58
+ }
59
+ } ) ,
60
+ sizeSnapshot ( )
61
+ ] ,
62
+ ...overrides
68
63
} ,
69
- external,
70
- plugins : [
71
- commonjs ( ) ,
72
- nodeResolve ( {
73
- jsnext : true
74
- } ) ,
75
- babel ( {
76
- exclude : 'node_modules/**'
77
- } ) ,
78
- replace ( {
79
- 'process.env.NODE_ENV' : JSON . stringify ( 'development' )
80
- } ) ,
81
- sizeSnapshot ( )
82
- ] ,
83
- ...overrides
84
- } ,
85
64
86
- // UMD Production
87
- {
88
- input : 'src/index.js' ,
89
- output : {
90
- file : `dist/${ pkg . name } .min.js` ,
91
- format : 'umd' ,
92
- name,
93
- indent : false
65
+ // UMD Development
66
+ {
67
+ input : entryPoint ,
68
+ output : {
69
+ file : `dist/${ pkg . name } .js` ,
70
+ format : 'umd' ,
71
+ name,
72
+ indent : false
73
+ } ,
74
+ external,
75
+ plugins : [
76
+ commonjs ( ) ,
77
+ nodeResolve ( {
78
+ jsnext : true
79
+ } ) ,
80
+ esbuild ( ) ,
81
+ babel ( {
82
+ exclude : 'node_modules/**'
83
+ } ) ,
84
+ replace ( {
85
+ 'process.env.NODE_ENV' : JSON . stringify ( 'development' )
86
+ } ) ,
87
+ sizeSnapshot ( )
88
+ ] ,
89
+ ...overrides
94
90
} ,
95
- external,
96
- plugins : [
97
- commonjs ( ) ,
98
- nodeResolve ( {
99
- jsnext : true
100
- } ) ,
101
- babel ( {
102
- exclude : 'node_modules/**'
103
- } ) ,
104
- replace ( {
105
- 'process.env.NODE_ENV' : JSON . stringify ( 'production' )
106
- } ) ,
107
- terser ( {
108
- compress : {
109
- pure_getters : true ,
110
- unsafe : true ,
111
- unsafe_comps : true ,
112
- warnings : false
113
- }
114
- } ) ,
115
- sizeSnapshot ( )
116
- ] ,
117
- ...overrides
118
- }
119
- ]
91
+
92
+ // UMD Production
93
+ {
94
+ input : entryPoint ,
95
+ output : {
96
+ file : `dist/${ pkg . name } .min.js` ,
97
+ format : 'umd' ,
98
+ name,
99
+ indent : false
100
+ } ,
101
+ external,
102
+ plugins : [
103
+ commonjs ( ) ,
104
+ nodeResolve ( {
105
+ jsnext : true
106
+ } ) ,
107
+ esbuild ( ) ,
108
+ babel ( {
109
+ exclude : 'node_modules/**'
110
+ } ) ,
111
+ replace ( {
112
+ 'process.env.NODE_ENV' : JSON . stringify ( 'production' )
113
+ } ) ,
114
+ terser ( {
115
+ compress : {
116
+ pure_getters : true ,
117
+ unsafe : true ,
118
+ unsafe_comps : true ,
119
+ warnings : false
120
+ }
121
+ } ) ,
122
+ sizeSnapshot ( )
123
+ ] ,
124
+ ...overrides
125
+ }
126
+ ]
127
+ }
120
128
121
129
export default generateRollupConfig
0 commit comments