-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathrollup.config.ts
90 lines (80 loc) · 1.94 KB
/
rollup.config.ts
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
85
86
87
88
89
90
import { type RollupOptions } from "rollup"
import dts from "rollup-plugin-dts"
//import { nodeResolve } from "@rollup/plugin-node-resolve"
import commonjs from "@rollup/plugin-commonjs"
import typescript from "rollup-plugin-ts"
import fs from "fs"
import path from "path"
import pkg from "./package.json"
const plugins =
[ commonjs()
, typescript({tsconfig:
{ allowJs: false
, noImplicitAny: true
, moduleResolution: "Node"
, resolveJsonModule: true
, allowSyntheticDefaultImports: true
, declaration: true
, declarationDir: "./dist/dts"
, emitDeclarationOnly: true
}
})
]
const umd = (input : string, file : string, name : string) : RollupOptions => {
return {
input,
output: {
file,
format: 'umd',
name
},
plugins
}
}
const cjs = (input : string, file : string) : RollupOptions => {
return {
input,
output: {
file,
format: 'cjs',
},
plugins
}
}
const iife = (input : string, file : string) : RollupOptions => {
return {
input,
output: {
file,
format: 'iife',
},
plugins
}
}
const esm = (input : string, file : string) : RollupOptions => {
return {
input,
output: {
file,
format: 'esm',
},
plugins
}
}
const targets =
[ iife("src/iife.ts", "dist/flowplayer.lang.all.js") // for cdn iife
, cjs("src/index.ts", pkg.main)
, esm("src/index.ts", pkg.module)
]
const langDir = "src/languages"
const languages = fs.readdirSync(langDir)
languages.forEach(lang => {
const input = path.join(langDir, lang)
const langCode = lang.split(".")[0]!
const esmOutput = path.join("dist", "esm", `flowplayer.lang.${langCode}.js`)
const umdOutput = path.join("dist", `flowplayer.lang.${langCode}.js`)
const umdConst = `flowplayer.i18n.${langCode}`
targets.push(umd(input, umdOutput, umdConst))
targets.push(esm(input, esmOutput))
})
export default targets as RollupOptions[]