-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrollup.js
145 lines (140 loc) · 2.95 KB
/
rollup.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
const rollup = require('rollup')
const resolve = require('rollup-plugin-node-resolve')
const commonjs = require('rollup-plugin-commonjs')
const typescript = require('rollup-plugin-typescript2')
const multiEntry = require('rollup-plugin-multi-entry')
const postcss = require('rollup-plugin-transform-postcss')
const replace = require('rollup-plugin-replace')
const uglify = require('rollup-plugin-uglify')
const progress = require('rollup-plugin-progress')
const json = require('rollup-plugin-json')
const cssimport = require('postcss-import')
const cssnext = require('postcss-cssnext')
const cssnested = require('postcss-nested')
const mixins = require('postcss-mixins')
const entries = require('./entries.json')
const pkg = require('./package.json')
const { BUILD_MODE, TRAVIS_BRANCH } = process.env
const [, , name] = process.argv
const postcssOptions = {
exclude: ['node_modules/**'],
plugins: [
cssimport,
cssnested,
mixins,
cssnext({
features: {
rem: { replace: true }
}
})
]
}
const resolveOptions = {
browser: true,
jsnext: true,
preferBuiltins: false
}
const commonjsOptions = {
include: 'node_modules/**',
namedExports: {
'node_modules/firebase/index.js': [
'app',
'apps',
'auth',
'database',
'initializeApp',
'messaging',
'storage'
]
}
}
const typescriptOptions = {
tsconfigOverride: {
include: ['src/**/*.ts']
}
}
const replaceOptions = {
'process.env': JSON.stringify({
BUILD_MODE,
TRAVIS_BRANCH,
PACKAGE_VERSION: pkg.version
})
}
const uglifyOptions = {
output: {
comments: (node, comment) => {
const text = comment.value
const type = comment.type
if (type == 'comment2') {
return /@preserve|@license|@cc_on|copyright/i.test(text)
}
}
}
}
const plugins = [
postcss(postcssOptions),
resolve(resolveOptions),
commonjs(commonjsOptions),
typescript(typescriptOptions),
replace(replaceOptions),
json()
]
const build = async (rollupOptions, writeOptions) => {
const bundle = await rollup.rollup({
...rollupOptions,
...{
onwarn: e => {
if (
e.message ===
`The 'this' keyword is equivalent to 'undefined' at the top level of an ES module, and has been rewritten`
) {
return
}
console.error(e)
}
}
})
await bundle.write(writeOptions)
}
if (BUILD_MODE === 'TEST') {
return build(
{
input: 'src/**/*.test.ts',
plugins: [multiEntry()].concat(plugins)
},
{
format: 'umd',
name: 'test',
file: 'dist/test.js'
}
)
}
const filteredEntries = name
? entries.filter(entry => entry.name === name)
: entries
if (!TRAVIS_BRANCH) {
// In this case it is local
plugins.push(progress())
} else {
plugins.push(uglify(uglifyOptions))
}
;(async () => {
for (const entry of filteredEntries) {
await Promise.all(
entry.build.map(bld => {
console.log(`Building ${bld.file}`)
return build(
{
input: bld.file,
plugins
},
{
name: entry.name,
format: bld.format,
file: bld.dest
}
)
})
)
}
})()