-
Notifications
You must be signed in to change notification settings - Fork 148
/
Copy pathrollup.config.js
109 lines (104 loc) · 2.82 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
/* eslint-env node */
import socialIcons from './rollup-plugin-social-icons.js'
import resolve from '@rollup/plugin-node-resolve'
import { babel } from '@rollup/plugin-babel'
import fs from 'fs'
import copy from 'rollup-plugin-copy'
const packagejson = JSON.parse(fs.readFileSync('./package.json'))
export async function config() {
const networks = (
await fs.promises.readdir(new URL('db', import.meta.url))
).map((filename) => filename.replace('.json', ''))
const external = (id) => {
if (id === 'react') return true
if (id === 'react-dom') return true
if (id === 'react/jsx-runtime') return true
if (/@babel\/runtime/u.test(id)) return true
return false
}
return [
{
input: {
'react-social-icons': 'src/react-social-icons.js',
component: 'src/component.jsx',
'icons/index': 'social-icons',
...networks.reduce((inputMap, network) => {
inputMap[`icons/${network}`] = `social-icons:${network}`
return inputMap
}, {}),
},
output: [
{
format: 'es',
dir: './dist',
entryFileNames: '[name].js',
sourcemap: false,
},
],
plugins: [
socialIcons(),
resolve(),
babel({
babelHelpers: 'runtime',
exclude: '**/node_modules/**',
targets: 'defaults and supports es6-module',
}),
copy({
targets: [
{
src: 'src/react-social-icons.d.ts',
dest: 'dist/',
},
{
src: 'src/react-social-icons.d.ts',
dest: 'dist/',
rename: 'component.d.ts',
},
],
}),
{
name: 'update-package-json-exports',
closeBundle: async () => {
const exports = {}
for (const network of networks) {
exports[`./${network}`] = `./dist/icons/${network}.js`
}
packagejson.exports = {
'.': './dist/react-social-icons.js',
'./component': './dist/component.js',
...exports,
}
await fs.promises.writeFile(
'./package.json',
JSON.stringify(packagejson, null, 2),
)
},
},
],
external,
},
{
input: {
'react-social-icons': 'src/react-social-icons.js',
},
output: {
format: 'cjs',
dir: './dist',
entryFileNames: '[name].cjs',
name: 'ReactSocialIcons',
sourcemap: false,
},
plugins: [
socialIcons(),
resolve(),
babel({
babelHelpers: 'runtime',
exclude: '**/node_modules/**',
targets: 'maintained node versions',
}),
],
external,
},
]
}
export default config()