-
Notifications
You must be signed in to change notification settings - Fork 9
/
rollup.config.js
99 lines (88 loc) · 2.06 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
import * as fs from 'fs'
import gettextParser from 'gettext-parser'
import babel from '@rollup/plugin-babel'
import commonjs from '@rollup/plugin-commonjs'
import replace from '@rollup/plugin-replace'
import resolve from '@rollup/plugin-node-resolve'
import typescript from '@rollup/plugin-typescript'
import postcss from 'rollup-plugin-postcss'
import postcssurl from 'postcss-url'
import BabelLoaderExcludeNodeModulesExcept from 'babel-loader-exclude-node-modules-except'
import { DEFAULT_EXTENSIONS } from '@babel/core'
import { readFile } from 'fs/promises'
const extensions = [...DEFAULT_EXTENSIONS, '.ts', '.tsx']
const packageJson = JSON.parse(
await readFile(
new URL('./package.json', import.meta.url)
)
)
const externals = [
...Object.keys(packageJson?.dependencies || {}),
...Object.keys(packageJson?.peerDependencies || {})
].map(packageName => new RegExp(`^${packageName}`))
const translations = fs
.readdirSync('./l10n')
.filter(name => name !== 'messages.pot' && name.endsWith('.pot'))
.map(file => {
const path = './l10n/' + file
const locale = file.slice(0, -'.pot'.length)
const po = fs.readFileSync(path)
const json = gettextParser.po.parse(po)
return {
locale,
json,
}
})
export default [
{
input: 'lib/index.ts',
output: [
{
file: 'dist/index.cjs',
format: 'cjs',
sourcemap: true
},
{
file: 'dist/index.mjs',
format: 'esm',
sourcemap: true
}
],
external: externals,
plugins: [
resolve({ extensions }),
typescript(),
commonjs({ extensions }),
replace({
preventAssignment: true,
delimiters: ['\\b', '\\b'],
values: {
__TRANSLATIONS__: JSON.stringify(translations)
}
}),
babel({
babelHelpers: 'bundled',
extensions,
exclude: BabelLoaderExcludeNodeModulesExcept(['toastify-js']),
}),
]
},
{
input: 'styles/toast.scss',
output: {
file: 'dist/index.css'
},
plugins: [
postcss({
extract: true,
sourceMap: true,
plugins: [
postcssurl({
url: 'inline',
encodeType: 'base64',
}),
]
})
]
},
]