-
Notifications
You must be signed in to change notification settings - Fork 83
/
rollup.config.js
87 lines (80 loc) · 2.08 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
import { terser } from 'rollup-plugin-terser'
import pkg from './package.json'
import typescript from 'rollup-plugin-typescript2'
import commonjs from '@rollup/plugin-commonjs'
import { string } from 'rollup-plugin-string'
import json from '@rollup/plugin-json'
import builtins from 'builtins'
import replace from '@rollup/plugin-replace'
const version = process.env.VERSION || pkg.version
const sourcemap = 'inline'
const banner = `/*
* picgo@${version}, https://github.com/PicGo/PicGo-Core
* (c) 2018-${new Date().getFullYear()} PicGo Group
* Released under the MIT License.
*/`
const input = './src/index.ts'
const commonOptions = {
// Creating regex of the packages to make sure sub-paths of the
// packages such as `lowdb/adapters/FileSync` are also treated as external
// See https://github.com/rollup/rollup/issues/3684#issuecomment-926558056
external: [
...Object.keys(pkg.dependencies),
...builtins()
].map(packageName => new RegExp(`^${packageName}(/.*)?`)),
plugins: [
typescript({
tsconfigOverride: {
compilerOptions: {
target: 'ES2017',
module: 'ES2015'
}
}
}),
// terser(),
commonjs(),
string({
// Required to be specified
include: [
'**/*.applescript',
'**/*.ps1',
'**/*.sh'
]
}),
json(),
replace({
'process.env.PICGO_VERSION': JSON.stringify(pkg.version),
preventAssignment: true
})
],
input
}
const isDev = process.env.NODE_ENV === 'development'
if (!isDev) {
commonOptions.plugins.push(terser())
}
/** @type import('rollup').RollupOptions */
const nodeCjs = {
output: [{
file: 'dist/index.cjs.js',
format: 'cjs',
banner,
sourcemap
}],
...commonOptions
}
const nodeEsm = {
output: [{
file: 'dist/index.esm.js',
format: 'esm',
banner,
sourcemap
}],
...commonOptions
}
const bundles = []
const env = process.env.BUNDLES || ''
if (env.includes('cjs')) bundles.push(nodeCjs)
if (env.includes('esm')) bundles.push(nodeEsm)
if (bundles.length === 0) bundles.push(nodeCjs, nodeEsm)
export default bundles