-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.fssrc.ts
92 lines (84 loc) · 1.96 KB
/
.fssrc.ts
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
// .fssrc.ts
// by @allex_wang
import MagicString from 'magic-string'
import progressPlugin from 'rollup-plugin-progress'
import { BundlerOptions, Plugin } from './src/types'
import { name, version, license, author, description } from './package.json'
const banner = (short = false) => {
let s
if (short) {
s = `/*! ${name} v${version} | ${license} licensed | ${(author as any).name || author} */`
} else {
s = `/**
* ${name} v${version} - ${description}
*
* @author ${author}
* Released under the ${license} license.
*/`
}
return s
}
const progress = () => {
if (process.env.TRAVIS || process.env.NETLIFY) {
return {}
}
return progressPlugin()
}
function addShebang(): Plugin {
return {
name: 'add-shebang',
renderChunk(code, chunkInfo) {
if (chunkInfo.fileName === 'bin/cli.js') {
const magicString = new MagicString(code);
magicString.prepend('#!/usr/bin/env node\n\n');
return { code: magicString.toString(), map: magicString.generateMap({ hires: true }) }
}
return null
}
}
}
const spec: BundlerOptions = {
destDir: './',
dependencies: [
'fs',
'path',
'os',
'events',
'util',
'assert',
'process',
'url',
'child_process'
],
entry: [
{
input: {
'bin/cli': 'src/bin/cli.ts'
},
treeshake: {
moduleSideEffects: false
},
plugins: [
'resolve',
'typescript',
'commonjs',
['replace', null], // with `null` to disable the builtin `replace` plugin
progress(),
process.env.NODE_ENV !== 'development' ? ['minimize', { output: { beautify: false } }] : null,
addShebang(),
],
output: [
{
chunkFileNames: 'lib/[name].js',
dir: './',
format: 'cjs',
get banner() {
return banner()
},
manualChunks: { 'bundler': ['src/index.ts'] },
}
]
}
]
}
export default spec