-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrollup.config.ts
164 lines (145 loc) · 3.98 KB
/
rollup.config.ts
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
import fs from 'fs';
import glob from 'glob';
// import path from 'path';
// import cleaner from 'rollup-plugin-cleaner';
import del from 'rollup-plugin-delete';
import { uglify } from 'rollup-plugin-uglify';
import externals from 'rollup-plugin-node-externals';
import commonjs from '@rollup/plugin-commonjs';
import resolve from '@rollup/plugin-node-resolve';
// import styles from 'rollup-plugin-styles';
import postcss from 'rollup-plugin-postcss';
import postcssPresetEnv from 'postcss-preset-env';
import cssnano from 'cssnano';
// import postcss from 'rollup-plugin-postcss';
// import stylusCssModules from 'rollup-plugin-stylus-css-modules';
// import svg from 'rollup-plugin-svg';
import svgr from '@svgr/rollup';
import json from '@rollup/plugin-json';
// import dts from '@guanghechen/postcss-modules-dts';
// import dts from 'rollup-plugin-dts';
// import { babel } from '@rollup/plugin-babel';
import typescript from 'rollup-plugin-typescript2';
import pkg from './package.json' assert { type: 'json' };
/* initialize CSS files because of a catch-22 situation:
https://github.com/rollup/rollup/issues/1404 */
glob.sync('src/**/*.styl').forEach(css => {
// Use forEach because https://github.com/rollup/rollup/issues/1873
const definition = `${css}.d.ts`;
if (!fs.existsSync(definition))
fs.writeFileSync(
definition,
'const mod: { [cls: string]: string }\nexport default mod\n'
);
});
const external = [
'react',
'react-dom',
'moment',
'timen',
'justorm',
'compareq',
'classnames',
'nanoid',
'lodash.omit',
'lodash.pick',
];
const { COMPRESS } = process.env;
export default [
{
// preserveModules: true,
input: 'index.ts',
output: [
// {
// dir: pkg.main,
// format: 'cjs',
// name: 'uilib',
// sourcemap: true,
// // exports: 'named',
// },
{
dir: pkg.module,
format: 'esm',
// format: 'iife',
// exports: 'named',
sourcemap: Boolean(COMPRESS),
preserveModules: true,
},
],
external,
plugins: [
del({ targets: './dist/*' }),
externals({ deps: true }),
resolve(),
commonjs(),
json(),
svgr({ exportType: 'default' }),
// styles({ modules: true }),
// stylusCssModules({ output: 'index.css' }),
typescript({
useTsconfigDeclarationDir: true,
tsconfig: 'tsconfig.json',
}),
postcss({
minimize: true,
modules: true,
// use: {
// sass: null,
// stylus: null,
// less: null,
// },
// extract: true,
// config: {
// path: './src/docs/config/postcss.config.cjs',
// ctx: {
// env: 'production',
// },
// },
plugins: [
postcssPresetEnv({ stage: 3 }),
cssnano({
preset: [
'default',
{
discardComments: {
removeAll: true,
},
},
],
}),
],
}),
// babel({
// babelHelpers: 'bundled',
// include: path.resolve('src/components'),
// extensions: ['.js', '.ts', '.jsx', '.tsx'],
// }),
COMPRESS && uglify(),
generateLocalLib(),
],
},
// {
// input: 'dist/types/index.d.ts',
// output: [{ file: 'dist/index.d.ts', format: 'esm' }],
// // external: [/\.css$/],
// plugins: [resolve({ extensions: ['.ts', '.js'] }), dts()],
// },
];
function generateLocalLib() {
return {
name: 'generate-local-lib',
writeBundle: (options, bundle) => {
const libJSON = Object.entries(bundle).reduce(
// @ts-ignore
(acc, [path, { code }]) => ({
...acc,
[`/node_modules/@foreverido/uilib/${path}`]: code,
}),
{
'/package.json': JSON.stringify(pkg),
}
);
fs.writeFile('src/docs/localLib.json', JSON.stringify(libJSON), () => {});
},
};
}