@@ -3,8 +3,6 @@ const babel = require("@rollup/plugin-babel").default;
3
3
const copy = require ( "rollup-plugin-copy" ) ;
4
4
const extensions = require ( "rollup-plugin-extensions" ) ;
5
5
const prettier = require ( "rollup-plugin-prettier" ) ;
6
- const replace = require ( "@rollup/plugin-replace" ) ;
7
- const { terser } = require ( "rollup-plugin-terser" ) ;
8
6
const typescript = require ( "@rollup/plugin-typescript" ) ;
9
7
const {
10
8
createBanner,
@@ -13,185 +11,56 @@ const {
13
11
} = require ( "../../rollup.utils" ) ;
14
12
const { name, version } = require ( "./package.json" ) ;
15
13
16
- module . exports = function rollup ( ) {
14
+ function getRollupConfig ( format , filename , includeTypesAndCopy = false ) {
17
15
const { ROOT_DIR , SOURCE_DIR , OUTPUT_DIR } = getBuildDirectories (
18
16
name ,
19
17
// We don't live in a folder matching our package name
20
18
"router"
21
19
) ;
22
20
23
- // JS modules for bundlers
24
- const modules = [
25
- {
26
- input : `${ SOURCE_DIR } /index.ts` ,
27
- output : {
28
- file : `${ OUTPUT_DIR } /index.js` ,
29
- format : "esm" ,
30
- sourcemap : ! PRETTY ,
31
- banner : createBanner ( "@remix-run/router" , version ) ,
32
- } ,
33
- plugins : [
34
- extensions ( { extensions : [ ".ts" ] } ) ,
35
- babel ( {
36
- babelHelpers : "bundled" ,
37
- exclude : / n o d e _ m o d u l e s / ,
38
- presets : [
39
- [ "@babel/preset-env" , { loose : true } ] ,
40
- "@babel/preset-typescript" ,
41
- ] ,
42
- plugins : [ "babel-plugin-dev-expression" ] ,
43
- extensions : [ ".ts" ] ,
44
- } ) ,
45
- typescript ( {
46
- tsconfig : path . join ( __dirname , "tsconfig.json" ) ,
47
- exclude : [ "__tests__" ] ,
48
- noEmitOnError : true ,
49
- } ) ,
50
- copy ( {
51
- targets : [
52
- { src : path . join ( ROOT_DIR , "LICENSE.md" ) , dest : SOURCE_DIR } ,
53
- ] ,
54
- verbose : true ,
55
- } ) ,
56
- ] . concat ( PRETTY ? prettier ( { parser : "babel" } ) : [ ] ) ,
21
+ return {
22
+ input : `${ SOURCE_DIR } /index.ts` ,
23
+ output : {
24
+ file : `${ OUTPUT_DIR } /${ filename } ` ,
25
+ format,
26
+ sourcemap : ! PRETTY ,
27
+ banner : createBanner ( "@remix-run/router" , version ) ,
57
28
} ,
58
- ] ;
29
+ plugins : [
30
+ extensions ( { extensions : [ ".ts" ] } ) ,
31
+ babel ( {
32
+ babelHelpers : "bundled" ,
33
+ exclude : / n o d e _ m o d u l e s / ,
34
+ presets : [
35
+ [ "@babel/preset-env" , { loose : true } ] ,
36
+ "@babel/preset-typescript" ,
37
+ ] ,
38
+ extensions : [ ".ts" ] ,
39
+ } ) ,
40
+ ...( includeTypesAndCopy
41
+ ? [
42
+ typescript ( {
43
+ tsconfig : path . join ( __dirname , "tsconfig.json" ) ,
44
+ exclude : [ "__tests__" ] ,
45
+ noEmitOnError : true ,
46
+ } ) ,
47
+ copy ( {
48
+ targets : [
49
+ { src : path . join ( ROOT_DIR , "LICENSE.md" ) , dest : SOURCE_DIR } ,
50
+ ] ,
51
+ verbose : true ,
52
+ } ) ,
53
+ ]
54
+ : [ ] ) ,
55
+ ] . concat ( PRETTY ? prettier ( { parser : "babel" } ) : [ ] ) ,
56
+ } ;
57
+ }
59
58
60
- // JS modules for <script type=module>
61
- const webModules = [
62
- {
63
- input : `${ SOURCE_DIR } /index.ts` ,
64
- output : {
65
- file : `${ OUTPUT_DIR } /router.development.js` ,
66
- format : "esm" ,
67
- sourcemap : ! PRETTY ,
68
- banner : createBanner ( "@remix-run/router" , version ) ,
69
- } ,
70
- plugins : [
71
- extensions ( { extensions : [ ".ts" ] } ) ,
72
- babel ( {
73
- babelHelpers : "bundled" ,
74
- exclude : / n o d e _ m o d u l e s / ,
75
- presets : [ "@babel/preset-modules" , "@babel/preset-typescript" ] ,
76
- plugins : [ "babel-plugin-dev-expression" ] ,
77
- extensions : [ ".ts" ] ,
78
- } ) ,
79
- replace ( {
80
- preventAssignment : true ,
81
- values : { "process.env.NODE_ENV" : JSON . stringify ( "development" ) } ,
82
- } ) ,
83
- ] . concat ( PRETTY ? prettier ( { parser : "babel" } ) : [ ] ) ,
84
- } ,
85
- {
86
- input : `${ SOURCE_DIR } /index.ts` ,
87
- output : {
88
- file : `${ OUTPUT_DIR } /router.production.min.js` ,
89
- format : "esm" ,
90
- sourcemap : ! PRETTY ,
91
- banner : createBanner ( "@remix-run/router" , version ) ,
92
- } ,
93
- plugins : [
94
- extensions ( { extensions : [ ".ts" ] } ) ,
95
- babel ( {
96
- babelHelpers : "bundled" ,
97
- exclude : / n o d e _ m o d u l e s / ,
98
- presets : [
99
- [
100
- "@babel/preset-modules" ,
101
- {
102
- // Don't spoof `.name` for Arrow Functions, which breaks when minified anyway.
103
- loose : true ,
104
- } ,
105
- ] ,
106
- "@babel/preset-typescript" ,
107
- ] ,
108
- plugins : [ "babel-plugin-dev-expression" ] ,
109
- extensions : [ ".ts" ] ,
110
- } ) ,
111
- replace ( {
112
- preventAssignment : true ,
113
- values : { "process.env.NODE_ENV" : JSON . stringify ( "production" ) } ,
114
- } ) ,
115
- // compiler(),
116
- terser ( { ecma : 8 , safari10 : true } ) ,
117
- ] . concat ( PRETTY ? prettier ( { parser : "babel" } ) : [ ] ) ,
118
- } ,
119
- ] ;
120
-
121
- // UMD modules for <script> tags and CommonJS (node)
122
- const globals = [
123
- {
124
- input : `${ SOURCE_DIR } /index.ts` ,
125
- output : {
126
- file : `${ OUTPUT_DIR } /umd/router.development.js` ,
127
- format : "umd" ,
128
- sourcemap : ! PRETTY ,
129
- banner : createBanner ( "@remix-run/router" , version ) ,
130
- name : "Router" ,
131
- } ,
132
- plugins : [
133
- extensions ( { extensions : [ ".ts" ] } ) ,
134
- babel ( {
135
- babelHelpers : "bundled" ,
136
- exclude : / n o d e _ m o d u l e s / ,
137
- presets : [
138
- [ "@babel/preset-env" , { loose : true } ] ,
139
- "@babel/preset-typescript" ,
140
- ] ,
141
- plugins : [ "babel-plugin-dev-expression" ] ,
142
- extensions : [ ".ts" ] ,
143
- } ) ,
144
- replace ( {
145
- preventAssignment : true ,
146
- values : { "process.env.NODE_ENV" : JSON . stringify ( "development" ) } ,
147
- } ) ,
148
- ] . concat ( PRETTY ? prettier ( { parser : "babel" } ) : [ ] ) ,
149
- } ,
150
- {
151
- input : `${ SOURCE_DIR } /index.ts` ,
152
- output : {
153
- file : `${ OUTPUT_DIR } /umd/router.production.min.js` ,
154
- format : "umd" ,
155
- sourcemap : ! PRETTY ,
156
- banner : createBanner ( "@remix-run/router" , version ) ,
157
- name : "Router" ,
158
- } ,
159
- plugins : [
160
- extensions ( { extensions : [ ".ts" ] } ) ,
161
- babel ( {
162
- babelHelpers : "bundled" ,
163
- exclude : / n o d e _ m o d u l e s / ,
164
- presets : [
165
- [ "@babel/preset-env" , { loose : true } ] ,
166
- "@babel/preset-typescript" ,
167
- ] ,
168
- plugins : [ "babel-plugin-dev-expression" ] ,
169
- extensions : [ ".ts" ] ,
170
- } ) ,
171
- replace ( {
172
- preventAssignment : true ,
173
- values : { "process.env.NODE_ENV" : JSON . stringify ( "production" ) } ,
174
- } ) ,
175
- // compiler(),
176
- terser ( ) ,
177
- ] . concat ( PRETTY ? prettier ( { parser : "babel" } ) : [ ] ) ,
178
- } ,
179
- ] ;
180
-
181
- // Node entry points
182
- const node = [
183
- {
184
- input : `${ SOURCE_DIR } /node-main.js` ,
185
- output : {
186
- file : `${ OUTPUT_DIR } /main.js` ,
187
- format : "cjs" ,
188
- banner : createBanner ( "@remix-run/router" , version ) ,
189
- } ,
190
- plugins : [ ] . concat ( PRETTY ? prettier ( { parser : "babel" } ) : [ ] ) ,
191
- } ,
59
+ module . exports = function rollup ( ) {
60
+ return [
61
+ getRollupConfig ( "esm" , "router.js" , true ) ,
62
+ getRollupConfig ( "cjs" , "router.cjs.js" , false ) ,
192
63
] ;
193
-
194
- return [ ...modules , ...webModules , ...globals , ...node ] ;
195
64
} ;
196
65
197
66
/**
0 commit comments