-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathrollup.config.js
119 lines (111 loc) · 2.89 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
110
111
112
113
114
115
116
117
118
119
import { babel } from '@rollup/plugin-babel'
import commonjs from '@rollup/plugin-commonjs'
import replace from '@rollup/plugin-replace'
import terser from '@rollup/plugin-terser'
import copy from 'rollup-plugin-copy'
import replacement from 'rollup-plugin-module-replacement'
import uploadcare from 'uploadcare-widget'
const bundleConfig = ({ format, dir, minify, widgetBundle }) => {
const bundleExtension = format === 'cjs' ? 'cjs' : 'mjs'
const typesExtenson = format === 'cjs' ? 'cts' : 'mts'
return {
input: 'src/index.js',
external: ['react', 'react-fast-compare', 'uploadcare-widget'],
output: {
entryFileNames: `[name].${bundleExtension}`,
chunkFileNames: `[name]-[hash].${bundleExtension}`,
format,
dir,
sourcemap: false
},
plugins: [
widgetBundle &&
replacement({
entries: [
{
find: 'uploadcare-widget',
replacement: `uploadcare-widget/${widgetBundle}`
}
]
}),
commonjs({
include: /node_modules/,
sourceMap: false
}),
babel({
exclude: 'node_modules/**',
presets: [['@babel/env', { modules: false }]],
babelHelpers: 'bundled'
}),
minify && terser(),
copy({
targets: [
{
src: 'types/index.d.ts',
dest: dir,
rename: `index.d.${typesExtenson}`
}
]
})
].filter(Boolean)
}
}
export default [
// esm build with all locales
bundleConfig({ format: 'esm', dir: 'dist/esm' }),
// cjs build with all locales
bundleConfig({ format: 'cjs', dir: 'dist/cjs' }),
// minified builds with all locales
// Saves ~13 KB on react-widget and ~227 KB on uploadcare-widget
bundleConfig({
format: 'cjs',
dir: 'dist/cjs-min',
widgetBundle: 'uploadcare.min.js',
minify: true
}),
bundleConfig({
format: 'esm',
dir: 'dist/esm-min',
widgetBundle: 'uploadcare.min.js',
minify: true
}),
// builds with en locale only (saves ~147 KB on uploadcare-widget)
bundleConfig({
format: 'esm',
dir: 'dist/esm-en',
widgetBundle: 'uploadcare.lang.en.js'
}),
bundleConfig({
format: 'cjs',
dir: 'dist/cjs-en',
widgetBundle: 'uploadcare.lang.en.js'
}),
// minified builds with en locale only
// Saves ~13 KB on react-widget and ~314 KB on uploadcare-widget
bundleConfig({
format: 'esm',
dir: 'dist/esm-en-min',
widgetBundle: 'uploadcare.lang.en.min.js',
minify: true
}),
bundleConfig({
format: 'cjs',
dir: 'dist/cjs-en-min',
widgetBundle: 'uploadcare.lang.en.min.js',
minify: true
}),
{
input: 'src/langs.js',
output: {
format: 'esm',
file: 'locales.js',
sourcemap: false
},
plugins: [
replace({
__LANGS__: JSON.stringify(uploadcare.locales),
preventAssignment: true
})
]
}
]