rollup.config.js 1.12 KB
Newer Older
1
2
'use strict'

XhmikosR's avatar
XhmikosR committed
3
4
const path = require('path')
const babel = require('rollup-plugin-babel')
5
const resolve = require('@rollup/plugin-node-resolve')
XhmikosR's avatar
XhmikosR committed
6
const banner = require('./banner.js')
7
const babelHelpers = require('./babel-helpers.js')
XhmikosR's avatar
XhmikosR committed
8

XhmikosR's avatar
XhmikosR committed
9
const BUNDLE = process.env.BUNDLE === 'true'
Johann-S's avatar
Johann-S committed
10
const ESM = process.env.ESM === 'true'
11

XhmikosR's avatar
XhmikosR committed
12
let fileDest = `bootstrap${ESM ? '.esm' : ''}`
13
const external = ['popper.js']
14
const plugins = [
15
16
17
18
  babel({
  // Only transpile our source code
    exclude: 'node_modules/**',
    // Include only required helpers
19
    externalHelpersWhitelist: babelHelpers
20
  })
21
22
23
24
25
26
]
const globals = {
  'popper.js': 'Popper'
}

if (BUNDLE) {
XhmikosR's avatar
XhmikosR committed
27
  fileDest += '.bundle'
Johann-S's avatar
Johann-S committed
28
29
  // Remove last entry in external array to bundle Popper
  external.pop()
30
  delete globals['popper.js']
Johann-S's avatar
Johann-S committed
31
  plugins.push(resolve())
32
33
}

Johann-S's avatar
Johann-S committed
34
const rollupConfig = {
XhmikosR's avatar
XhmikosR committed
35
  input: path.resolve(__dirname, `../js/index.${ESM ? 'esm' : 'umd'}.js`),
36
  output: {
37
    banner,
XhmikosR's avatar
XhmikosR committed
38
    file: path.resolve(__dirname, `../dist/js/${fileDest}.js`),
Johann-S's avatar
Johann-S committed
39
40
    format: ESM ? 'esm' : 'umd',
    globals
41
42
43
  },
  external,
  plugins
44
}
Johann-S's avatar
Johann-S committed
45
46
47
48
49
50

if (!ESM) {
  rollupConfig.output.name = 'bootstrap'
}

module.exports = rollupConfig