简体   繁体   English

使用闭包库构建库

[英]Build a library using Closure Library

I'm trying to "build" my project using Closure Library; 我正在尝试使用Closure库“构建”我的项目; Sadly, after many tests I can't build something without problems. 可悲的是,经过许多测试,我无法毫无问题地构建某些东西。 My project is a library, so I haven't got an entry point or anything like that, most of the code is made of objects and functions for the user. 我的项目是一个库,所以我没有入口点或类似的东西,大多数代码都是由用户的对象和函数组成的。

I've got a project like that: 我有一个像这样的项目:

 - build
      - build.sh
      - compiler.jar
 - libs
      - closure-library
 - src

My build.sh file: 我的build.sh文件:

java -jar compiler.jar --compilation_level SIMPLE_OPTIMIZATIONS --js_output_file out.js `find ../src/ -name '*.js'`

With this command line I've got the error: goog.require('goog.vec.Vec2'); 通过此命令行,我得到了错误: goog.require('goog.vec.Vec2'); ; ; So I think I need to include google closure library in this line, right? 所以我想我需要在这一行中包含Google闭包库,对吗?

So, I've tried to change my build.sh to something like that (added closure-library folder): 因此,我尝试将build.sh更改为类似的内容(添加了closure-library文件夹):

java -jar compiler.jar --compilation_level SIMPLE_OPTIMIZATIONS --js_output_file out.js `find ../src/ ../libs/closure-library/closure/ -name '*.js'`

With this script, I've got many error from the closure library like that: 有了这个脚本,我从闭包库中得到了很多错误,例如:

../libs/closure-library/closure/goog/i18n/datetimeformat_test.js:572: ERROR - This style of octal literal is not supported in strict mode.
  var date = new Date(Date.UTC(2015, 11 - 1, 01, 11, 0, 1));

And my resulting file (out.js) haven't got all my library's functions. 而且我生成的文件(out.js)还没有我所有库的功能。 I'm not sure to understand where is the problem. 我不确定问题出在哪里。

  • Did I really have to include google closure in the build part? 我真的必须在构建部分中包括google关闭吗?
  • I'm working on a Javascript library so I haven't got an entry point and all the code must be included in the resulting file. 我正在使用Javascript库,因此没有入口点,所有代码都必须包含在结果文件中。 So, how can I do that? 那么,我该怎么做呢?

Thanks for your time! 谢谢你的时间!

Edit: I've tried something different: removing all lines like "goog.require('goog.vec.Mat4');" 编辑:我尝试了不同的方法:删除所有行,如“ goog.require('goog.vec.Mat4');” from my library. 从我的图书馆。 The build is done successfully but my simulation didn't work anymore: Cannot read property 'Mat4' of undefined 构建成功完成,但是我的模拟不再起作用: Cannot read property 'Mat4' of undefined

The functionality you are looking for is documented on the GitHub wiki under Manage Closure Dependencies 您正在寻找的功能记录在GitHub Wiki上的Manage Closure Dependencies下

Determining Dependencies 确定依赖关系

1. Your Library Source Contains goog.provide Statements 1.您的库源文件包含goog.provide语句

In this case you would use --only_closure_dependencies combined with --closure_entry_point flags. 在这种情况下,您可以将--only_closure_dependencies--closure_entry_point标志结合使用。 Your "entry" points are any class in your library from which you want to calculate dependencies. 您的“入口”点是您要从中计算依赖关系的库中的任何类。 You can have multiple entry points. 您可以有多个入口点。

2. Your Library Source Does Not Contain goog.provide Statements 2.您的库源文件不包含goog.provide语句

Use the --manage_closure_dependencies flag. 使用--manage_closure_dependencies标志。 This instructs the compiler to include any JS file which does not contain a goog.provide statement in the output and to calculate all needed dependencies based on the goog.require statements in those files. 这指示编译器在输出中包括任何不包含goog.provide语句的JS文件,并根据这些文件中的goog.require语句计算所有需要的依赖关系。

Providing Files To The Compiler 提供文件给编译器

Closure-compiler's --js input flags can specify minimatch glob style patterns and this is the preferred method for providing Closure-library files as input. Closure编译器的--js输入标志可以指定minimatch glob样式模式,这是提供Closure-library文件作为输入的首选方法。 If you are using the --manage_closure_dependencies option, you must exclude the Closure-library test files. 如果使用--manage_closure_dependencies选项,则必须排除Closure-library测试文件。

Example: 例:

java -jar compiler.jar --compilation_level=SIMPLE_OPTIMIZATIONS
    --js_output_file=out.js
    --manage_closure_dependencies
    --js='../src/**.js'
    --js='../libs/closure-library/**.js'
    --js='!../libs/closure-library/**_test.js'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM