-
Notifications
You must be signed in to change notification settings - Fork 19
/
rollup.config.js
75 lines (70 loc) · 1.99 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
69
70
71
72
73
74
75
'use strict';
const path = require('path');
const { nodeResolve } = require('@rollup/plugin-node-resolve');
const commonjs = require('@rollup/plugin-commonjs');
const typescript = require('rollup-plugin-typescript2');
const workerLoader = require('rollup-plugin-web-worker-loader');
const pkg = require('./package.json');
const { babel } = require('@rollup/plugin-babel');
const terser = require('@rollup/plugin-terser');
const { DEFAULT_EXTENSIONS } = require('@babel/core');
const { base64 } = require('@picovoice/web-utils/plugins');
const extensions = [...DEFAULT_EXTENSIONS, '.ts'];
console.log(process.env.TARGET);
console.log(extensions);
function capitalizeFirstLetter(string) {
return string.charAt(0).toUpperCase() + string.slice(1);
}
const iifeBundleName = pkg.name
.split('@picovoice/')[1]
.split('-')
.map(word => capitalizeFirstLetter(word))
.join('');
console.log(iifeBundleName);
export default {
input: [path.resolve(__dirname, pkg.entry)],
output: [
{
file: path.resolve(__dirname, pkg.module),
format: 'esm',
sourcemap: false,
},
{
file: path.resolve(__dirname, 'dist', 'esm', 'index.min.js'),
format: 'esm',
sourcemap: false,
plugins: [terser()],
},
{
file: path.resolve(__dirname, pkg.iife),
format: 'iife',
name: iifeBundleName,
sourcemap: false,
},
{
file: path.resolve(__dirname, 'dist', 'iife', 'index.min.js'),
format: 'iife',
name: iifeBundleName,
sourcemap: false,
plugins: [terser()],
},
],
plugins: [
nodeResolve({ extensions }),
commonjs(),
workerLoader({ targetPlatform: 'browser', sourcemap: false }),
typescript({
typescript: require('typescript'),
cacheRoot: path.resolve(__dirname, '.rts2_cache'),
clean: true,
}),
babel({
extensions: extensions,
babelHelpers: 'runtime',
exclude: '**/node_modules/**',
}),
base64({
include: ['lib/**/*.wasm', './src/**/*.js']
})
],
};