question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

remap polyfills (via $jscomp) without including $jscomp definition in the output

See original GitHub issue

When splitting the app into “bundles”, sharing $jscomp definitions between all bundles could be beneficial, especially if the rollups are created by concatenating “bundles” on-demand.

With the new option --inject_library=es6_runtime we can easily externalize $jscomp definitions that can be used to patch the environment, but the missing part is how to compile modules with the proper mapping for polyfills without having to include $jscomp definitions in those other files?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:14 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
brad4dcommented, Sep 28, 2017

AFAICT, the purpose of this issue is to request the ability to do something like this.

  1. Run closure-compiler on a.js, b.js, and c.js to create abc_out.js
  2. Run closure-compiler on x.js, y.js, and z.js to create xyz_out.js
  3. Concatenate abc_out.js and xyz_out.js when shipping them to the browser and / or load them independently in the browser.

Presumably externs files are used to define the interface between code in the 2 output files. This bug exists because you would need to include the $jscomp polyfill code needed to support transpilation only once.

A core part of the closure-compiler design is that it should see all of the relevant code, except possibly some external library code that is not compiled. Separately compiling pieces then putting them together later isn’t something we actively try to support.

If the purpose of doing things this way is to reduce the amount of code that must be shipped to the browser, the --module flag should be used as @ChadKillingsworth suggested above. With this flag the compiler sees all the code as input, but splits the output into separately loadable files. Here’s his nice SO article about it.

https://stackoverflow.com/questions/10395810/how-do-i-split-my-javascript-into-modules-using-googles-closure-compiler/10401030#10401030

0reactions
stevendwoodcommented, Nov 16, 2017

@brad4d - given the answer from @shicks here https://github.com/google/closure-compiler/issues/1603 it seems like you kind of can do this ? I think first would need to get the polyfills in a separate output file by compiling an empty source with force inject es6 runtime.

Then you build abc_out.js and xyz_out.js using the option setPreventLibraryInjection(true). Or presumably you could write a small file that used all the transpilable features you wanted to support and compile that to get the polyfills. You then combine the polyfill and the two output files.

Read more comments on GitHub >

github_iconTop Results From Across the Web

command line compiler generates bigger file than the online ...
$jscomp.polyfill=function(a,c,b,d){if(c){b=$jscomp.global;a=a.split(". ... This tells the compiler not to polyfill Array.prototype.find and also disables ...
Read more >
third_party/ink/closure/base.js - chromium/src - Git at Google
you may not use this file except in compliance with the License. ... path (relative to base.js) should define a function $jscomp.transpile.
Read more >
$jscomp not defined in code loaded for clojurescript and reagent
1 Answer 1 ... $jscomp is related to the Closure Compiler and the Polyfills it creates. It might be enough to tweak the...
Read more >
Download Patch File - OpenDev
defineProperty=$jscomp. ... Object.prototype&&(b[k]=q.value)};$jscomp. ... whose with without", literal:"AppleScript false linefeed return pi quote result ...
Read more >
Changelog — thheller/shadow-cljs 2.15.5 - cljdoc
[ 8d0ad ] work arround not being able to ignore @define in npm files; [ bfdda ] fix error message for ... [...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found