bootstrap/build/rollup.config.mjs

60 lines
1.4 KiB
JavaScript
Raw Permalink Normal View History

2023-08-06 04:37:24 +00:00
import path from 'node:path'
import process from 'node:process'
import { fileURLToPath } from 'node:url'
import { babel } from '@rollup/plugin-babel'
import { nodeResolve } from '@rollup/plugin-node-resolve'
import replace from '@rollup/plugin-replace'
import banner from './banner.mjs'
2023-08-06 04:37:24 +00:00
const __dirname = path.dirname(fileURLToPath(import.meta.url))
2017-12-16 12:00:38 +00:00
2019-02-26 11:20:34 +00:00
const BUNDLE = process.env.BUNDLE === 'true'
2019-03-01 09:11:41 +00:00
const ESM = process.env.ESM === 'true'
2023-08-06 04:37:24 +00:00
let destinationFile = `bootstrap${ESM ? '.esm' : ''}`
2020-06-19 08:17:01 +00:00
const external = ['@popperjs/core']
const plugins = [
babel({
// Only transpile our source code
exclude: 'node_modules/**',
// Include the helpers in the bundle, at most one copy of each
babelHelpers: 'bundled'
})
]
const globals = {
2020-06-19 08:17:01 +00:00
'@popperjs/core': 'Popper'
}
if (BUNDLE) {
2023-08-06 04:37:24 +00:00
destinationFile += '.bundle'
2018-10-14 11:59:51 +00:00
// Remove last entry in external array to bundle Popper
external.pop()
2020-06-19 08:17:01 +00:00
delete globals['@popperjs/core']
plugins.push(
replace({
'process.env.NODE_ENV': '"production"',
preventAssignment: true
}),
nodeResolve()
)
}
2019-03-01 09:11:41 +00:00
const rollupConfig = {
2019-03-01 22:50:31 +00:00
input: path.resolve(__dirname, `../js/index.${ESM ? 'esm' : 'umd'}.js`),
output: {
banner: banner(),
2023-08-06 04:37:24 +00:00
file: path.resolve(__dirname, `../dist/js/${destinationFile}.js`),
2019-03-01 09:11:41 +00:00
format: ESM ? 'esm' : 'umd',
globals,
generatedCode: 'es2015'
},
external,
plugins
}
2019-03-01 09:11:41 +00:00
if (!ESM) {
rollupConfig.output.name = 'bootstrap'
}
2023-08-06 04:37:24 +00:00
export default rollupConfig