-
Notifications
You must be signed in to change notification settings - Fork 6
/
rollup.config.js
43 lines (41 loc) · 1.27 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
import resolve from '@rollup/plugin-node-resolve'
import pug from 'rollup-plugin-pug'
export default {
output: {
format: 'umd',
},
plugins: [
resolve(),
pug({
basedir: 'src/demo/',
pugRuntime: false,
staticPattern: /\S/,
}),
typescript(),
],
}
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)
return {
resolveId(importee, importer) {
if (importer) {
const resolved = ts.nodeModuleNameResolver(importee, importer.replace(/\\/g, '/'), compilerOptions, compilerHost)
if (resolved.resolvedModule && !resolved.resolvedModule.resolvedFileName.endsWith('.d.ts')) {
return resolved.resolvedModule.resolvedFileName
}
}
},
transform(code, id) {
if (id.endsWith('.ts')) {
const transformed = ts.transpileModule(code, { compilerOptions })
return {
code: transformed.outputText,
map: transformed.sourceMapText && JSON.parse(transformed.sourceMapText),
}
}
},
}
}