-
Notifications
You must be signed in to change notification settings - Fork 8
/
rollup.config.js
158 lines (142 loc) · 3.84 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
/* -------------------------------------------------------------------------- */
/* External Dependencies */
/* -------------------------------------------------------------------------- */
import * as path from 'path';
import pluginTypescript from '@rollup/plugin-typescript';
import pluginCommonjs from '@rollup/plugin-commonjs';
import pluginNodeResolve from '@rollup/plugin-node-resolve';
import { babel } from '@rollup/plugin-babel';
import replace from '@rollup/plugin-replace';
import { terser } from 'rollup-plugin-terser';
import multiInput from 'rollup-plugin-multi-input';
import postcss from 'rollup-plugin-postcss';
import postcssImport from 'postcss-import';
import autoprefixer from 'autoprefixer';
import serve from 'rollup-plugin-serve';
import livereload from 'rollup-plugin-livereload';
import analyze from 'rollup-plugin-analyzer';
import visualizer from 'rollup-plugin-visualizer';
/* -------------------------- Internal Dependencies ------------------------- */
import pkg from './package.json';
import defaultTsConfig from './tsconfig.json';
const moduleName = pkg.name.replace(/^@.*\//, '');
const inputFileName = [
'src/**/*.ts',
process.env.NODE_ENV === 'prod' ? 'src/!(test.tsx)/**/*.tsx' : 'src/**/*.tsx',
];
const author = pkg.author;
const bundles = {
es: 'dist/bundle-es',
cjs: 'dist/bundle-cjs',
browser: 'dist/scout-bar',
};
const banner = `
/**
* ${moduleName}.js
* @summary ${pkg.description}
* @version v${pkg.version}
* @author ${author}
* @license Released under the ${pkg.license} license.
* @copyright Adenekan Wonderful 2021
*/
`;
const pluginsSetups = bundle => ({
external: ['react', 'react-dom'],
plugins: [
multiInput(),
postcss({ plugins: [postcssImport(), autoprefixer()], minimize: true }),
pluginTypescript({
...defaultTsConfig.compilerOptions,
...{
declaration: true,
emitDeclarationOnly: true,
outDir: `${bundle}`,
declarationDir: `${bundle}`,
exclude: [
'node_modules',
'dist',
process.env.NODE_ENV === 'prod' ? 'src/test.tsx' : '',
],
},
}),
analyze({
hideDeps: true,
summaryOnly: true,
}),
visualizer(),
babel({
babelHelpers: 'bundled',
configFile: path.resolve(__dirname, '.babelrc.js'),
extensions: ['.ts', '.tsx'],
exclude: 'node_modules/**',
}),
pluginCommonjs({
extensions: ['.ts', '.tsx'],
}),
replace({
'process.env.NODE_ENV': JSON.stringify(
process.env.NODE_ENV === 'prod' ? 'production' : 'development'
),
preventAssignment: true,
}),
pluginNodeResolve({
browser: bundle === bundles.browser ? true : false,
}),
],
});
export default [
{
input: inputFileName,
output: [
{
name: moduleName,
dir: bundles.browser,
format: 'esm',
sourcemap: 'inline',
banner,
plugins:
process.env.NODE_ENV === 'prod'
? [terser()]
: [
serve({
verbose: true,
contentBase: '',
historyApiFallback: false,
host: 'localhost',
port: 3008,
}),
livereload('dist'),
],
},
],
...pluginsSetups(bundles.browser),
},
// ES
{
input: inputFileName,
output: [
{
dir: bundles.es,
format: 'es',
sourcemap: 'inline',
banner,
exports: 'named',
},
],
...pluginsSetups(bundles.es),
},
// CommonJS
{
input: inputFileName,
output: [
{
dir: bundles.cjs,
format: 'cjs',
sourcemap: 'inline',
banner,
exports: 'named',
},
],
...pluginsSetups(bundles.cjs),
},
];