-
Notifications
You must be signed in to change notification settings - Fork 1
/
rollup.config.js
158 lines (148 loc) · 4.7 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
import { readFileSync, writeFileSync } from 'fs'
import babel from '@rollup/plugin-babel'
import nodeResolve from '@rollup/plugin-node-resolve'
import typescript from 'rollup-plugin-typescript2'
import { terser } from 'rollup-plugin-terser'
const bannerMsg = `/*! ****************************************************************************
Copyright (c) Microblink. All rights reserved.
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
MERCHANTABLITY OR NON-INFRINGEMENT.
***************************************************************************** */`
const terserConfig = {
compress: {
pure_getters: true,
unsafe: true,
unsafe_comps: true,
warnings: false
}
}
function replaceWorker(workerFile) {
return {
name: 'replace-placeholder',
writeBundle: (options, bundle) => {
const outputFilePath = options.file
const outputFileName = outputFilePath.split('/').pop()
const incompleteCode = bundle[outputFileName].code
const workerContent = readFileSync(workerFile, 'utf8')
const completeCode = incompleteCode.replace('@PLACEHOLDER:worker', workerContent)
writeFileSync(outputFilePath, completeCode)
}
}
}
const config = {
worker: {
input: 'src/worker.ts',
output: {
file: 'resources/BlinkInputSDK.worker.min.js',
format: 'iife'
},
plugins: [
nodeResolve(),
typescript({ tsconfigOverride: { compilerOptions: { declaration: false } } }),
babel({ babelHelpers: 'bundled' }),
terser(terserConfig)
]
},
cjs: {
input: 'src/index.ts',
output: {
file: 'lib/blinkinput-sdk.js',
format: 'cjs',
indent: false,
banner: bannerMsg
},
plugins: [
nodeResolve(),
typescript({ useTsconfigDeclarationDir: true }),
babel({ babelHelpers: 'bundled' }),
replaceWorker('resources/BlinkInputSDK.worker.min.js')
]
},
es: {
input: 'src/index.ts',
output: {
file: 'es/blinkinput-sdk.js',
format: 'es',
indent: false,
sourcemap: true,
banner: bannerMsg
},
plugins: [
nodeResolve(),
typescript({ tsconfigOverride: { compilerOptions: { declaration: false, sourceMap: true } } }),
babel({ babelHelpers: 'bundled' }),
replaceWorker('resources/BlinkInputSDK.worker.min.js')
]
},
esModule: {
input: 'src/index.ts',
output: {
file: 'es/blinkinput-sdk.mjs',
format: 'es',
indent: false,
banner: bannerMsg
},
plugins: [
nodeResolve(),
typescript({ tsconfigOverride: { compilerOptions: { declaration: false } } }),
babel({ babelHelpers: 'bundled' }),
terser(terserConfig),
replaceWorker('resources/BlinkInputSDK.worker.min.js')
]
},
umdDev: {
input: 'src/index.ts',
output: {
file: 'dist/blinkinput-sdk.js',
format: 'umd',
name: 'BlinkInputSDK',
indent: false,
sourcemap: true,
banner: bannerMsg
},
plugins: [
nodeResolve(),
typescript({ tsconfigOverride: { compilerOptions: { declaration: false, sourceMap: true } } }),
babel({ babelHelpers: 'bundled' }),
replaceWorker('resources/BlinkInputSDK.worker.min.js')
]
},
umdProd: {
input: 'src/index.ts',
output: {
file: 'dist/blinkinput-sdk.min.js',
format: 'umd',
name: 'BlinkInputSDK',
indent: false,
banner: bannerMsg
},
plugins: [
nodeResolve(),
typescript({ tsconfigOverride: { compilerOptions: { declaration: false } } }),
babel({ babelHelpers: 'bundled' }),
terser(terserConfig),
replaceWorker('resources/BlinkInputSDK.worker.min.js')
]
},
workerTest: {
input: 'src/MicroblinkSDK/worker/Worker.test.js',
treeshake: false,
output: {
file: 'resources/Worker.test.js',
format: 'iife',
indent: false,
banner: bannerMsg
}
}
}
export default [
config.worker,
config.cjs,
config.es,
config.esModule,
config.umdDev,
config.umdProd,
config.workerTest
]