forked from buefy/buefy
-
Notifications
You must be signed in to change notification settings - Fork 1
/
rollup.config.js
171 lines (159 loc) · 4.47 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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
import vue from 'rollup-plugin-vue'
import node from 'rollup-plugin-node-resolve'
import cjs from 'rollup-plugin-commonjs'
import babel from 'rollup-plugin-babel'
import { terser } from 'rollup-plugin-terser'
import fs from 'fs'
import path from 'path'
import pack from './package.json'
const babelConfig = {
exclude: 'node_modules/**',
runtimeHelpers: true,
babelrc: false,
presets: [['@babel/preset-env', { modules: false }]]
}
const bannerTxt = `/*! Buefy v${pack.version} | MIT License | github.com/buefy/buefy */`
const baseFolder = './src/'
const componentsFolder = 'components/'
const components = fs
.readdirSync(baseFolder + componentsFolder)
.filter((f) =>
fs.statSync(path.join(baseFolder + componentsFolder, f)).isDirectory()
)
const entries = {
'index': './src/index.js',
'helpers': './src/utils/helpers.js',
'config': './src/utils/ConfigComponent.js',
...components.reduce((obj, name) => {
obj[name] = (baseFolder + componentsFolder + name)
return obj
}, {})
}
const capitalize = (s) => {
if (typeof s !== 'string') return ''
return s.charAt(0).toUpperCase() + s.slice(1)
}
const vuePluginConfig = {
template: {
isProduction: true,
compilerOptions: {
whitespace: 'condense'
}
}
}
export default () => {
const mapComponent = (name) => {
return [
{
input: baseFolder + componentsFolder + `${name}/index.js`,
external: ['vue'],
output: {
format: 'umd',
name: capitalize(name),
file: `dist/components/${name}/index.js`,
banner: bannerTxt,
exports: 'named',
globals: {
vue: 'Vue'
}
},
plugins: [
node({
extensions: ['.vue', '.js']
}),
cjs(),
vue(vuePluginConfig),
babel(babelConfig)
]
}
]
}
let config = [
{
input: entries,
external: ['vue'],
output: {
format: 'esm',
dir: `dist/esm`
},
plugins: [
node({
extensions: ['.vue', '.js']
}),
vue(vuePluginConfig),
babel(babelConfig),
cjs()
]
},
{
input: entries,
external: ['vue'],
output: {
format: 'cjs',
dir: 'dist/cjs',
exports: 'named'
},
plugins: [
node({
extensions: ['.vue', '.js']
}),
vue(vuePluginConfig),
babel(babelConfig),
cjs()
]
},
{
input: 'src/index.js',
external: ['vue'],
output: {
format: 'umd',
name: capitalize('buefy'),
file: 'dist/buefy.js',
exports: 'named',
banner: bannerTxt,
globals: {
vue: 'Vue'
}
},
plugins: [
node({
extensions: ['.vue', '.js']
}),
vue(vuePluginConfig),
babel(babelConfig),
cjs()
]
},
{
input: 'src/index.js',
external: ['vue'],
output: {
format: 'esm',
file: 'dist/buefy.esm.js',
banner: bannerTxt
},
plugins: [
node({
extensions: ['.vue', '.js']
}),
vue(vuePluginConfig),
babel(babelConfig),
cjs()
]
},
// individual components
...components.map((f) => mapComponent(f)).reduce((r, a) => r.concat(a), [])
]
if (process.env.MINIFY === 'true') {
config = config.filter((c) => !!c.output.file)
config.forEach((c) => {
c.output.file = c.output.file.replace(/\.js/g, '.min.js')
c.plugins.push(terser({
output: {
comments: '/^!/'
}
}))
})
}
return config
}