This repository has been archived by the owner on Jul 12, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.js
100 lines (95 loc) · 2.45 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
import commonjs from '@rollup/plugin-commonjs';
import json from '@rollup/plugin-json';
import nodeResolve from '@rollup/plugin-node-resolve';
import url from '@rollup/plugin-url';
import path from 'path';
import postcssUrl from 'postcss-url';
import postcss from 'rollup-plugin-postcss';
import typescript2 from 'rollup-plugin-typescript2';
import packageJson from './package.json';
const COMMONJS_EXTENSION = 'cjs';
const ESM_EXTENSION = 'js';
const IS_DEV = process.env.NODE_ENV === 'development';
const MAIN_DIR = path.parse(packageJson.main).dir;
const MODULE_DIR = path.parse(packageJson.module).dir;
const TSCONFIG = IS_DEV ? './tsconfig.development.json' : './tsconfig.json';
const EXTERNAL = new Set([
...Object.keys(packageJson.dependencies || Object.create(null)),
...Object.keys(packageJson.peerDependencies || Object.create(null)),
]);
export default [
{
cache: true,
input: 'src/index.ts',
treeshake: !IS_DEV,
external(id) {
if (EXTERNAL.has(id)) {
return true;
}
for (const pkg of EXTERNAL) {
if (id.startsWith(`${pkg}/`)) {
return true;
}
}
return false;
},
output: [
{
chunkFileNames: `[name]-[hash].${COMMONJS_EXTENSION}`,
dir: MAIN_DIR,
entryFileNames: `[name].${COMMONJS_EXTENSION}`,
exports: 'named',
format: 'cjs',
sourcemap: IS_DEV,
},
{
chunkFileNames: `[name]-[hash].${ESM_EXTENSION}`,
dir: MODULE_DIR,
entryFileNames: `[name].${ESM_EXTENSION}`,
format: 'es',
sourcemap: IS_DEV,
},
],
plugins: [
json({
compact: !IS_DEV,
}),
url(),
postcss({
autoModules: true,
extract: false,
minimize: !IS_DEV,
plugins: [
postcssUrl([
{
encodeType: 'base64',
maxSize: 1024,
url: 'inline',
},
{
assetsPath: 'images',
url: 'copy',
useHash: true,
},
]),
],
use: ['sass'],
}),
nodeResolve({
extensions: ['.js', '.jsx', '.ts', '.tsx'],
preferBuiltins: true,
}),
commonjs({
extensions: ['.js', '.jsx'],
}),
typescript2({
check: !IS_DEV,
tsconfig: TSCONFIG,
useTsconfigDeclarationDir: true,
}),
],
watch: {
exclude: 'node_modules/**',
},
},
];