forked from annexare/Countries
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.js
56 lines (50 loc) · 1.42 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
const jsonPlugin = require('@rollup/plugin-json')
const { terser: terserPlugin } = require('rollup-plugin-terser')
const typescriptPlugin = require('rollup-plugin-typescript2')
const pkg = require('./package.json')
const banner = `/*! ${pkg.name} v${pkg.version} by Annexare | ${pkg.license} */`
const dataList = ['countries.2to3', 'countries.3to2', 'countries.emoji']
const getConfig = (inputFile, outFile, moduleName) => ({
input: `src/${inputFile}.ts`,
treeshake: true,
output: {
amd: {
id: moduleName,
},
banner,
file: `dist/${outFile}.min.js`,
format: 'umd',
name: moduleName,
},
plugins: [
jsonPlugin({
compact: true,
}),
typescriptPlugin(),
terserPlugin({
ecma: 5,
format: {
comments: function (node, comment) {
if (comment.type == 'comment2') {
// multiline comment
return /countries-list|@preserve|@license|@cc_on/i.test(comment.value)
}
},
},
ie8: true,
}),
],
})
const getModuleName = (fileName) => {
const result = fileName.toLowerCase().split(/[\s\.]+/)
for (let i = 0; i < result.length; i++) {
result[i] = result[i].charAt(0).toUpperCase() + result[i].slice(1)
}
return result.join('')
}
module.exports = [
getConfig('index', 'index.es5', 'Countries'),
...dataList.map((dataName) =>
getConfig(dataName + '.data', 'more/' + dataName, getModuleName(dataName))
),
]