-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathrollup.config.mjs
79 lines (69 loc) · 2.25 KB
/
rollup.config.mjs
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
import { nodeResolve } from '@rollup/plugin-node-resolve';
import terser from '@rollup/plugin-terser';
import ignore from 'rollup-plugin-ignore';
import replace from '@rollup/plugin-replace';
import strip from '@rollup/plugin-strip';
const original = {
input: 'src/browser.mjs',
output: {
file: 'browser/country/iplookup.js',
format: 'iife',
name: 'IpLookup',
},
plugins: [
{
preventAssignment: true,
"__CDNURL__": false,
"__DATA_TYPE__": "'country'",
},
nodeResolve({
browser: true,
}),
ignore(["fs", "path"]),
strip({
functions: ['console.*'],
})
]
}
const settings = [original]
const DeepCopy = obj => {
if(Array.isArray(obj)) {
return obj.map(DeepCopy)
} else if(obj.constructor === Object) {
const newObj = {}
for(const key in obj) {
newObj[key] = DeepCopy(obj[key])
}
return newObj
}
return obj
}
settings[1] = DeepCopy(original)
settings[1].output.file = settings[1].output.file.replace('.js', '.min.js')
settings[1].plugins.push(terser())
settings[2] = DeepCopy(original)
settings[2].output.format = 'cjs'
settings[2].output.file = settings[2].output.file.replace('.js', '.cjs')
settings[2].plugins[0]["__CDNURL__"] = '"https://cdn.jsdelivr.net/npm/@iplookup/country/"'
settings[3] = DeepCopy(original)
settings[3].output.format = 'es'
settings[3].output.file = settings[3].output.file.replace('.js', '.mjs')
settings[3].plugins[0]["__CDNURL__"] = '"https://cdn.jsdelivr.net/npm/@iplookup/country/"'
settings.push(...settings.map(setting => {
const newSetting = DeepCopy(setting)
newSetting.output.file = newSetting.output.file.replace('country', 'geocode')
newSetting.plugins[0]["__DATA_TYPE__"] = "'geocode'"
return newSetting
}))
const extraSettings = settings.map(setting => {
const extraSetting = DeepCopy(setting)
extraSetting.input = extraSetting.input.replace('browser', 'browser-extra')
extraSetting.output.file = extraSetting.output.file.replace('country', 'country-extra').replace('geocode', 'geocode-extra')
return extraSetting
})
const exportSettings = settings.concat(extraSettings)
exportSettings.forEach(setting => {
// console.log(setting.plugins[0])
setting.plugins[0] = replace(setting.plugins[0])
})
export default exportSettings;