forked from atomiks/tippyjs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.build.js
113 lines (101 loc) · 3.53 KB
/
rollup.build.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
const fs = require('fs')
const pkg = require('./package.json')
const { rollup } = require('rollup')
const babel = require('rollup-plugin-babel')
const minify = require('rollup-plugin-babel-minify')
const sass = require('rollup-plugin-sass')
const postcss = require('postcss')
const autoprefixer = require('autoprefixer')
const cssnano = require('cssnano')
const resolve = require('rollup-plugin-node-resolve')
const commonjs = require('rollup-plugin-commonjs')
const cssOnly = require('rollup-plugin-css-only')
const json = require('rollup-plugin-json')
const { magenta, red, green, blue, bold, yellow } = require('colorette')
// wrapper utils
const sassPluginOutput = name =>
sass({
output: name,
processor: css =>
postcss([autoprefixer, cssnano])
.process(css)
.then(result => result.css),
})
const r = (entryFile, plugins = [], excludePopper) =>
rollup({
input: `./build/${entryFile}`,
plugins:
typeof plugins === 'string'
? [sassPluginOutput(plugins), cssOnly({ output: plugins })]
: [
pluginJSON,
pluginSCSS,
pluginCSS,
...plugins,
pluginCJS,
pluginResolve,
],
external: excludePopper ? ['popper.js'] : [],
})
const output = type => (fileName, { min, sourcemap = true } = {}) => ({
name: 'tippy',
format: type,
file: `./dist/${type === 'es' ? 'esm/' : ''}${fileName}`,
globals: { 'popper.js': 'Popper' },
sourcemap,
banner: min
? false
: `/*!
* Tippy.js v${pkg.version}
* (c) 2017-${new Date().getFullYear()} atomiks
* MIT
*/`,
})
// plugins
const pluginES5 = babel({
presets: [['env', { modules: false }], 'stage-2'],
plugins: ['external-helpers'],
})
const pluginMinify = minify({ comments: false })
const pluginJSON = json()
const pluginSCSS = sassPluginOutput('./dist/tippy.css')
const pluginCSS = cssOnly({ output: false })
const pluginCJS = commonjs()
const pluginResolve = resolve({ browser: true })
const umd = output('umd')
const esm = output('es')
const build = async () => {
console.log(blue('⏳ Building UMD and ESM bundles...'))
// Tippy + Popper
const bundle = await r('bundle.js', [pluginES5])
// "all" is reliant on the existence of compiled css
await bundle.write(umd('tippy.js'))
const bundleMin = await r('bundle.js', [pluginES5, pluginMinify])
// Tippy
const standalone = await r('bundle.js', [pluginES5], true)
const standaloneMin = await r('bundle.js', [pluginES5, pluginMinify], true)
// Tippy + Popper + CSS
const all = await r('main.js', [pluginES5])
const allMin = await r('main.js', [pluginES5, pluginMinify])
all.write(umd('tippy.all.js'))
allMin.write(umd('tippy.all.min.js', { min: true }))
console.log(green('✓ All'))
bundle.write(esm('tippy.js'))
bundleMin.write(umd('tippy.min.js', { min: true }))
bundleMin.write(esm('tippy.min.js', { min: true }))
console.log(green('✓ Bundle'))
standalone.write(umd('tippy.standalone.js'))
standalone.write(esm('tippy.standalone.js'))
standaloneMin.write(umd('tippy.standalone.min.js', { min: true }))
standaloneMin.write(esm('tippy.standalone.min.js', { min: true }))
console.log(green('✓ Standalone'))
console.log(blue('\n⏳ Building CSS themes...'))
for (let theme of fs.readdirSync('./src/scss/themes')) {
theme = theme.replace('.scss', '')
const t = await r(`themes/${theme}.js`, `./dist/themes/${theme}.css`)
await t.write(umd(`tippy.${theme}.js`, { sourcemap: false }))
fs.unlinkSync(`./dist/tippy.${theme}.js`)
}
console.log(green('✓ Themes\n'))
}
build()