5
5
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
6
6
*/
7
7
8
- const rollup = require ( 'rollup' )
9
8
const path = require ( 'path' )
9
+ const rollup = require ( 'rollup' )
10
10
const babel = require ( 'rollup-plugin-babel' )
11
11
const banner = require ( './banner.js' )
12
- const TEST = process . env . NODE_ENV === 'test'
13
12
13
+ const TEST = process . env . NODE_ENV === 'test'
14
14
const plugins = [
15
15
babel ( {
16
16
exclude : 'node_modules/**' , // Only transpile our source code
@@ -23,9 +23,6 @@ const plugins = [
23
23
]
24
24
} )
25
25
]
26
-
27
- const format = 'umd'
28
- const rootPath = ! TEST ? '../js/dist/' : '../js/coverage/dist/'
29
26
const bsPlugins = {
30
27
Alert : path . resolve ( __dirname , '../js/src/alert.js' ) ,
31
28
Button : path . resolve ( __dirname , '../js/src/button.js' ) ,
@@ -39,45 +36,47 @@ const bsPlugins = {
39
36
Tooltip : path . resolve ( __dirname , '../js/src/tooltip.js' ) ,
40
37
Util : path . resolve ( __dirname , '../js/src/util.js' )
41
38
}
39
+ const rootPath = TEST ? '../js/coverage/dist/' : '../js/dist/'
42
40
43
- Object . keys ( bsPlugins )
44
- . forEach ( ( pluginKey ) => {
45
- console . log ( `Building ${ pluginKey } plugin...` )
41
+ function build ( plugin ) {
42
+ console . log ( `Building ${ plugin } plugin...` )
46
43
47
- const external = [ 'jquery' , 'popper.js' ]
48
- const globals = {
49
- jquery : 'jQuery' , // Ensure we use jQuery which is always available even in noConflict mode
50
- 'popper.js' : 'Popper'
51
- }
44
+ const external = [ 'jquery' , 'popper.js' ]
45
+ const globals = {
46
+ jquery : 'jQuery' , // Ensure we use jQuery which is always available even in noConflict mode
47
+ 'popper.js' : 'Popper'
48
+ }
52
49
53
- // Do not bundle Util in plugins
54
- if ( pluginKey !== 'Util' ) {
55
- external . push ( bsPlugins . Util )
56
- globals [ bsPlugins . Util ] = 'Util'
57
- }
50
+ // Do not bundle Util in plugins
51
+ if ( plugin !== 'Util' ) {
52
+ external . push ( bsPlugins . Util )
53
+ globals [ bsPlugins . Util ] = 'Util'
54
+ }
58
55
59
- // Do not bundle Tooltip in Popover
60
- if ( pluginKey === 'Popover' ) {
61
- external . push ( bsPlugins . Tooltip )
62
- globals [ bsPlugins . Tooltip ] = 'Tooltip'
63
- }
56
+ // Do not bundle Tooltip in Popover
57
+ if ( plugin === 'Popover' ) {
58
+ external . push ( bsPlugins . Tooltip )
59
+ globals [ bsPlugins . Tooltip ] = 'Tooltip'
60
+ }
64
61
65
- const pluginFilename = `${ pluginKey . toLowerCase ( ) } .js`
62
+ const pluginFilename = `${ plugin . toLowerCase ( ) } .js`
66
63
67
- rollup . rollup ( {
68
- input : bsPlugins [ pluginKey ] ,
69
- plugins,
70
- external
71
- } ) . then ( ( bundle ) => {
72
- bundle . write ( {
73
- banner : banner ( pluginFilename ) ,
74
- format,
75
- name : pluginKey ,
76
- sourcemap : true ,
77
- globals,
78
- file : path . resolve ( __dirname , `${ rootPath } ${ pluginFilename } ` )
79
- } )
80
- . then ( ( ) => console . log ( `Building ${ pluginKey } plugin... Done!` ) )
81
- . catch ( ( err ) => console . error ( `${ pluginKey } : ${ err } ` ) )
64
+ rollup . rollup ( {
65
+ input : bsPlugins [ plugin ] ,
66
+ plugins,
67
+ external
68
+ } ) . then ( ( bundle ) => {
69
+ bundle . write ( {
70
+ banner : banner ( pluginFilename ) ,
71
+ format : 'umd' ,
72
+ name : plugin ,
73
+ sourcemap : true ,
74
+ globals,
75
+ file : path . resolve ( __dirname , `${ rootPath } ${ pluginFilename } ` )
82
76
} )
77
+ . then ( ( ) => console . log ( `Building ${ plugin } plugin... Done!` ) )
78
+ . catch ( ( err ) => console . error ( `${ plugin } : ${ err } ` ) )
83
79
} )
80
+ }
81
+
82
+ Object . keys ( bsPlugins ) . forEach ( ( plugin ) => build ( plugin ) )
0 commit comments