-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.js
53 lines (46 loc) · 1.82 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
import typescript from 'rollup-plugin-typescript2'
import nodeResolve from '@rollup/plugin-node-resolve'
import commonjs from '@rollup/plugin-commonjs'
import * as Rollup from 'rollup'
import fs from 'fs'
import uglify from 'uglify-es'
const alwaysThrowRequire = 'Symbol()'
if (!fs.existsSync('./dist')) fs.mkdirSync('./dist')
if (!fs.existsSync('./dist/typescript.js')) {
let typescriptSourceCode = fs.readFileSync(require.resolve('typescript'), 'utf-8')
typescriptSourceCode = typescriptSourceCode.replace(/require\(.+?\)/g, alwaysThrowRequire)
typescriptSourceCode = typescriptSourceCode.replace(/typeof module !== "undefined"/g, 'false')
typescriptSourceCode = typescriptSourceCode.replace(/typeof (process|ChakraHost|require)/g, '"undefined"')
const ts = uglify.minify(typescriptSourceCode, { compress: true })
console.log('Writing typescript')
if (ts.error) throw ts.error
fs.writeFileSync('./dist/typescript.js', ts.code)
}
const ignore = ['vm', '@microsoft/typescript-etw', 'fs', 'path', 'os', 'crypto', 'buffer', 'source-map-support']
// const isDev = process.argv.join(' ').indexOf('-w') !== -1
/** @type {Rollup.RollupOptions} */
const config = {
input: './src/index.ts',
output: {
file: './dist/out.js',
format: 'iife',
sourcemap: true,
},
// bundle a typescript is slow and hard to debug
external: ['typescript'],
plugins: [
nodeResolve({
browser: true,
preferBuiltins: false,
mainFields: ['module', 'main'],
}),
typescript({ tsconfigOverride: { compilerOptions: { module: 'ESNext' } } }),
commonjs({
extensions: ['.js', '.ts', '.tsx'],
exclude: ['node_modules/lodash-es/'],
ignore: ignore,
sourceMap: true,
}),
],
}
export default config