forked from GetStream/react-activity-feed
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.js
98 lines (90 loc) · 2.34 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
import process from 'process';
import babel from '@rollup/plugin-babel';
import commonjs from '@rollup/plugin-commonjs';
import external from 'rollup-plugin-peer-deps-external';
import json from '@rollup/plugin-json';
import resolve from '@rollup/plugin-node-resolve';
import globals from 'rollup-plugin-node-globals';
import postcss from 'rollup-plugin-postcss';
import autoprefixer from 'autoprefixer';
import pkg from './package.json';
process.env.NODE_ENV = 'production';
const styleBundle = (watch = false) => ({
input: 'src/styles/index.scss',
cache: false,
watch: watch ? { include: 'src/styles/**/*', chokidar: false } : {},
output: [{ file: pkg.style, format: 'es' }],
plugins: [
// TODO: find out how to implement "failOnError"
postcss({
extract: true,
minimize: true,
plugins: [autoprefixer],
}),
],
});
const extensions = ['.js', '.jsx', '.ts', '.tsx'];
const baseConfig = {
input: 'src/index.tsx',
cache: false,
watch: { chokidar: false },
};
const normalBundle = {
...baseConfig,
output: [
{
file: pkg.main,
format: 'cjs',
sourcemap: true,
},
],
external: [
/@babel/,
'@webscopeio/react-textarea-autocomplete',
/dayjs/,
/emoji-mart/,
'getstream',
'i18next',
'immutable',
/linkifyjs/,
/lodash/,
'react-file-utils',
'react-image-lightbox',
'stream-analytics',
'url-parse',
'use-debounce',
],
plugins: [
resolve({ browser: true, extensions }),
commonjs({ include: /node_modules/ }),
json(),
external(),
babel({ babelHelpers: 'runtime', exclude: 'node_modules/**', extensions }),
],
};
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: [
resolve({ browser: true, extensions }),
commonjs({ include: /node_modules/ }),
external(),
babel({ babelHelpers: 'runtime', exclude: 'node_modules/**', extensions }),
json(),
globals({ process: true }),
],
};
export default () =>
process.env.ROLLUP_WATCH ? [styleBundle(true), normalBundle] : [styleBundle(), normalBundle, fullBrowserBundle];