forked from GetStream/stream-chat-react
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.js
152 lines (145 loc) Β· 4.25 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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
import babel from '@rollup/plugin-babel';
import commonjs from '@rollup/plugin-commonjs';
import image from '@rollup/plugin-image';
import json from '@rollup/plugin-json';
import resolve from '@rollup/plugin-node-resolve';
import typescript from '@rollup/plugin-typescript';
import external from 'rollup-plugin-peer-deps-external';
import url from 'rollup-plugin-url';
import copy from 'rollup-plugin-copy';
import globals from 'rollup-plugin-node-globals';
import visualizer from 'rollup-plugin-visualizer';
import replace from '@rollup/plugin-replace';
import builtins from '@stream-io/rollup-plugin-node-builtins';
import { terser } from 'rollup-plugin-terser';
import { prepend } from 'rollup-plugin-insert';
import process from 'process';
import pkg from './package.json';
process.env.NODE_ENV = 'production';
const baseConfig = {
cache: false,
inlineDynamicImports: true,
input: 'src/index.ts',
watch: {
chokidar: false,
},
};
const externalDependencies = [
/@babel/,
'@braintree/sanitize-url',
'@fortawesome/free-regular-svg-icons',
'@fortawesome/react-fontawesome',
'@juggle/resize-observer',
'@stream-io/transliterate',
'custom-event',
/dayjs/,
/emoji-mart/,
'emoji-regex',
'i18next',
'isomorphic-ws',
'linkifyjs',
'lodash.debounce',
'lodash.isequal',
'lodash.throttle',
'lodash.uniqby',
'mml-react',
'pretty-bytes',
'prop-types',
'react-fast-compare',
'react-images',
'react-image-gallery',
'react-is',
'react-player',
'react-textarea-autosize',
'react-virtuoso',
'textarea-caret',
/uuid/,
];
const basePlugins = ({ useBrowserResolve = false }) => [
replace({
preventAssignment: true,
'process.env.NODE_ENV': JSON.stringify('production'),
}),
// Remove peer-dependencies from final bundle
external(),
image(),
resolve({
browser: useBrowserResolve,
}),
typescript(),
babel({
babelHelpers: 'runtime',
exclude: 'node_modules/**',
}),
commonjs(),
// import files as data-uris or es modules
url(),
copy({
targets: [
{ dest: 'dist/assets', src: './node_modules/@stream-io/stream-chat-css/dist/assets/*' },
{ dest: 'dist/css', src: './node_modules/@stream-io/stream-chat-css/dist/css/*.css' },
{ dest: 'dist/scss', src: './node_modules/@stream-io/stream-chat-css/dist/scss/*' },
{ dest: 'dist/css/v2', src: './node_modules/@stream-io/stream-chat-css/dist/v2/css/*.css' },
{ dest: 'dist/scss/v2', src: './node_modules/@stream-io/stream-chat-css/dist/v2/scss/*' },
],
verbose: process.env.VERBOSE,
watch: process.env.ROLLUP_WATCH,
}),
// Json to ES modules conversion
json({ compact: true }),
process.env.BUNDLE_SIZE ? visualizer() : null,
];
const normalBundle = {
...baseConfig,
external: externalDependencies,
output: [
{
file: pkg.main,
format: 'cjs',
sourcemap: true,
},
],
plugins: [...basePlugins({ useBrowserResolve: false })],
};
const fullBrowserBundle = ({ min } = { min: false }) => ({
...baseConfig,
output: [
{
file: min ? pkg.jsdelivr : pkg.jsdelivr.replace('.min', ''),
format: 'iife',
globals: {
react: 'React',
'react-dom': 'ReactDOM',
'stream-chat': 'StreamChat',
},
name: 'StreamChatReact', // write all exported values to window under key StreamChatReact
sourcemap: true,
},
],
plugins: [
...basePlugins({ useBrowserResolve: true }),
{
load: (id) => (id.match(/.s?css$/) ? '' : null),
name: 'ignore-css-and-scss',
resolveId: (importee) => (importee.match(/.s?css$/) ? importee : null),
},
builtins(),
globals({
buffer: false,
dirname: false,
filename: false,
globals: false,
process: true,
}),
// To work with globals rollup expects them to be namespaced, which is not the case with stream-chat.
// This injects some code to define stream-chat globals as expected by rollup.
prepend(
'window.StreamChat.StreamChat=StreamChat;window.StreamChat.logChatPromiseExecution=logChatPromiseExecution;window.StreamChat.Channel=Channel;window.ICAL=window.ICAL||{};',
),
min ? terser() : null,
],
});
export default () =>
process.env.ROLLUP_WATCH
? [normalBundle]
: [normalBundle, fullBrowserBundle({ min: true }), fullBrowserBundle()];