1
1
// common plugins
2
- import resolve from "@rollup/plugin-node-resolve" ;
3
- import commonjs from "@rollup/plugin-commonjs" ;
4
- import { terser } from "rollup-plugin-terser" ;
2
+ import resolve from "@rollup/plugin-node-resolve"
3
+ import commonjs from "@rollup/plugin-commonjs"
4
+ import { terser } from "rollup-plugin-terser"
5
5
// @ts -ignore
6
- import autoExternal from "rollup-plugin-auto-external" ;
6
+ import autoExternal from "rollup-plugin-auto-external"
7
7
8
- import typescript from "@rollup/plugin-typescript" ;
9
- import coffeescript from "rollup-plugin-coffee-script" ;
10
- import json from "@rollup/plugin-json" ;
11
- import cssOnly from "rollup-plugin-css-only" ;
12
- import babel from "@rollup/plugin-babel" ;
13
- import { wasm } from "@rollup/plugin-wasm" ;
8
+ import typescript from "@rollup/plugin-typescript"
9
+ import coffeescript from "rollup-plugin-coffee-script"
10
+ import json from "@rollup/plugin-json"
11
+ import cssOnly from "rollup-plugin-css-only"
12
+ import babel from "@rollup/plugin-babel"
13
+ import { wasm } from "@rollup/plugin-wasm"
14
14
15
15
export type Plugin =
16
16
| "js"
@@ -25,60 +25,52 @@ export type Plugin =
25
25
| [ "coffee" , typeof coffeescript ]
26
26
| [ "json" , typeof json ]
27
27
| [ "css" , typeof cssOnly ]
28
- | [ "wasm" , typeof wasm ] ;
28
+ | [ "wasm" , typeof wasm ]
29
29
30
30
// function to check if the first array has any of the second array
31
31
// first array can have `[string, object]` as their input
32
- function includesAny (
33
- arr1 : Array < string | [ string , Object ] > ,
34
- arr2 : Array < string >
35
- ) : null | number {
32
+ function includesAny ( arr1 : Array < string | [ string , Object ] > , arr2 : Array < string > ) : null | number {
36
33
for ( let index = 0 ; index < arr1 . length ; index ++ ) {
37
- const elm = arr1 [ index ] ;
38
- let name : string ;
34
+ const elm = arr1 [ index ]
35
+ let name : string
39
36
if ( typeof elm === "string" ) {
40
37
// plugin name only
41
- name = elm ;
38
+ name = elm
42
39
} else {
43
40
// plugin with options
44
- name = elm [ 0 ] ;
41
+ name = elm [ 0 ]
45
42
}
46
43
if ( arr2 . includes ( name ) ) {
47
- return index ;
44
+ return index
48
45
}
49
46
}
50
- return null ;
47
+ return null
51
48
}
52
49
53
50
export function createPlugins (
54
51
inputPluginsNames : Array < Plugin > = [ "ts" , "js" , "json" , "coffee" ] ,
55
52
extraPlugins ?: Array < any > | boolean ,
56
53
extraPluginsDeprecated ?: Array < any >
57
54
) {
58
- let plugins = [ ] ;
55
+ let plugins = [ ]
59
56
60
57
// language specific
61
58
62
59
// typescript
63
- const tsIndex = includesAny ( inputPluginsNames , [
64
- "ts" ,
65
- ".ts" ,
66
- "typescript" ,
67
- "TypeScript" ,
68
- ] ) ;
60
+ const tsIndex = includesAny ( inputPluginsNames , [ "ts" , ".ts" , "typescript" , "TypeScript" ] )
69
61
if ( tsIndex !== null ) {
70
- const typescript = require ( "@rollup/plugin-typescript" ) ;
62
+ const typescript = require ( "@rollup/plugin-typescript" )
71
63
if ( typeof inputPluginsNames [ tsIndex ] === "string" ) {
72
64
// plugin name only
73
65
plugins . push (
74
66
typescript ( {
75
67
noEmitOnError : false ,
76
68
module : "ESNext" , // do not modify the imports
77
69
} )
78
- ) ;
70
+ )
79
71
} else {
80
72
// plugin with options
81
- plugins . push ( typescript ( inputPluginsNames [ tsIndex ] [ 1 ] ) ) ;
73
+ plugins . push ( typescript ( inputPluginsNames [ tsIndex ] [ 1 ] ) )
82
74
}
83
75
}
84
76
@@ -90,110 +82,107 @@ export function createPlugins(
90
82
"coffee-script" ,
91
83
"CoffeeScript" ,
92
84
"cs" ,
93
- ] ) ;
85
+ ] )
94
86
if ( coffeeIndex !== null ) {
95
- const coffeescript = require ( "rollup-plugin-coffee-script" ) ;
87
+ const coffeescript = require ( "rollup-plugin-coffee-script" )
96
88
if ( typeof inputPluginsNames [ coffeeIndex ] === "string" ) {
97
89
// plugin name only
98
- plugins . push ( coffeescript ( ) ) ;
90
+ plugins . push ( coffeescript ( ) )
99
91
} else {
100
92
// plugin with options
101
- plugins . push ( coffeescript ( inputPluginsNames [ coffeeIndex ] [ 1 ] ) ) ;
93
+ plugins . push ( coffeescript ( inputPluginsNames [ coffeeIndex ] [ 1 ] ) )
102
94
}
103
95
}
104
96
105
97
// json
106
- const jsonIndex = includesAny ( inputPluginsNames , [ "json" , ".json" , "JSON" ] ) ;
98
+ const jsonIndex = includesAny ( inputPluginsNames , [ "json" , ".json" , "JSON" ] )
107
99
if ( jsonIndex !== null ) {
108
- const json = require ( "@rollup/plugin-json" ) ;
100
+ const json = require ( "@rollup/plugin-json" )
109
101
if ( typeof inputPluginsNames [ jsonIndex ] === "string" ) {
110
102
// plugin name only
111
- plugins . push ( json ( { compact : true } ) ) ;
103
+ plugins . push ( json ( { compact : true } ) )
112
104
} else {
113
105
// plugin with options
114
- plugins . push ( json ( inputPluginsNames [ jsonIndex ] [ 1 ] ) ) ;
106
+ plugins . push ( json ( inputPluginsNames [ jsonIndex ] [ 1 ] ) )
115
107
}
116
108
}
117
109
118
110
// css only
119
- const cssIndex = includesAny ( inputPluginsNames , [ "css" , ".css" ] ) ;
111
+ const cssIndex = includesAny ( inputPluginsNames , [ "css" , ".css" ] )
120
112
if ( cssIndex !== null ) {
121
- const cssOnly = require ( "rollup-plugin-css-only" ) ;
113
+ const cssOnly = require ( "rollup-plugin-css-only" )
122
114
console . log ( `
123
115
css only was chosen to bundle css files into a single file.
124
116
This plugin requires you to import css files in a dummy js file and pass it as an input to rollup.
125
117
This should be done in a separate step from src code bundling
126
- ` ) ;
118
+ ` )
127
119
if ( typeof inputPluginsNames [ cssIndex ] === "string" ) {
128
120
// plugin name only
129
- plugins . push ( cssOnly ( { output : "dist/bundle.css" } ) ) ;
121
+ plugins . push ( cssOnly ( { output : "dist/bundle.css" } ) )
130
122
} else {
131
123
// plugin with options
132
- plugins . push ( cssOnly ( inputPluginsNames [ cssIndex ] [ 1 ] ) ) ;
124
+ plugins . push ( cssOnly ( inputPluginsNames [ cssIndex ] [ 1 ] ) )
133
125
}
134
126
// minify css
135
127
if ( process . env . NODE_ENV === "production" ) {
136
128
// TODO get the output from the plugin when the user uses options
137
- const execute = require ( "rollup-plugin-execute" ) ;
138
- plugins . push ( execute ( [ "csso dist/bundle.css --output dist/bundle.css" ] ) ) ;
129
+ const execute = require ( "rollup-plugin-execute" )
130
+ plugins . push ( execute ( [ "csso dist/bundle.css --output dist/bundle.css" ] ) )
139
131
}
140
132
}
141
133
142
134
// babel
143
- let babelInput = extraPlugins ;
135
+ let babelInput = extraPlugins
144
136
if ( typeof babelInput === "boolean" ) {
145
137
console . warn (
146
138
'Setting babel with the second argument is depcrated. Pass "babel" like other plugins to the first argument'
147
- ) ;
139
+ )
148
140
}
149
141
150
- const babelIndex = includesAny ( inputPluginsNames , [ "babel" ] ) ;
142
+ const babelIndex = includesAny ( inputPluginsNames , [ "babel" ] )
151
143
if ( babelIndex !== null || babelInput === true ) {
152
- const { babel } = require ( "@rollup/plugin-babel" ) ;
153
- if (
154
- babelInput === true ||
155
- typeof inputPluginsNames [ babelIndex ! ] === "string"
156
- ) {
144
+ const { babel } = require ( "@rollup/plugin-babel" )
145
+ if ( babelInput === true || typeof inputPluginsNames [ babelIndex ! ] === "string" ) {
157
146
// plugin name only
158
147
plugins . push (
159
148
babel ( {
160
149
extensions : [ ".js" , ".jsx" , ".mjs" , ".coffee" ] ,
161
150
babelHelpers : "bundled" ,
162
151
} )
163
- ) ;
152
+ )
164
153
} else {
165
154
// plugin with options
166
- plugins . push ( babel ( inputPluginsNames [ babelIndex ! ] [ 1 ] ) ) ;
155
+ plugins . push ( babel ( inputPluginsNames [ babelIndex ! ] [ 1 ] ) )
167
156
}
168
157
}
169
158
170
159
// wasm
171
- const wasmIndex = includesAny ( inputPluginsNames , [ "wasm" , "WebAssembly" ] ) ;
160
+ const wasmIndex = includesAny ( inputPluginsNames , [ "wasm" , "WebAssembly" ] )
172
161
if ( wasmIndex !== null ) {
173
- const wasm = require ( "@rollup/plugin-wasm" ) ;
162
+ const wasm = require ( "@rollup/plugin-wasm" )
174
163
if ( typeof inputPluginsNames [ wasmIndex ] === "string" ) {
175
164
// plugin name only
176
- plugins . push ( wasm ( ) ) ;
165
+ plugins . push ( wasm ( ) )
177
166
} else {
178
167
// plugin with options
179
- plugins . push ( wasm ( inputPluginsNames [ wasmIndex ] [ 1 ] ) ) ;
168
+ plugins . push ( wasm ( inputPluginsNames [ wasmIndex ] [ 1 ] ) )
180
169
}
181
170
}
182
171
183
172
// extra plugins
184
173
if ( typeof extraPlugins !== "boolean" && extraPlugins !== undefined ) {
185
174
try {
186
- plugins . push ( ...extraPlugins ) ;
175
+ plugins . push ( ...extraPlugins )
187
176
} catch ( e ) {
188
- console . error ( "You should pass extraPlugins as an array" ) ;
177
+ console . error ( "You should pass extraPlugins as an array" )
189
178
}
190
179
}
191
180
192
181
if ( extraPluginsDeprecated ) {
193
182
try {
194
- plugins . push ( ...extraPluginsDeprecated ) ;
183
+ plugins . push ( ...extraPluginsDeprecated )
195
184
} catch ( e ) {
196
- console . error ( "You should pass extraPluginsDeprecated as an array" ) ;
185
+ console . error ( "You should pass extraPluginsDeprecated as an array" )
197
186
}
198
187
}
199
188
@@ -212,9 +201,9 @@ export function createPlugins(
212
201
213
202
// so Rollup can convert externals to an ES module
214
203
commonjs ( ) ,
215
- ] ;
204
+ ]
216
205
217
- plugins . push ( ...pluginsCommon ) ;
206
+ plugins . push ( ...pluginsCommon )
218
207
219
208
// minify only in production mode
220
209
if ( process . env . NODE_ENV === "production" ) {
@@ -226,10 +215,10 @@ export function createPlugins(
226
215
drop_console : false ,
227
216
} ,
228
217
} )
229
- ) ;
218
+ )
230
219
}
231
220
232
- return plugins ;
221
+ return plugins
233
222
}
234
223
235
224
export function createConfig (
@@ -251,5 +240,5 @@ export function createConfig(
251
240
// loaded externally
252
241
external : externals ,
253
242
plugins : plugins ,
254
- } ;
243
+ }
255
244
}
0 commit comments