-
-
Notifications
You must be signed in to change notification settings - Fork 99
Expand file tree
/
Copy pathrollup.config.js
More file actions
80 lines (70 loc) · 1.91 KB
/
rollup.config.js
File metadata and controls
80 lines (70 loc) · 1.91 KB
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
import { readFileSync, existsSync } from 'node:fs'
import { builtinModules } from 'node:module'
import terser from '@rollup/plugin-terser'
import commonjs from '@rollup/plugin-commonjs'
import json from '@rollup/plugin-json'
import { nodeResolve } from '@rollup/plugin-node-resolve'
import replace from '@rollup/plugin-replace'
import typescript from '@rollup/plugin-typescript'
import copy from 'rollup-plugin-copy'
import { string } from 'rollup-plugin-string'
const pkg = JSON.parse(readFileSync('./package.json', 'utf8'))
const version = process.env.VERSION || pkg.version
const sourcemap = true
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 external = [
...(Object.keys(pkg.dependencies || {}).map(packageName => new RegExp(`^${packageName}(/.*)?`))),
...builtinModules.map(moduleName => new RegExp(`^(node:)?${moduleName}(/.*)?`))
]
const plugins = [
typescript({ tsconfig: './tsconfig.json' }),
commonjs(),
nodeResolve({ preferBuiltins: true }),
string({
include: ['**/*.applescript', '**/*.ps1', '**/*.sh']
}),
json(),
replace({
'process.env.PICGO_VERSION': JSON.stringify(pkg.version),
preventAssignment: true
})
]
if (existsSync('assets')) {
plugins.splice(1, 0, copy({ targets: [{ src: 'assets', dest: 'dist' }] }))
}
const isDev = process.env.NODE_ENV === 'development'
const commonOptions = {
external,
plugins,
input
}
if (!isDev) {
commonOptions.plugins.push(terser())
}
/** @type import('rollup').RollupOptions[] */
const bundles = [
{
output: [{
file: 'dist/index.cjs.js',
format: 'cjs',
banner,
sourcemap
}],
...commonOptions
},
{
output: [{
file: 'dist/index.esm.js',
format: 'esm',
banner,
sourcemap
}],
...commonOptions
}
]
export default bundles