forked from trevoreyre/autocomplete
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.js
98 lines (94 loc) · 2.5 KB
/
rollup.config.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
import babel from 'rollup-plugin-babel'
import { terser } from 'rollup-plugin-terser'
import commonjs from 'rollup-plugin-commonjs'
import vue from 'rollup-plugin-vue'
import postcss from 'rollup-plugin-postcss'
import copy from 'rollup-plugin-copy'
// Creates three bundles, a CommonJS bundle for Node, an ES modules bundle for use in
// other bundlers such as Webpack or Rollup, and an IIFE bundle for use in the browser
// in a <script> tag. All three bundles are transpiled to ES5 (with exception of
// the import/export statements in the ES bundle). Function is async to allow importing
// package.json file to reference for bundle names.
const createConfig = async ({ root, plugins = [] }) => {
const pkg = await import(`./${root}/package.json`)
return Promise.resolve([
// CommonJS and ES modules bundles use same configuration with two outputs
{
input: `${root}/index.js`,
output: [
{
file: `${root}/${pkg.main}`,
format: 'cjs',
},
{
file: `${root}/${pkg.module}`,
format: 'esm',
},
],
plugins: [
babel({
exclude: 'node_modules/**',
}),
postcss({
extract: `${root}/dist/style.css`,
minimize: true,
}),
copy({
targets: {
LICENSE: `${root}/LICENSE`,
},
}),
...plugins,
],
},
// IIFE bundle uses separate configuration to minify JS as additional step
{
input: `${root}/index.js`,
output: {
name: 'Autocomplete',
file: `${root}/${pkg.unpkg}`,
format: 'iife',
},
plugins: [
babel({
exclude: 'node_modules/**',
}),
postcss({
extract: `${root}/dist/style.css`,
minimize: true,
}),
...plugins,
terser(),
],
},
])
}
const config = async () => {
const [
autocompleteConfig,
autocompleteJsConfig,
autocompleteVueConfig,
] = await Promise.all([
createConfig({ root: 'packages/autocomplete' }),
createConfig({ root: 'packages/autocomplete-js' }),
createConfig({
root: 'packages/autocomplete-vue',
plugins: [
commonjs(),
vue({
css: false,
compileTemplate: true,
template: {
isProduction: true,
},
}),
],
}),
])
return Promise.resolve([
...autocompleteConfig,
...autocompleteJsConfig,
...autocompleteVueConfig,
])
}
export default config