forked from buzz/mediainfo.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.js
53 lines (44 loc) · 1.54 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 fs from 'fs'
import { join } from 'path'
import url from 'url'
import babel from '@rollup/plugin-babel'
import resolve from '@rollup/plugin-node-resolve'
import terser from '@rollup/plugin-terser'
import virtual from '@rollup/plugin-virtual'
const dirname = url.fileURLToPath(new URL('.', import.meta.url))
// Global variable name for UMD build
const umdName = 'MediaInfo'
const srcDir = join(dirname, 'src')
const distDir = join(dirname, 'dist')
const esmBundleDir = join(distDir, 'esm-bundle')
const umdBundleDir = join(distDir, 'umd')
const mediaInfoModuleContent = fs
.readFileSync(join(dirname, 'build', 'MediaInfoModule.browser.js'))
.toString()
const makeOutput = (format, minify = false) => ({
file: join(format === 'esm' ? esmBundleDir : umdBundleDir, `index${minify ? '.min' : ''}.js`),
format,
name: format === 'umd' ? umdName : undefined,
plugins: minify ? [terser()] : undefined,
sourcemap: 'inline',
})
export default {
input: join(srcDir, 'index.ts'),
output: ['esm', 'umd'].reduce(
(acc, format) => [...acc, makeOutput(format), makeOutput(format, true)],
[]
),
plugins: [
resolve({ extensions: ['.ts'] }),
// The module loader generated by emscripten is different for each environment.
// For the bundler we just inject the correct content.
virtual({ 'src/MediaInfoModule': mediaInfoModuleContent }),
babel({
babelHelpers: 'bundled',
envName: 'ESM_ROLLUP',
exclude: ['./node_modules/**', './src/cli.ts'],
extensions: ['.ts'],
include: ['./src/**'],
}),
],
}