I'm trying to achieve following use case:
- my codebase is split to 3 JavaScript files: A, B and C
- files B and C both depends on file A (meaning they are e.g. calling methods declared in A)
- all files are using ES2015 (ES6) code
I'm using Google Closure Compiler to transpile them to ES5 and minify them. Which works fine with following configuration of NPM module google-closure-compiler
:
default: {
files: {
"A.min.js" : "A.js",
"B.min.js" : "B.js",
"C.min.js" : "C.js",
},
options: {
compilation_level: "SIMPLE",
language_in: "ES6_STRICT",
language_out: "ES5_STRICT"
}
}
But I'd like to optimize it. The configuration above causes that Closure Compiler 'injects' the same polyfill to all 3 files where needed (e.g. if A and C are using WeakMap, then both A.min and C.min contain polyfill for WeakMap).
My question is, is there a way to force the compiler to put common polyfills in only A? Something like if B or C are using WeakMap, then if A is using WeakMap, put polyfill to A. If A is not using WeakMap, put polyfills to B and C as usual?