Javascript 使用闭包编译器编译两个js文件

Javascript 使用闭包编译器编译两个js文件,javascript,google-closure-compiler,Javascript,Google Closure Compiler,我有两个js文件: 1.js 2.js: 注意,2.js将访问1.js中定义的方法(setLength) 因此,我希望编译器使用相同的替换来编译这两个文件 我想要这样的结果: (function(){ function x(a,b){ a.length=b; } ........... })(); function View(){ x(this,3); } 这可能吗 顺便说一句,我使用compiler.js编译文件: java -jar compiler.jar --js f

我有两个js文件:

1.js

2.js:

注意,
2.js
将访问
1.js
中定义的方法(
setLength

因此,我希望编译器使用相同的替换来编译这两个文件

我想要这样的结果:

(function(){
  function x(a,b){
  a.length=b;
}
  ...........
})();

function View(){
  x(this,3);
}
这可能吗

顺便说一句,我使用compiler.js编译文件:

java -jar compiler.jar --js file.js --js_output_file file.min.js
这是一个文件,我想编译多个文件,每个文件都有自己的输出文件,如下所示:

java -jar compiler.jar --js file.js,file2.js --js_output_file file.min.js,file2.min.js

要使用相同的替换来编译这两个文件,闭包编译器的两个选项可能会有所帮助

--variable_map_input_file VAL : File containing the serialized version of the variable renaming map produced by a previous compilation --variable_map_output_file VAL : File where the serialized version of t he variable renaming map produced shou ld be saved --变量映射输入文件VAL:包含序列化版本的文件 生成的变量重命名映射的 根据以前的汇编 --variable_map_output_file VAL:t的序列化版本所在的文件 他用变量更名图制作了寿 我会得救的 所以你可以

  • 首先编译1.js并生成变量_map

    java -jar compiler.jar --js 1.js --js_output_file 1.min.js -variable_map_output_file variable_map.txt java -jar compiler.jar --js 2.js --js_output_file 2.min.js --variable_map_input_file variable_map.txt java-jar compiler.jar--js 1.js--js_output_file 1.min.js-variable_map_output_file variable_map.txt
  • 然后使用生成的变量_map编译2.js

    java -jar compiler.jar --js 1.js --js_output_file 1.min.js -variable_map_output_file variable_map.txt java -jar compiler.jar --js 2.js --js_output_file 2.min.js --variable_map_input_file variable_map.txt java-jar compiler.jar--js2.js--js_output_file 2.min.js--variable_map_input_file variable_map.txt
如果2.js将引用1.js中定义的函数,那么编译器将需要一个


使用输出包装器
(function(){%s})(
),无法从2.js访问1.js中定义的所有函数。您可能需要删除包装,或者使用

似乎使用
模块
可以满足我的要求。