This repository was archived by the owner on Nov 5, 2024. It is now read-only.
generated from CharlesStover/node-package-template
-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathrollup.config.js
69 lines (64 loc) · 1.71 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
import commonjs from '@rollup/plugin-commonjs';
import nodeResolve from '@rollup/plugin-node-resolve';
import path from 'path';
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.peerDependencies));
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: [
nodeResolve({
extensions: ['.js', '.jsx', '.ts', '.tsx'],
preferBuiltins: true,
}),
commonjs({
extensions: ['.js', '.jsx'],
}),
typescript2({
check: !IS_DEV,
tsconfig: TSCONFIG,
useTsconfigDeclarationDir: true,
}),
],
watch: {
exclude: 'node_modules/**',
},
},
];