google-closure-compiler

Exclude debug JavaScript code during minification

守給你的承諾、 提交于 2019-12-27 17:18:28
问题 I'm looking into different ways to minify my JavaScript code including the regular JSMin, Packer, and YUI solutions. I'm really interested in the new Google Closure Compiler, as it looks exceptionally powerful. I noticed that Dean Edwards packer has a feature to exclude lines of code that start with three semicolons. This is handy to exclude debug code. For instance: ;;; console.log("Starting process"); I'm spending some time cleaning up my codebase and would like to add hints like this to

How i can mark function as “private” to renaming it by Google Closure Compiler?

余生长醉 提交于 2019-12-25 04:51:41
问题 I have private function createSomething(): function Player(id) { /** * Creates stuff * @private */ this.createSomething = function() { // do something good }; } and I want to see the renamed function "createSomething()" after compiling the source with Google Closure Compiler. Yes, I know about ADVANCED_OPTIMIZATIONS but it is incompatible with jQuery and other libraries. 回答1: The solution is to use a string literal to refer to the property. function Player(id) { /** * @private */ this[

Google closure compiler doesn't remove unreachable code marked with @define annotation

久未见 提交于 2019-12-25 03:44:50
问题 Why this code doesn't result in an empty string after compilation with SIMPLE_OPTIMIZATIONS /** * @define {boolean} */ var TEST = false; (function() { if (TEST) { foo(); } })(); and instead I get the following? var TEST=!1;(function(){TEST&&foo()})(); The if is unreachable but the closure compiler doesn't remove the code. With "advanced optimizations" the result is what I expect (empty) but "simple optimizations" give the above result. Why this difference? The code will never be executed in

How to have a type in Closure Compiler externs without a constructor

雨燕双飞 提交于 2019-12-24 15:58:34
问题 I am trying to make externs for the Google Closure Compiler for types that have no constructor. I have tried the following, but it gives me a Bad type annotation. Unknown type WindowsMediaActiveX.Cdrom error because nothing tells the compiler that WindowsMediaActiveX.Cdrom is a type instead of just a collection of methods/properties. /** * @fileoverview Declares externs for the Windows media player ActiveX control. * @author Joshua Dwire * @suppress {duplicate} */ var WindowsMediaActiveX={};

Using Three.js as Closure library?

核能气质少年 提交于 2019-12-24 11:22:31
问题 Looking at Three.js's build script, I see they use Google Closure compiler. I am having a small script utilizing Three.js. Can I use Google Closure to compile the script with Three.js as a library (instead of having Three.min.js preambled or included in an HTML tag) so the final output javascript is much smaller. I'm asking this because I don't see any goog.provide in Three.js source. 回答1: It looks like the build command does not specify a compilation level. That means it is using the default

Dojo build requesting already inlined Dijit templates

放肆的年华 提交于 2019-12-24 10:48:28
问题 I am a developer on a large Dojo project and I am having some issues with the Google Closure compiler. We have around a hundred templates for Dijit widgets so the plan was to make the Closure compiler inline the HTML in the JavaScript file rather than require them AMD style. To achieve this I changed the "mini" parameter in /profiles/app.profile.js from true to false. When compiling, everything seems to work fine, even when running the app i have no issues but something strange happens. Even

Google Closure Compiler advanced: remove code blocks at compile time

╄→гoц情女王★ 提交于 2019-12-24 08:28:50
问题 If I take this code and compile it (advanced optimizations) /**@constructor*/ function MyObject() { this.test = 4 this.toString = function () {return 'test object'} } window['MyObject'] = MyObject I get this code window.MyObject=function(){this.test=4;this.toString=function(){return"test object"}}; Is there any way I can remove the toString function using the Closure Compiler? 回答1: toString is implicitly callable, so unless the Closure compiler can prove that the result of MyObject is never

What does @code mean in Google Closure?

女生的网名这么多〃 提交于 2019-12-24 01:44:23
问题 An example is here: * An implementation of {@code goog.events.Listenable} with full W3C * EventTarget-like support (capture/bubble mechanism, https://developer.pubref.org/static/apidoc/global/closure/goog/events/EventTarget.html I can guess what it means but where can I find its exact definition? I checked all the Google Closure Annotation docs but couldn't find. Thanks :) 回答1: Updated Per my new understanding; Since JSDocs supports markdown. {@code FooBar} is therefore deprecated in favor of

How to use google-closure-compiler-js for a node.js app without gulp/grunt/webpack?

柔情痞子 提交于 2019-12-24 01:29:34
问题 The docs don't have any examples of using this on its own but they do say this: Unless you're using the Gulp or Webpack plugins, you'll need to specify code via flags. Both jsCode and externs accept an array containing objects in the form {src, path, sourceMap}. Using path, you can construct a virtual filesystem for use with ES6 or CommonJS imports—although for CommonJS, be sure to set processCommonJsModules: true. I've created a "compile.js" file based on the docs: const compile = require(

How to tell Closure Compiler to preserve properties on an object

时光总嘲笑我的痴心妄想 提交于 2019-12-24 00:38:41
问题 I have an object declared like this: my.namespace.FEATURES = { FIRST_FEATURE = "first feature", SECOND_FEATURE = "second feature" }; I use my.namespace.my.object to keep track of what kinds of features are available/implemented in my code. Every newly released version will have a modified set of features. A third-party using my minimized code will want to know what they can do in the version they have, so I supply the following function, which is exported, so that they know what they can do.