-
Notifications
You must be signed in to change notification settings - Fork 7
/
rollup.config.js
63 lines (58 loc) · 1.69 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
import summary from 'rollup-plugin-summary'
export default {
output: {
format: 'umd',
},
plugins: [
umdEntry(),
typescript(),
summary(),
],
}
const path = require('path')
const umdEntryTemplate = entry =>
`import _default, * as named from './${path.parse(entry).name}'
Object.keys(named).forEach(function (name) { _default[name] = named[name] })
export default _default
`
function umdEntry() {
return {
resolveId(importee, importer) {
if (!importer) {
return path.resolve(__dirname, importee + '?')
}
},
load(id) {
if (id.endsWith('?')) {
return umdEntryTemplate(id.slice(0, -1))
}
},
}
}
function typescript() {
const ts = require('typescript')
const tsconfig = require('./tsconfig.json')
const compilerOptions = Object.assign({}, tsconfig && tsconfig.compilerOptions, { module: ts.ModuleKind.ES2015, noEmitHelpers: true, importHelpers: true })
const compilerHost = ts.createCompilerHost(compilerOptions)
const { minify } = require('terser')
return {
resolveId(importee, importer) {
if (importer) {
const resolved = ts.nodeModuleNameResolver(importee, importer.replace(/\\/g, '/'), compilerOptions, compilerHost)
return resolved.resolvedModule.resolvedFileName.replace(/\/tslib\.d\.ts$/, '/tslib.es6.js')
}
},
transform(code, id) {
if (id.endsWith('.ts')) {
const transformed = ts.transpileModule(code, { compilerOptions })
return {
code: transformed.outputText,
map: transformed.sourceMapText && JSON.parse(transformed.sourceMapText),
}
}
if (id.endsWith('/tslib.es6.js')) {
return minify(code)
}
},
}
}