This repository has been archived by the owner on Jan 29, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.api.config.js
84 lines (76 loc) · 2.1 KB
/
rollup.api.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
const path = require('path')
const jsonPlugin = require('@rollup/plugin-json')
const nodeResolvePlugin = require('@rollup/plugin-node-resolve').nodeResolve
const typescriptPlugin = require('@rollup/plugin-typescript')
const terserPlugin = require('rollup-plugin-terser').terser
const dtsPlugin = require('rollup-plugin-dts').default
const licensePlugin = require('rollup-plugin-license')
const { version, config } = require('./package.json')
import commonjs from '@rollup/plugin-commonjs'
import replace from '@rollup/plugin-replace';
const outputDirectory = `dist/v${version}`
const commonBanner = licensePlugin({
banner: {
content: {
file: path.join(__dirname, 'LICENSE.md'),
},
},
})
const buildDate = JSON.stringify(new Date().toUTCString())
const buildVersion = JSON.stringify(version)
const isProd = process.env.npm_lifecycle_event === 'build'
const workerURL = JSON.stringify(isProd ? config.workerProdURL : config.workerDevURL)
const commonInput = {
input: './src/observer.collector/__package__/index.ts',
plugins: [
nodeResolvePlugin({
browser: true,
}),
jsonPlugin(),
typescriptPlugin({
declaration: false,
}),
commonjs(),
commonBanner,
replace({
__buildDate__: buildDate,
__buildVersion__: buildVersion,
__workerUrl__: workerURL,
__isDebug__: JSON.stringify(isProd === false)
})
],
}
const commonOutput = {
name: 'ObserverRTC',
exports: 'named',
}
const commonTerser = terserPlugin(require('./terser.config.js'))
const buildDev = {
...commonOutput,
file: `${outputDirectory}/observer.js`,
format: 'umd',
}
const buildProduction = {
...commonOutput,
file: `${outputDirectory}/observer.min.js`,
format: 'umd',
plugins: [commonTerser],
}
module.exports = [
// Browser bundles. They have all the dependencies included for convenience.
{
...commonInput,
output: [
isProd ? buildProduction : buildDev
],
},
// TypeScript definition
{
...commonInput,
plugins: [dtsPlugin(), commonBanner],
output: {
file: `${outputDirectory}/observer.d.ts`,
format: 'es',
},
},
]