-
Notifications
You must be signed in to change notification settings - Fork 2
/
gcompiler.js
28 lines (24 loc) · 926 Bytes
/
gcompiler.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
const ClosureCompiler = require('google-closure-compiler').compiler;
const fs = require('fs');
console.log(ClosureCompiler.COMPILER_PATH); // absolute path to the compiler jar
console.log(ClosureCompiler.CONTRIB_PATH); // absolute path to the contrib folder which contain externs
const compileLevels = {
WHITESPACE_ONLY: 'WHITESPACE_ONLY',
SIMPLE_OPTIMIZATIONS: 'SIMPLE_OPTIMIZATIONS',
ADVANCED_OPTIMIZATIONS: 'ADVANCED_OPTIMIZATIONS'
}
const closureCompiler = new ClosureCompiler({
js: ['dist/index.js', 'dist/helpers.js', 'dist/main.js', 'dist/validation.js'],
module_resolution: 'node',
process_common_js_modules: true,
compilation_level: compileLevels.ADVANCED_OPTIMIZATIONS
});
const compilerProcess = closureCompiler.run((exitCode, stdOut, stdErr) => {
console.error(stdErr);
fs.writeFile('dist/out.js', stdOut, error => {
if (error) {
console.error(error);
return;
}
});
});