-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrollup.config.js
68 lines (61 loc) · 1.39 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
const fs = require('fs');
const path = require('path');
const { minify } = require('terser');
const { transpileModule } = require('typescript');
const tsconfig = require('./tsconfig.json');
const pkg = require('./package.json');
const resolve = {
name: 'resolve',
resolveId(file, importer) {
let tmp, { ext } = path.parse(file);
if (ext) return file;
let next = path.resolve(path.dirname(importer), file);
if (fs.existsSync(next)) return next;
if (fs.existsSync(tmp = next + '.ts')) return tmp;
if (fs.existsSync(tmp = next + '.js')) return tmp;
return null;
}
};
const terser = {
name: 'terser',
renderChunk(code, _chunk, opts) {
return minify(code, {
toplevel: true,
sourceMap: !!opts.sourcemap,
compress: true,
});
}
};
const typescript = {
name: 'typescript',
transform(code, file) {
if (!/\.ts$/.test(file)) return code;
// @ts-ignore
let output = transpileModule(code, { ...tsconfig, fileName: file });
return {
code: output.outputText.replace('$$VERSION$$', pkg.version),
map: output.sourceMapText || null
};
}
};
module.exports = {
input: 'src/bin.ts',
output: {
format: 'esm',
file: 'cfw.js',
banner: '#!/usr/bin/env node',
esModule: false,
interop: false,
strict: false,
freeze: false,
},
external: [
...require('module').builtinModules,
...Object.keys(pkg.dependencies),
],
plugins: [
resolve,
typescript,
terser,
]
}