-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup2.js
52 lines (46 loc) · 1.58 KB
/
rollup2.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
var rollup = require( 'rollup' );
var nodeResolve = require('rollup-plugin-node-resolve');
var commonJS = require('rollup-plugin-commonjs');
var closure = require('google-closure-compiler-js');
var argv = require('yargs').argv;
require('core-js')
//simple closure compiler wrapper for rollup
function closureCompilerPlugin(options = {}){
return {
transformBundle(bundle){
const compilation = Object.assign({}, options, {
jsCode: options.jsCode ? options.jsCode.concat({ src: bundle }) : [{ src: bundle }]
});
console.log('closure compiler optimizing...');
const transformed = closure.compile(compilation);
console.log('closure compiler optimizing complete');
return { code: transformed.compiledCode, map: transformed.sourceMap };
}
}
}
var writeIIFE = fileName => bundle => bundle.write({format: 'iife', dest: fileName, moduleName: 'inbox'});
//rollup plugins
var plugins = [
nodeResolve({ module: true }),
commonJS({
namedExports: {
'node_modules/angularfire2/node_modules/firebase/database-node.js':
['initializeApp', 'auth', 'database'],
'node_modules/angularfire2/node_modules/firebase/firebase-browser.js':
['initializeApp', 'auth', 'database']
}
})
]
//only do closure in prod mode (slow!)
if(argv.prod){
plugins.push(closureCompilerPlugin({ compilationLevel: 'SIMPLE' }));
}
//build the AOT package
var buildAOT = rollup.rollup({
entry: './tmp/main.js',
plugins: plugins,
context: 'window'
})
.then(writeIIFE('./dist/build.js'))
.then(() => console.log('built angular2'))
.catch(err => console.log(err));