Skip to content

Commit a7ca5f4

Browse files
committed
Create a bundled release of Bootstrap with Popper.js inside
1 parent 870b743 commit a7ca5f4

File tree

18 files changed

+214
-56
lines changed

18 files changed

+214
-56
lines changed

.babelrc

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,5 @@
88
}
99
]
1010
],
11-
"plugins": [
12-
"transform-es2015-modules-strip"
13-
]
11+
"plugins": ["external-helpers"]
1412
}

build/rollup.config.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
const path = require('path')
2+
const babel = require('rollup-plugin-babel')
3+
const resolve = require('rollup-plugin-node-resolve')
4+
const BUNDLE = process.env.BUNDLE === 'true'
5+
6+
var fileDest = 'bootstrap.js'
7+
var external = ['jquery', 'popper.js']
8+
const plugins = [
9+
babel({
10+
exclude: 'node_modules/**', // only transpile our source code
11+
externalHelpersWhitelist: [ // include only required helpers
12+
'typeof',
13+
'classCallCheck',
14+
'createClass',
15+
'inherits',
16+
'possibleConstructorReturn'
17+
]
18+
})
19+
]
20+
const globals = {
21+
jquery: '$',
22+
'popper.js': 'Popper'
23+
}
24+
25+
if (BUNDLE) {
26+
fileDest = 'bootstrap.bundle.js'
27+
// remove last entry in external array to bundle Popper
28+
external.pop()
29+
delete globals['popper.js']
30+
plugins.push(resolve())
31+
}
32+
33+
module.exports = {
34+
input: path.resolve(__dirname, '../js/src/index.js'),
35+
output: {
36+
file: path.resolve(__dirname, `../dist/js/${fileDest}`),
37+
format: 'iife'
38+
},
39+
name: 'bootstrap',
40+
external: external,
41+
globals: globals,
42+
plugins: plugins
43+
}

build/stamp.js

Lines changed: 11 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,19 @@
1-
const fs = require('fs')
1+
const fs = require('fs')
2+
const path = require('path')
3+
const pkg = require(path.resolve(__dirname, '../package.json'))
4+
const year = new Date().getFullYear()
25

3-
fs.readFile('package.json', (err, data) => {
4-
if (err) {
5-
throw err
6-
}
6+
const pathBoostrap = path.resolve(__dirname, '../dist/js/bootstrap.js')
7+
const pathBootstrapBundle = path.resolve(__dirname, '../dist/js/bootstrap.bundle.js')
8+
const contentFile = fs.readFileSync(pathBoostrap, { encoding: 'UTF8' })
9+
const contentBundleFile = fs.readFileSync(pathBootstrapBundle, { encoding: 'UTF8' })
710

8-
const pkg = JSON.parse(data)
9-
const year = new Date().getFullYear()
10-
11-
const stampTop =
11+
const stamp =
1212
`/*!
1313
* Bootstrap v${pkg.version} (${pkg.homepage})
1414
* Copyright 2011-${year} ${pkg.author}
1515
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
1616
*/
17-
18-
if (typeof jQuery === 'undefined') {
19-
throw new Error('Bootstrap\\'s JavaScript requires jQuery. jQuery must be included before Bootstrap\\'s JavaScript.')
20-
}
21-
22-
(function ($) {
23-
var version = $.fn.jquery.split(' ')[0].split('.')
24-
if ((version[0] < 3) || (version[0] >= 4)) {
25-
throw new Error('Bootstrap\\'s JavaScript requires at least jQuery v3.0.0 but less than v4.0.0')
26-
}
27-
})(jQuery);
28-
29-
(function () {
3017
`
31-
const stampEnd = `
32-
})();`
33-
34-
process.stdout.write(stampTop)
35-
36-
process.stdin.on('end', () => {
37-
process.stdout.write(stampEnd)
38-
})
39-
40-
process.stdin.pipe(process.stdout)
41-
})
18+
fs.writeFileSync(pathBoostrap, `${stamp}${contentFile}`, { encoding: 'UTF8' })
19+
fs.writeFileSync(pathBootstrapBundle, `${stamp}${contentBundleFile}`, { encoding: 'UTF8' })

js/src/alert.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import $ from 'jquery'
12
import Util from './util'
23

34

@@ -8,7 +9,7 @@ import Util from './util'
89
* --------------------------------------------------------------------------
910
*/
1011

11-
const Alert = (($) => {
12+
const Alert = (() => {
1213

1314

1415
/**

js/src/button.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1+
import $ from 'jquery'
12
/**
23
* --------------------------------------------------------------------------
34
* Bootstrap (v4.0.0-beta): button.js
45
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
56
* --------------------------------------------------------------------------
67
*/
78

8-
const Button = (($) => {
9+
const Button = (() => {
910

1011

1112
/**

js/src/carousel.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import $ from 'jquery'
12
import Util from './util'
23

34

@@ -8,7 +9,7 @@ import Util from './util'
89
* --------------------------------------------------------------------------
910
*/
1011

11-
const Carousel = (($) => {
12+
const Carousel = (() => {
1213

1314

1415
/**

js/src/collapse.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import $ from 'jquery'
12
import Util from './util'
23

34

@@ -8,7 +9,7 @@ import Util from './util'
89
* --------------------------------------------------------------------------
910
*/
1011

11-
const Collapse = (($) => {
12+
const Collapse = (() => {
1213

1314

1415
/**

js/src/dropdown.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
/* global Popper */
2-
1+
import $ from 'jquery'
2+
import Popper from 'popper.js'
33
import Util from './util'
44

55

@@ -10,7 +10,7 @@ import Util from './util'
1010
* --------------------------------------------------------------------------
1111
*/
1212

13-
const Dropdown = (($) => {
13+
const Dropdown = (() => {
1414

1515
/**
1616
* Check for Popper dependency
@@ -445,6 +445,6 @@ const Dropdown = (($) => {
445445

446446
return Dropdown
447447

448-
})(jQuery)
448+
})(jQuery, Popper)
449449

450450
export default Dropdown

js/src/index.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import $ from 'jquery'
2+
import Alert from './alert'
3+
import Button from './button'
4+
import Carousel from './carousel'
5+
import Collapse from './collapse'
6+
import Dropdown from './dropdown'
7+
import Modal from './modal'
8+
import Popover from './popover'
9+
import Scrollspy from './scrollspy'
10+
import Tab from './tab'
11+
import Tooltip from './tooltip'
12+
import Util from './util'
13+
14+
/**
15+
* --------------------------------------------------------------------------
16+
* Bootstrap (v4.0.0-alpha.6): index.js
17+
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
18+
* --------------------------------------------------------------------------
19+
*/
20+
21+
if (typeof jQuery === 'undefined') {
22+
throw new Error('Bootstrap\'s JavaScript requires jQuery. jQuery must be included before Bootstrap\'s JavaScript.')
23+
}
24+
25+
(() => {
26+
const version = $.fn.jquery.split(' ')[0].split('.')
27+
const min = 3
28+
const max = 4
29+
if (version[0] < min || version[0] >= max) {
30+
throw new Error('Bootstrap\'s JavaScript requires at least jQuery v3.0.0 but less than v4.0.0')
31+
}
32+
})(jQuery)
33+
34+
export {
35+
Util,
36+
Alert,
37+
Button,
38+
Carousel,
39+
Collapse,
40+
Dropdown,
41+
Modal,
42+
Popover,
43+
Scrollspy,
44+
Tab,
45+
Tooltip
46+
}

js/src/modal.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import $ from 'jquery'
12
import Util from './util'
23

34

@@ -8,7 +9,7 @@ import Util from './util'
89
* --------------------------------------------------------------------------
910
*/
1011

11-
const Modal = (($) => {
12+
const Modal = (() => {
1213

1314

1415
/**

0 commit comments

Comments
 (0)