mirror of
https://github.com/twbs/bootstrap.git
synced 2025-08-19 03:41:19 +02:00
Create a bundled release of Bootstrap with Popper.js inside
This commit is contained in:
43
build/rollup.config.js
Normal file
43
build/rollup.config.js
Normal file
@@ -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',
|
||||
external: external,
|
||||
globals: globals,
|
||||
plugins: plugins
|
||||
}
|
@@ -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' })
|
||||
|
Reference in New Issue
Block a user