forked from nl-design-system/denhaag
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.mjs
111 lines (102 loc) · 2.58 KB
/
rollup.config.mjs
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
import typescript from 'rollup-plugin-typescript2';
import nodeResolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import svgrImport from '@svgr/rollup';
import _ from 'lodash';
import fs from 'node:fs';
import path from 'node:path';
import { cwd } from 'node:process';
import postcss from 'rollup-plugin-postcss';
import discardDuplicates from 'postcss-discard-duplicates';
import { readFileSync } from 'node:fs';
import summary from 'rollup-plugin-summary';
const svgr = svgrImport.default;
const tsconfig = JSON.parse(readFileSync('./tsconfig.json', 'utf8'));
const inputExists = (config) => {
try {
return fs.existsSync(config.input);
} catch (e) {
return false;
}
};
const externalDependencies = [
'@material-ui/core',
'@material-ui/lab',
'react',
'react-dom',
'date-fns',
'@material-ui/core/transitions',
'@material-ui/core/OverridableComponent',
];
const internalDependencies = _.keys(tsconfig.compilerOptions.paths);
const dependencies = externalDependencies.concat(internalDependencies);
const createConfig = ({ dir, format, baseUrl }) => ({
input: path.join(baseUrl, 'src/index.tsx'),
output: {
dir,
sourcemap: false,
format,
compact: true,
},
plugins: [
postcss({
extensions: ['.css', '.scss'],
minimize: true,
}),
nodeResolve(),
commonjs({ include: /node_modules/ }),
svgr({ icon: true, svgo: true, memo: true }),
typescript({
cacheDir: path.join(path.dirname(import.meta.url), '.rollup-cache'),
tsconfig: path.join(baseUrl, 'tsconfig.json'),
tsBuildInfoFile: path.join(baseUrl, '.tsbuildinfo'),
compilerOptions: {
outDir: dir,
},
}),
summary(),
],
external: dependencies,
});
const baseUrl = cwd();
const configs = [
createConfig({ format: 'cjs', dir: './dist/cjs', baseUrl }),
createConfig({ format: 'esm', dir: './dist/mjs', baseUrl }),
{
input: 'src/index.scss',
output: {
dir: './dist',
sourcemap: false,
format: 'esm',
compact: true,
},
plugins: [
postcss({
extensions: ['.css', '.scss'],
extract: true,
}),
],
},
{
input: 'src/index.scss',
output: {
dir: './dist',
sourcemap: false,
format: 'esm',
compact: true,
},
plugins: [
postcss({
extensions: ['.css', '.scss'],
plugins: [discardDuplicates()],
extract: true,
}),
],
},
]
.map(({ input, ...config }) => ({
...config,
input: path.resolve(cwd(), input),
}))
.filter(inputExists);
export default configs;