4 ms·
I struggled quite some time with Closure Compiler, and in particular with CG's broken/inofficial support for CommonJS modules. I succeeded by pasting all module
by tannhaeuser 10y ago
I struggled quite some time with Closure Compiler, and in particular with CG's broken/inofficial support for CommonJS modules. I succeeded by pasting all module code into one file, removing `require()` calls and presenting only the single concatenated file to CG (and the minification and linting results were very good).
Granted, this is only possible if you reference modules/classes uniformly by the same name across your source, rather than using CommonJS "import as", and it only applies if you have no or few external dependencies which isn't realistic in the general case. Supposedly, using ES6 modules fixes this but I haven't checked yet.
- thelgevold 10y agoThere is a flag to tell it to process commonJS. I played with that here: http://www.syntaxsuccess.com/viewarticle/combining-es2015-modules-and-commonjs-modules-using-the-closure-compiler http://www.syntaxsuccess.com/viewarticle/combining-es2015-mo... Combining es6 and commonJS in the same project.
- lobster_johnson 10y agoYou should use Browserify or Webpack to bundle code together like that. They will handle the import chains for you and give you a single file that can be passed to Closure without any issues. Browserify is particularly easy to get going with; Webpack requires a bit more config. Edit: See this comment: https://news.ycombinator.com/item?id=13910621 https://news.ycombinator.com/item?id=13910621.