-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathrollup.config.js
60 lines (55 loc) · 1.52 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
// @ts-check
import addGitMsg from 'rollup-plugin-add-git-msg'
import babel from '@rollup/plugin-babel'
import commonjs from '@rollup/plugin-commonjs'
import resolve from '@rollup/plugin-node-resolve'
import pkg from './package.json'
// List of njs built-in modules.
const njsExternals = ['crypto', 'fs', 'querystring']
const isEnvProd = process.env.NODE_ENV === 'production'
/**
* Plugin to fix syntax of the default export to be compatible with njs.
* (https://github.com/rollup/rollup/pull/4182#issuecomment-1002241017)
*
* @return {import('rollup').OutputPlugin}
*/
const fixExportDefault = () => ({
name: 'fix-export-default',
renderChunk: (code) => ({
code: code.replace(/\bexport { (\S+) as default };/, 'export default $1;'),
map: null,
}),
})
/**
* @type {import('rollup').RollupOptions}
*/
const options = {
input: 'src/index.ts',
external: njsExternals,
plugins: [
// Transpile TypeScript sources to JS.
babel({
babelHelpers: 'bundled',
envName: 'njs',
extensions: ['.ts', '.mjs', '.js'],
}),
// Resolve node modules.
resolve({
extensions: ['.mjs', '.js', '.json', '.ts'],
}),
// Convert CommonJS modules to ES6 modules.
commonjs(),
// Fix syntax of the default export.
fixExportDefault(),
// Plugins to use in production mode only.
...isEnvProd ? [
// Add git tag, commit SHA, build date and copyright at top of the file.
addGitMsg(),
] : [],
],
output: {
file: pkg.main,
format: 'es',
},
}
export default options