-
Notifications
You must be signed in to change notification settings - Fork 29
/
rollup.config.mjs
53 lines (50 loc) · 1.29 KB
/
rollup.config.mjs
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
import glob from 'glob';
import path from 'path';
import fs from 'fs';
import resolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import terser from '@rollup/plugin-terser';
const watcher = (globs) => ({
buildStart () {
for (const item of globs) {
glob.sync(path.resolve(item)).forEach((filename) => { this.addWatchFile(filename) })
}
}
})
const updateVersion = () => ({
renderStart (outputOptions, inputOptions) {
outputOptions.footer = () => `SdenvExtend.version = 'V${JSON.parse(fs.readFileSync('package.json', 'utf8')).version}'`
}
})
export default () => {
const fileName = 'sdenv-extend';
return {
input: 'src/index.js',
output: [
{
file: `build/${fileName}-cjs.js`,
strict: false,
format: 'cjs',
},
{
file: `build/${fileName}-iife.js`,
format: 'iife',
name: 'SdenvExtend',
strict: false,
plugins: [updateVersion()]
},
{
file: `build/${fileName}-iife.min.js`,
format: 'iife',
name: 'SdenvExtend',
strict: false,
plugins: [terser(), updateVersion()]
}
],
plugins: [
resolve({ moduleDirectories: ['node_modules'] }),
commonjs(),
watcher(['package.json']),
]
}
}