11// 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"
55// @ts -ignore
6- import autoExternal from "rollup-plugin-auto-external" ;
6+ import autoExternal from "rollup-plugin-auto-external"
77
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"
1414
1515export type Plugin =
1616 | "js"
@@ -25,60 +25,52 @@ export type Plugin =
2525 | [ "coffee" , typeof coffeescript ]
2626 | [ "json" , typeof json ]
2727 | [ "css" , typeof cssOnly ]
28- | [ "wasm" , typeof wasm ] ;
28+ | [ "wasm" , typeof wasm ]
2929
3030// function to check if the first array has any of the second array
3131// 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 {
3633 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
3936 if ( typeof elm === "string" ) {
4037 // plugin name only
41- name = elm ;
38+ name = elm
4239 } else {
4340 // plugin with options
44- name = elm [ 0 ] ;
41+ name = elm [ 0 ]
4542 }
4643 if ( arr2 . includes ( name ) ) {
47- return index ;
44+ return index
4845 }
4946 }
50- return null ;
47+ return null
5148}
5249
5350export function createPlugins (
5451 inputPluginsNames : Array < Plugin > = [ "ts" , "js" , "json" , "coffee" ] ,
5552 extraPlugins ?: Array < any > | boolean ,
5653 extraPluginsDeprecated ?: Array < any >
5754) {
58- let plugins = [ ] ;
55+ let plugins = [ ]
5956
6057 // language specific
6158
6259 // typescript
63- const tsIndex = includesAny ( inputPluginsNames , [
64- "ts" ,
65- ".ts" ,
66- "typescript" ,
67- "TypeScript" ,
68- ] ) ;
60+ const tsIndex = includesAny ( inputPluginsNames , [ "ts" , ".ts" , "typescript" , "TypeScript" ] )
6961 if ( tsIndex !== null ) {
70- const typescript = require ( "@rollup/plugin-typescript" ) ;
62+ const typescript = require ( "@rollup/plugin-typescript" )
7163 if ( typeof inputPluginsNames [ tsIndex ] === "string" ) {
7264 // plugin name only
7365 plugins . push (
7466 typescript ( {
7567 noEmitOnError : false ,
7668 module : "ESNext" , // do not modify the imports
7769 } )
78- ) ;
70+ )
7971 } else {
8072 // plugin with options
81- plugins . push ( typescript ( inputPluginsNames [ tsIndex ] [ 1 ] ) ) ;
73+ plugins . push ( typescript ( inputPluginsNames [ tsIndex ] [ 1 ] ) )
8274 }
8375 }
8476
@@ -90,110 +82,107 @@ export function createPlugins(
9082 "coffee-script" ,
9183 "CoffeeScript" ,
9284 "cs" ,
93- ] ) ;
85+ ] )
9486 if ( coffeeIndex !== null ) {
95- const coffeescript = require ( "rollup-plugin-coffee-script" ) ;
87+ const coffeescript = require ( "rollup-plugin-coffee-script" )
9688 if ( typeof inputPluginsNames [ coffeeIndex ] === "string" ) {
9789 // plugin name only
98- plugins . push ( coffeescript ( ) ) ;
90+ plugins . push ( coffeescript ( ) )
9991 } else {
10092 // plugin with options
101- plugins . push ( coffeescript ( inputPluginsNames [ coffeeIndex ] [ 1 ] ) ) ;
93+ plugins . push ( coffeescript ( inputPluginsNames [ coffeeIndex ] [ 1 ] ) )
10294 }
10395 }
10496
10597 // json
106- const jsonIndex = includesAny ( inputPluginsNames , [ "json" , ".json" , "JSON" ] ) ;
98+ const jsonIndex = includesAny ( inputPluginsNames , [ "json" , ".json" , "JSON" ] )
10799 if ( jsonIndex !== null ) {
108- const json = require ( "@rollup/plugin-json" ) ;
100+ const json = require ( "@rollup/plugin-json" )
109101 if ( typeof inputPluginsNames [ jsonIndex ] === "string" ) {
110102 // plugin name only
111- plugins . push ( json ( { compact : true } ) ) ;
103+ plugins . push ( json ( { compact : true } ) )
112104 } else {
113105 // plugin with options
114- plugins . push ( json ( inputPluginsNames [ jsonIndex ] [ 1 ] ) ) ;
106+ plugins . push ( json ( inputPluginsNames [ jsonIndex ] [ 1 ] ) )
115107 }
116108 }
117109
118110 // css only
119- const cssIndex = includesAny ( inputPluginsNames , [ "css" , ".css" ] ) ;
111+ const cssIndex = includesAny ( inputPluginsNames , [ "css" , ".css" ] )
120112 if ( cssIndex !== null ) {
121- const cssOnly = require ( "rollup-plugin-css-only" ) ;
113+ const cssOnly = require ( "rollup-plugin-css-only" )
122114 console . log ( `
123115 css only was chosen to bundle css files into a single file.
124116 This plugin requires you to import css files in a dummy js file and pass it as an input to rollup.
125117 This should be done in a separate step from src code bundling
126- ` ) ;
118+ ` )
127119 if ( typeof inputPluginsNames [ cssIndex ] === "string" ) {
128120 // plugin name only
129- plugins . push ( cssOnly ( { output : "dist/bundle.css" } ) ) ;
121+ plugins . push ( cssOnly ( { output : "dist/bundle.css" } ) )
130122 } else {
131123 // plugin with options
132- plugins . push ( cssOnly ( inputPluginsNames [ cssIndex ] [ 1 ] ) ) ;
124+ plugins . push ( cssOnly ( inputPluginsNames [ cssIndex ] [ 1 ] ) )
133125 }
134126 // minify css
135127 if ( process . env . NODE_ENV === "production" ) {
136128 // 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" ] ) )
139131 }
140132 }
141133
142134 // babel
143- let babelInput = extraPlugins ;
135+ let babelInput = extraPlugins
144136 if ( typeof babelInput === "boolean" ) {
145137 console . warn (
146138 'Setting babel with the second argument is depcrated. Pass "babel" like other plugins to the first argument'
147- ) ;
139+ )
148140 }
149141
150- const babelIndex = includesAny ( inputPluginsNames , [ "babel" ] ) ;
142+ const babelIndex = includesAny ( inputPluginsNames , [ "babel" ] )
151143 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" ) {
157146 // plugin name only
158147 plugins . push (
159148 babel ( {
160149 extensions : [ ".js" , ".jsx" , ".mjs" , ".coffee" ] ,
161150 babelHelpers : "bundled" ,
162151 } )
163- ) ;
152+ )
164153 } else {
165154 // plugin with options
166- plugins . push ( babel ( inputPluginsNames [ babelIndex ! ] [ 1 ] ) ) ;
155+ plugins . push ( babel ( inputPluginsNames [ babelIndex ! ] [ 1 ] ) )
167156 }
168157 }
169158
170159 // wasm
171- const wasmIndex = includesAny ( inputPluginsNames , [ "wasm" , "WebAssembly" ] ) ;
160+ const wasmIndex = includesAny ( inputPluginsNames , [ "wasm" , "WebAssembly" ] )
172161 if ( wasmIndex !== null ) {
173- const wasm = require ( "@rollup/plugin-wasm" ) ;
162+ const wasm = require ( "@rollup/plugin-wasm" )
174163 if ( typeof inputPluginsNames [ wasmIndex ] === "string" ) {
175164 // plugin name only
176- plugins . push ( wasm ( ) ) ;
165+ plugins . push ( wasm ( ) )
177166 } else {
178167 // plugin with options
179- plugins . push ( wasm ( inputPluginsNames [ wasmIndex ] [ 1 ] ) ) ;
168+ plugins . push ( wasm ( inputPluginsNames [ wasmIndex ] [ 1 ] ) )
180169 }
181170 }
182171
183172 // extra plugins
184173 if ( typeof extraPlugins !== "boolean" && extraPlugins !== undefined ) {
185174 try {
186- plugins . push ( ...extraPlugins ) ;
175+ plugins . push ( ...extraPlugins )
187176 } catch ( e ) {
188- console . error ( "You should pass extraPlugins as an array" ) ;
177+ console . error ( "You should pass extraPlugins as an array" )
189178 }
190179 }
191180
192181 if ( extraPluginsDeprecated ) {
193182 try {
194- plugins . push ( ...extraPluginsDeprecated ) ;
183+ plugins . push ( ...extraPluginsDeprecated )
195184 } catch ( e ) {
196- console . error ( "You should pass extraPluginsDeprecated as an array" ) ;
185+ console . error ( "You should pass extraPluginsDeprecated as an array" )
197186 }
198187 }
199188
@@ -212,9 +201,9 @@ export function createPlugins(
212201
213202 // so Rollup can convert externals to an ES module
214203 commonjs ( ) ,
215- ] ;
204+ ]
216205
217- plugins . push ( ...pluginsCommon ) ;
206+ plugins . push ( ...pluginsCommon )
218207
219208 // minify only in production mode
220209 if ( process . env . NODE_ENV === "production" ) {
@@ -226,10 +215,10 @@ export function createPlugins(
226215 drop_console : false ,
227216 } ,
228217 } )
229- ) ;
218+ )
230219 }
231220
232- return plugins ;
221+ return plugins
233222}
234223
235224export function createConfig (
@@ -251,5 +240,5 @@ export function createConfig(
251240 // loaded externally
252241 external : externals ,
253242 plugins : plugins ,
254- } ;
243+ }
255244}
0 commit comments