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

XhmikosR's avatar
XhmikosR committed
3
4
const path = require('path')
const babel = require('rollup-plugin-babel')
Johann-S's avatar
Johann-S committed
5
const resolve = 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
15
16
17
18
19
20
21
22
23
24
25
  babel({
  // Only transpile our source code
    exclude: 'node_modules/**',
    // Include only required helpers
    externalHelpersWhitelist: [
      'defineProperties',
      'createClass',
      'inheritsLoose',
      'defineProperty',
      'objectSpread'
    ]
  })
26
27
28
29
30
31
]
const globals = {
  'popper.js': 'Popper'
}

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

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

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

module.exports = rollupConfig