forked from GetStream/stream-chat-react
/
rollup.config.js
201 lines (194 loc) · 4.86 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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
// @flow
import babel from 'rollup-plugin-babel';
import external from 'rollup-plugin-peer-deps-external';
import commonjs from 'rollup-plugin-commonjs';
import scss from 'rollup-plugin-scss';
import json from 'rollup-plugin-json';
import url from 'rollup-plugin-url';
import copy from 'rollup-plugin-copy-glob';
import resolve from 'rollup-plugin-node-resolve';
import builtins from '@stream-io/rollup-plugin-node-builtins';
import globals from 'rollup-plugin-node-globals';
import PropTypes from 'prop-types';
import replace from 'rollup-plugin-replace';
import process from 'process';
import pkg from './package.json';
process.env.NODE_ENV = 'production';
const baseConfig = {
input: 'src/index.js',
cache: false,
watch: {
chokidar: false,
},
};
const normalBundle = {
...baseConfig,
output: [
{
file: pkg.main,
format: 'cjs',
sourcemap: true,
},
{
file: pkg.module,
format: 'es',
sourcemap: true,
},
],
external: [
'linkifyjs',
'linkifyjs/lib/linkify',
'dayjs',
'dayjs/plugin/calendar',
'dayjs/plugin/updateLocale',
'dayjs/plugin/localizedFormat',
'dayjs/plugin/localeData',
'dayjs/plugin/relativeTime',
'stream-chat-client',
'react-images',
'lodash/debounce',
'lodash/throttle',
'lodash/truncate',
'i18next',
'moment',
'dayjs/locale/nl',
'dayjs/locale/it',
'dayjs/locale/ru',
'dayjs/locale/tr',
'dayjs/locale/fr',
'dayjs/locale/hi',
'dayjs/locale/es',
'dayjs/locale/en',
'lodash/uniq',
'lodash.uniqby',
'emoji-mart',
'emoji-mart/data/all.json',
'emoji-regex',
'seamless-immutable',
'isomorphic-ws',
'visibilityjs',
'custom-event',
'textarea-caret',
'@braintree/sanitize-url',
'@webscopeio/react-textarea-autocomplete',
'@webscopeio/react-textarea-autocomplete/style.css',
'emoji-mart/css/emoji-mart.css',
'react-dropzone',
'react-markdown',
'deep-equal',
'shallow-diff',
'immutable',
'url-parse',
'stream-chat',
'pretty-bytes',
'stream-analytics',
'react-textarea-autosize',
'prop-types',
'react-player',
'react-markdown/with-html',
'react-file-utils',
'react-file-utils/dist/index.css',
'uuid/v4',
'uuid',
'@fortawesome/react-fontawesome',
'@fortawesome/free-regular-svg-icons',
'@babel/runtime/regenerator',
'@babel/runtime/helpers/asyncToGenerator',
'@babel/runtime/helpers/objectWithoutProperties',
'@babel/runtime/helpers/toConsumableArray',
'@babel/runtime/helpers/objectSpread',
'@babel/runtime/helpers/extends',
'@babel/runtime/helpers/defineProperty',
'@babel/runtime/helpers/assertThisInitialized',
'@babel/runtime/helpers/inherits',
'@babel/runtime/helpers/getPrototypeOf',
'@babel/runtime/helpers/possibleConstructorReturn',
'@babel/runtime/helpers/createClass',
'@babel/runtime/helpers/classCallCheck',
'@babel/runtime/helpers/slicedToArray',
'@babel/runtime/helpers/typeof',
'react-is',
],
plugins: [
replace({
'process.env.NODE_ENV': JSON.stringify('production'),
}),
external(),
babel({
runtimeHelpers: true,
exclude: 'node_modules/**',
}),
scss({
output: pkg.style,
prefix: `@import "./variables.scss";`,
}),
copy(
[
{ files: 'src/styles/**/*', dest: 'dist/scss' },
{ files: 'src/assets/*', dest: 'dist/assets' },
{ files: 'src/i18n/*.json', dest: 'dist/i18n' },
],
{
verbose: true,
watch: process.env.ROLLUP_WATCH,
},
),
url(),
commonjs(),
json(),
],
};
const fullBrowserBundle = {
...baseConfig,
output: [
{
file: pkg.jsdelivr,
format: 'iife',
sourcemap: true,
name: 'window', // write all exported values to window
extend: true, // extend window, not overwrite it
globals: {
react: 'React',
'react-dom': 'ReactDOM',
},
},
],
plugins: [
replace({
'process.env.NODE_ENV': JSON.stringify('production'),
}),
external(),
babel({
runtimeHelpers: true,
exclude: 'node_modules/**',
}),
{
name: 'ignore-css-and-scss',
resolveId: (importee) => (importee.match(/.s?css$/) ? importee : null),
load: (id) => (id.match(/.s?css$/) ? '' : null),
},
builtins(),
resolve({
browser: true,
}),
url(),
commonjs({
namedExports: {
'prop-types': Object.keys(PropTypes),
'node_modules/react-is/index.js': ['isValidElementType'],
},
}),
json(),
globals({
process: true,
globals: false,
buffer: false,
dirname: false,
filename: false,
}),
copy([{ files: 'src/i18n/*.json', dest: 'dist/i18n' }]),
// terser(),
],
};
export default () =>
process.env.ROLLUP_WATCH ? [normalBundle] : [normalBundle, fullBrowserBundle];