是否有相当于Google的Closure Compiler for HTML最小化?
我正在使用Google Closure Compiler应用程序(命令行界面).当我运行它时,我得到以下错误.
deploy/js/Home.js:40: ERROR - Parse error. invalid property id
this.$images.wrapAll('<div id="slideInner"></div>').css({float:'left'});
^
1 error(s), 0 warning(s)
Run Code Online (Sandbox Code Playgroud) 我正在查看由闭包生成的一个缩小的js文件.我发现无论我在哪里检查变量和字符串之间的相等性,
a == "13" || a == "40"
Run Code Online (Sandbox Code Playgroud)
闭合取代它
"13" == a || "40" == a
Run Code Online (Sandbox Code Playgroud)
为什么要进行此修改?这里有一些性能优势吗?
我试图确定在javascript中生成类名的规则.我将此脚本粘贴到Chrome开发工具控制台:
var obj = {
Constr : function() { }
};
var obj2 = obj;
console.log(new obj.Constr());
console.log(new obj2.Constr());
obj2.Constr2 = function() { };
console.log(new obj.Constr2());
console.log(new obj2.Constr2());
Run Code Online (Sandbox Code Playgroud)
以下是控制台中的结果:
obj.Constr
obj.Constr
obj2.Constr2
obj2.Constr2
Run Code Online (Sandbox Code Playgroud)
似乎类的名称由构造函数最初分配给的变量确定.我正在寻找CDT用来生成此名称的精确规则.此外,这与Google Closure Compiler识别的名称相同吗?
我试图看看我是否可以在Firebug中重现类似的行为,但我似乎无法在控制台中打印出类名.作为第二个问题,有谁知道如何在萤火虫中看到这个?
从Closure Compiler API执行太多请求会出现此错误:
Error(22): Too many compiles performed recently. Try again later.
Run Code Online (Sandbox Code Playgroud)
什么是实际/电流限制?这是小时限制吗?滚动的窗户?
有关如何计算的任何文件?我可以在此页面上找到有关此内容的唯一信息(搜索"滥用行为"):https://developers.google.com/closure/compiler/docs/gettingstarted_ui?hl = zh-CN
我已经将closure-compiler gem添加到我的Gemfile并设置了
config.assets.js_compressor = :closure
Run Code Online (Sandbox Code Playgroud)
在config/environments/production.rb文件中.
我相信这默认使用SIMPLE_OPTIMIZATIONS编译级别,我想知道是否有一个配置变量我可以在某处设置以指定高级级别.
我尝试挖掘sprockets代码,但还没有找到将选项传递给js_compressor的方法.
手册说我可以使用:
--warnings_whitelist_file VAL : A file containing warnings to
suppress. Each line should be of the
form
<file-name>:<line-number>? <warning-d
escription>
Run Code Online (Sandbox Code Playgroud)
这就是我的白名单的样子:
ef-utils.js:1 Redeclared variable: ef
ef-utils.js:1 Variable ef first declared in externs-ko.js
ef-validation.js:1 Redeclared variable: ef
ef-validation.js:1 Variable ef first declared in externs-ko.js
Run Code Online (Sandbox Code Playgroud)
编译时我仍然收到警告:
ef-utils.js:1: WARNING - Redeclared variable: ef
?var ef = (function (ns, ko) {
^
ef-utils.js:1: WARNING - Variable ef first declared in externs-ko.js
?var ef = (function (ns, ko) {
^
ef-validation.js:1: WARNING - Redeclared variable: …Run Code Online (Sandbox Code Playgroud) 这个问题是关于正确使用Google Closure Compiler的类型注释.
我们有一个约定,每个javascript文件都包含在一个函数中.示例文件:
Square.js:
(function() {
'use strict';
/**
* @constructor
*/
function Square() {};
Square.prototype.draw = function() {
};
}());
Run Code Online (Sandbox Code Playgroud)
如果我们在这个函数中定义一个类型(比如构造函数),那么闭包编译器在其他文件中并不知道它.例如,在另一个文件中:
foo.js:
(function() {
'use strict';
/** @param {Square} square */
function drawSquare(square) {
square.draw();
}
}());
Run Code Online (Sandbox Code Playgroud)
编译它-W VERBOSE会给出一个错误,即Square未定义类型:
foo.js:4: WARNING - Bad type annotation. Unknown type Square
/** @type {Square} square */
^
0 error(s), 1 warning(s), 83.3% typed
Run Code Online (Sandbox Code Playgroud)
我们已经在单独的文件中为所有类创建了externs来解决这个问题.创建externs是一个糟糕的解决方案,因为现在我们必须为每个类维护两个文件.
当Browserify结合我的JavaScript文件时,结果如下所示:
(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
// Including file contents
},{"foo":3}],3:[function(require,module,exports){
// Included file contents
...
Run Code Online (Sandbox Code Playgroud)
带有类型检查的Google Closure Compile(--jscomp_warning = checkTypes)会抱怨s使用一个参数而不是所需的两个参数调用的函数.
我正在取代的定义 s
function s(o,u){
Run Code Online (Sandbox Code Playgroud)
同
/** @param {*=} o @param {*=} u */function s(o,u){
Run Code Online (Sandbox Code Playgroud)
作为预处理步骤.
但是,必须有一个更好的方式.我的问题是:如何将Browserify与Google Closure Compiler结合使用类型检查,而无需查找和替换定义s?
我正在尝试谷歌闭包编译器作为webpack的替代品.目前我正在使用以下编译我的前端文件夹中的所有文件:
java -jar closure-compiler.jar --process_common_js_modules --js_output_file=static/out.js 'lib/js/src/frontend/*.js'"
Run Code Online (Sandbox Code Playgroud)
问题是其中一个文件需要React和ReactDOM.我收到以下错误:
lib/js/src/frontend/app.js:7: ERROR - Failed to load module "react"
var React = require("react");
^^^^^^^^^^^^^^^^
lib/js/src/frontend/app.js:8: ERROR - Failed to load module "react-dom"
var ReactDom = require("react-dom");
^^^^^^^^^^^^^^^^^^^^
Run Code Online (Sandbox Code Playgroud)
如何确保Google Closure Compiler查看node_modules以查找相关的第三方模块?