Skip to content

Commit 19f70f9

Browse files
committed
Tweak build/build-plugins.js.
1 parent 7c7a170 commit 19f70f9

File tree

1 file changed

+38
-39
lines changed

1 file changed

+38
-39
lines changed

build/build-plugins.js

Lines changed: 38 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
66
*/
77

8-
const rollup = require('rollup')
98
const path = require('path')
9+
const rollup = require('rollup')
1010
const babel = require('rollup-plugin-babel')
1111
const banner = require('./banner.js')
12-
const TEST = process.env.NODE_ENV === 'test'
1312

13+
const TEST = process.env.NODE_ENV === 'test'
1414
const plugins = [
1515
babel({
1616
exclude: 'node_modules/**', // Only transpile our source code
@@ -23,9 +23,6 @@ const plugins = [
2323
]
2424
})
2525
]
26-
27-
const format = 'umd'
28-
const rootPath = !TEST ? '../js/dist/' : '../js/coverage/dist/'
2926
const bsPlugins = {
3027
Alert: path.resolve(__dirname, '../js/src/alert.js'),
3128
Button: path.resolve(__dirname, '../js/src/button.js'),
@@ -39,45 +36,47 @@ const bsPlugins = {
3936
Tooltip: path.resolve(__dirname, '../js/src/tooltip.js'),
4037
Util: path.resolve(__dirname, '../js/src/util.js')
4138
}
39+
const rootPath = TEST ? '../js/coverage/dist/' : '../js/dist/'
4240

43-
Object.keys(bsPlugins)
44-
.forEach((pluginKey) => {
45-
console.log(`Building ${pluginKey} plugin...`)
41+
function build(plugin) {
42+
console.log(`Building ${plugin} plugin...`)
4643

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+
}
5249

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+
}
5855

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+
}
6461

65-
const pluginFilename = `${pluginKey.toLowerCase()}.js`
62+
const pluginFilename = `${plugin.toLowerCase()}.js`
6663

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}`)
8276
})
77+
.then(() => console.log(`Building ${plugin} plugin... Done!`))
78+
.catch((err) => console.error(`${plugin}: ${err}`))
8379
})
80+
}
81+
82+
Object.keys(bsPlugins).forEach((plugin) => build(plugin))

0 commit comments

Comments
 (0)