forked from rollup/rollup
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.js
136 lines (127 loc) · 2.86 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
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
import fs from 'fs';
import path from 'path';
import typescript from 'rollup-plugin-typescript';
import resolve from 'rollup-plugin-node-resolve';
import commonjs from 'rollup-plugin-commonjs';
import json from 'rollup-plugin-json';
import string from 'rollup-plugin-string';
import pkg from './package.json';
const commitHash = (function() {
try {
return fs.readFileSync('.commithash', 'utf-8');
} catch (err) {
return 'unknown';
}
})();
const banner = `/*
Rollup.js v${pkg.version}
${new Date()} - commit ${commitHash}
https://github.com/rollup/rollup
Released under the MIT License.
*/`;
const src = path.resolve('src');
const bin = path.resolve('bin');
function resolveTypescript() {
return {
name: 'resolve-typescript',
resolveId(importee, importer) {
// work around typescript's inability to resolve other extensions
if ( ~importee.indexOf( 'help.md' ) ) return path.resolve('bin/src/help.md');
if ( ~importee.indexOf( 'package.json' ) ) return path.resolve('package.json');
// bit of a hack — TypeScript only really works if it can resolve imports,
// but they misguidedly chose to reject imports with file extensions. This
// means we need to resolve them here
if (
importer &&
(importer.startsWith(src) || importer.startsWith(bin)) &&
importee[0] === '.' &&
path.extname(importee) === ''
) {
return path.resolve(path.dirname(importer), `${importee}.ts`);
}
}
};
}
export default [
/* rollup.js and rollup.es.js */
{
input: 'src/node-entry.ts',
plugins: [
json(),
resolveTypescript(),
typescript({
typescript: require('typescript')
}),
resolve(),
commonjs()
],
external: ['fs', 'path', 'events', 'module'],
banner,
sourcemap: true,
output: [
{ file: 'dist/rollup.js', format: 'cjs' },
{ file: 'dist/rollup.es.js', format: 'es' }
]
},
/* rollup.browser.js */
{
input: 'src/browser-entry.ts',
plugins: [
json(),
{
load: id => {
if ( ~id.indexOf( 'fs.ts' ) ) return fs.readFileSync( 'browser/fs.ts', 'utf-8' );
if ( ~id.indexOf( 'path.ts' ) ) return fs.readFileSync( 'browser/path.ts', 'utf-8' );
}
},
resolveTypescript(),
typescript({
typescript: require('typescript')
}),
resolve(),
commonjs()
],
banner,
sourcemap: true,
output: [
{
file: 'dist/rollup.browser.js',
format: 'umd',
name: 'rollup'
}
]
},
/* bin/rollup */
{
input: 'bin/src/index.ts',
plugins: [
string({ include: '**/*.md' }),
json(),
resolveTypescript(),
typescript({
typescript: require('typescript')
}),
commonjs({
include: 'node_modules/**'
}),
resolve(),
],
external: [
'fs',
'path',
'module',
'events',
'rollup',
'assert',
'os'
],
output: {
file: 'bin/rollup',
format: 'cjs',
banner: '#!/usr/bin/env node',
paths: {
rollup: '../dist/rollup.js'
}
}
}
];