-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.js
67 lines (60 loc) · 1.83 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
import terser from '@rollup/plugin-terser'
import progress from 'rollup-plugin-progress';
import pkg from "./package.json" assert {type: "json"}
import fs from "node:fs"
const production = process.env.MODE === 'production'
const sourcemap = !production
const banner = `
/**
* Datetime v${pkg.version}.
* Copyright ${new Date().getFullYear()} by Serhii Pimenov
* Licensed under MIT
*
* Build time: ${new Date().toLocaleDateString()} ${new Date().toLocaleTimeString()}
*/
`
let txt
txt = fs.readFileSync(`src/browser.js`, 'utf8')
txt = txt.replace(/version = ".+"/g, `version = "${pkg.version}"`)
txt = txt.replace(/build_time = ".+"/g, `build_time = "${new Date().toLocaleString()}"`)
fs.writeFileSync(`src/browser.js`, txt, { encoding: 'utf8', flag: 'w+' })
txt = fs.readFileSync(`src/index.js`, 'utf8')
txt = txt.replace(/version = ".+"/g, `version = "${pkg.version}"`)
txt = txt.replace(/build_time = ".+"/g, `build_time = "${new Date().toLocaleString()}"`)
fs.writeFileSync(`src/index.js`, txt, { encoding: 'utf8', flag: 'w+' })
export default [
{
input: './src/browser.js',
watch: { clearScreen: false },
output: {
file: './lib/datetime.js',
format: 'iife',
sourcemap: false,
banner,
plugins: [
production && terser({
keep_classnames: true,
keep_fnames: true,
})
],
}
},
{
input: './src/index.js',
watch: { clearScreen: false },
output: {
file: './dist/datetime.es.js',
format: 'es',
banner,
}
},
{
input: './src/index.js',
watch: { clearScreen: false },
output: {
file: './dist/datetime.cjs.js',
format: 'cjs',
banner,
}
},
];