Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create a bundled release of Bootstrap with Popper.js inside #23735

Merged
merged 1 commit into from
Aug 31, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions .babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,5 @@
}
]
],
"plugins": [
"transform-es2015-modules-strip"
]
"plugins": ["external-helpers"]
}
43 changes: 43 additions & 0 deletions build/rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
const path = require('path')
const babel = require('rollup-plugin-babel')
const resolve = require('rollup-plugin-node-resolve')
const BUNDLE = process.env.BUNDLE === 'true'

var fileDest = 'bootstrap.js'
var external = ['jquery', 'popper.js']
const plugins = [
babel({
exclude: 'node_modules/**', // only transpile our source code
externalHelpersWhitelist: [ // include only required helpers
'typeof',
'classCallCheck',
'createClass',
'inherits',
'possibleConstructorReturn'
]
})
]
const globals = {
jquery: '$',
'popper.js': 'Popper'
}

if (BUNDLE) {
fileDest = 'bootstrap.bundle.js'
// remove last entry in external array to bundle Popper
external.pop()
delete globals['popper.js']
plugins.push(resolve())
}

module.exports = {
input: path.resolve(__dirname, '../js/src/index.js'),
output: {
file: path.resolve(__dirname, `../dist/js/${fileDest}`),
format: 'iife'
},
name: 'bootstrap',
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI with that attribute a global bootstrap var will be added to the scope of folk's applications, Rollup do not accept to bundle without a name for iife

external: external,
globals: globals,
plugins: plugins
}
44 changes: 11 additions & 33 deletions build/stamp.js
Original file line number Diff line number Diff line change
@@ -1,41 +1,19 @@
const fs = require('fs')
const fs = require('fs')
const path = require('path')
const pkg = require(path.resolve(__dirname, '../package.json'))
const year = new Date().getFullYear()

fs.readFile('package.json', (err, data) => {
if (err) {
throw err
}
const pathBoostrap = path.resolve(__dirname, '../dist/js/bootstrap.js')
const pathBootstrapBundle = path.resolve(__dirname, '../dist/js/bootstrap.bundle.js')
const contentFile = fs.readFileSync(pathBoostrap, { encoding: 'UTF8' })
const contentBundleFile = fs.readFileSync(pathBootstrapBundle, { encoding: 'UTF8' })

const pkg = JSON.parse(data)
const year = new Date().getFullYear()

const stampTop =
const stamp =
`/*!
* Bootstrap v${pkg.version} (${pkg.homepage})
* Copyright 2011-${year} ${pkg.author}
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
*/

if (typeof jQuery === 'undefined') {
throw new Error('Bootstrap\\'s JavaScript requires jQuery. jQuery must be included before Bootstrap\\'s JavaScript.')
}

(function ($) {
var version = $.fn.jquery.split(' ')[0].split('.')
if ((version[0] < 3) || (version[0] >= 4)) {
throw new Error('Bootstrap\\'s JavaScript requires at least jQuery v3.0.0 but less than v4.0.0')
}
})(jQuery);

(function () {
`
const stampEnd = `
})();`

process.stdout.write(stampTop)

process.stdin.on('end', () => {
process.stdout.write(stampEnd)
})

process.stdin.pipe(process.stdout)
})
fs.writeFileSync(pathBoostrap, `${stamp}${contentFile}`, { encoding: 'UTF8' })
fs.writeFileSync(pathBootstrapBundle, `${stamp}${contentBundleFile}`, { encoding: 'UTF8' })
3 changes: 2 additions & 1 deletion js/src/alert.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import $ from 'jquery'
import Util from './util'


Expand All @@ -8,7 +9,7 @@ import Util from './util'
* --------------------------------------------------------------------------
*/

const Alert = (($) => {
const Alert = (() => {


/**
Expand Down
3 changes: 2 additions & 1 deletion js/src/button.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import $ from 'jquery'
/**
* --------------------------------------------------------------------------
* Bootstrap (v4.0.0-beta): button.js
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
* --------------------------------------------------------------------------
*/

const Button = (($) => {
const Button = (() => {


/**
Expand Down
3 changes: 2 additions & 1 deletion js/src/carousel.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import $ from 'jquery'
import Util from './util'


Expand All @@ -8,7 +9,7 @@ import Util from './util'
* --------------------------------------------------------------------------
*/

const Carousel = (($) => {
const Carousel = (() => {


/**
Expand Down
3 changes: 2 additions & 1 deletion js/src/collapse.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import $ from 'jquery'
import Util from './util'


Expand All @@ -8,7 +9,7 @@ import Util from './util'
* --------------------------------------------------------------------------
*/

const Collapse = (($) => {
const Collapse = (() => {


/**
Expand Down
8 changes: 4 additions & 4 deletions js/src/dropdown.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* global Popper */

import $ from 'jquery'
import Popper from 'popper.js'
import Util from './util'


Expand All @@ -10,7 +10,7 @@ import Util from './util'
* --------------------------------------------------------------------------
*/

const Dropdown = (($) => {
const Dropdown = (() => {

/**
* Check for Popper dependency
Expand Down Expand Up @@ -445,6 +445,6 @@ const Dropdown = (($) => {

return Dropdown

})(jQuery)
})(jQuery, Popper)

export default Dropdown
46 changes: 46 additions & 0 deletions js/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import $ from 'jquery'
import Alert from './alert'
import Button from './button'
import Carousel from './carousel'
import Collapse from './collapse'
import Dropdown from './dropdown'
import Modal from './modal'
import Popover from './popover'
import Scrollspy from './scrollspy'
import Tab from './tab'
import Tooltip from './tooltip'
import Util from './util'

/**
* --------------------------------------------------------------------------
* Bootstrap (v4.0.0-alpha.6): index.js
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
* --------------------------------------------------------------------------
*/

if (typeof jQuery === 'undefined') {
throw new Error('Bootstrap\'s JavaScript requires jQuery. jQuery must be included before Bootstrap\'s JavaScript.')
}

(() => {
const version = $.fn.jquery.split(' ')[0].split('.')
const min = 3
const max = 4
if (version[0] < min || version[0] >= max) {
throw new Error('Bootstrap\'s JavaScript requires at least jQuery v3.0.0 but less than v4.0.0')
}
})(jQuery)

export {
Util,
Alert,
Button,
Carousel,
Collapse,
Dropdown,
Modal,
Popover,
Scrollspy,
Tab,
Tooltip
}
3 changes: 2 additions & 1 deletion js/src/modal.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import $ from 'jquery'
import Util from './util'


Expand All @@ -8,7 +9,7 @@ import Util from './util'
* --------------------------------------------------------------------------
*/

const Modal = (($) => {
const Modal = (() => {


/**
Expand Down
3 changes: 2 additions & 1 deletion js/src/popover.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import $ from 'jquery'
import Tooltip from './tooltip'


Expand All @@ -8,7 +9,7 @@ import Tooltip from './tooltip'
* --------------------------------------------------------------------------
*/

const Popover = (($) => {
const Popover = (() => {


/**
Expand Down
3 changes: 2 additions & 1 deletion js/src/scrollspy.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import $ from 'jquery'
import Util from './util'


Expand All @@ -8,7 +9,7 @@ import Util from './util'
* --------------------------------------------------------------------------
*/

const ScrollSpy = (($) => {
const ScrollSpy = (() => {


/**
Expand Down
3 changes: 2 additions & 1 deletion js/src/tab.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import $ from 'jquery'
import Util from './util'


Expand All @@ -8,7 +9,7 @@ import Util from './util'
* --------------------------------------------------------------------------
*/

const Tab = (($) => {
const Tab = (() => {


/**
Expand Down
8 changes: 4 additions & 4 deletions js/src/tooltip.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* global Popper */

import $ from 'jquery'
import Popper from 'popper.js'
import Util from './util'


Expand All @@ -10,7 +10,7 @@ import Util from './util'
* --------------------------------------------------------------------------
*/

const Tooltip = (($) => {
const Tooltip = (() => {

/**
* Check for Popper dependency
Expand Down Expand Up @@ -728,6 +728,6 @@ const Tooltip = (($) => {

return Tooltip

})(jQuery)
})(jQuery, Popper)

export default Tooltip
4 changes: 3 additions & 1 deletion js/src/util.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import $ from 'jquery'

/**
* --------------------------------------------------------------------------
* Bootstrap (v4.0.0-beta): util.js
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
* --------------------------------------------------------------------------
*/

const Util = (($) => {
const Util = (() => {


/**
Expand Down
1 change: 1 addition & 0 deletions js/tests/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"global-require": "off",
"no-process-env": "off",
"no-process-exit": "off",
"no-sync": "off",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this off by default?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unfortunately no 😄

Copy link
Member

@XhmikosR XhmikosR Aug 31, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Weird, doesn't seem enabled here https://eslint.org/docs/rules/#nodejs-and-commonjs

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


// Stylistic Issues
"brace-style": "off",
Expand Down
Loading