This repository has been archived by the owner on Jun 27, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathrollup.factory.js
66 lines (64 loc) · 1.89 KB
/
rollup.factory.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
import typescript from 'typescript'
import resolve from '@rollup/plugin-node-resolve'
import json from '@rollup/plugin-json'
import commonjs from '@rollup/plugin-commonjs'
import replace from '@rollup/plugin-replace'
import sourceMaps from 'rollup-plugin-sourcemaps'
import ts from 'rollup-plugin-typescript2'
import polyfills from 'rollup-plugin-node-polyfills'
import progress from 'rollup-plugin-progress'
export default ({
dir,
pkg,
target,
}) => ({
input: pkg.source,
cache: true,
watch: {
include: 'src/**',
},
external: Object.keys(
Object.assign(
{},
pkg.dependencies,
pkg.peerDependencies,
pkg.optionalDependencies,
),
),
plugins: [
// Render build progress
progress(),
// Allow json resolution
json(),
// Allow node_modules resolution, so you can use 'external' to control
// which external modules to include in the bundle
// https://github.com/rollup/rollup-plugin-node-resolve#usage
resolve({
rootDir: dir,
preferBuiltins: true,
browser: target === 'web',
extensions: ['.mjs', '.ts', '.tsx', '.js', '.jsx', '.json', '.node'],
mainFields: ['module', 'jsnext', 'main', target === 'web' && 'browser'].filter(Boolean),
resolveOnly: target === 'node' ? ['tslib'] : [],
}),
// Allow bundling cjs modules (unlike webpack, rollup doesn't understand cjs)
commonjs({
extensions: ['.mjs', '.js'],
include: target === 'web' ? /\/node_modules\// : null,
}),
// Replace global variables
replace({
__VERSION__: JSON.stringify(pkg.version),
// 'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV),
}),
// Node polyfills
target === 'web' && polyfills(),
// Compile TypeScript files
ts({
typescript,
exclude: ['node_modules/**'],
}),
// Resolve source maps to the original source
sourceMaps(),
].filter(Boolean),
})