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

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

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

XhmikosR's avatar
XhmikosR committed
11
let fileDest = `bootstrap${ESM ? '.esm' : ''}`
12
const external = ['popper.js']
13
const plugins = [
14
  babel({
15
    // Only transpile our source code
16
    exclude: 'node_modules/**',
17
18
    // Include the helpers in the bundle, at most one copy of each
    babelHelpers: 'bundled'
19
  })
20
21
22
23
24
25
]
const globals = {
  'popper.js': 'Popper'
}

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

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

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

module.exports = rollupConfig