我正在尝试使用requirejs和闭包编译器作为优化器来创建一个grunt任务来构建一个javascript项目。我正在使用grunt-contrib-requirejs插件。
https://www.npmjs.org/package/grunt-contrib-requirejs
虽然我没有明确设置闭包编译器,但这里是配置和错误:
配置:
requirejs:
compile:
options:
sourceMap: true
baseUrl: "client"
mainConfigFile: "main.js"
name: "main.js"
out: "build/main.js"
optimize: "closure"
#generateSourceMaps: true
closure:
CompilerOptions: {},
CompilationLevel: 'SIMPLE_OPTIMIZATIONS'
loggingLevel: 'WARNING'
错误:
C:\Users\Project>grunt requirejs
Running "requirejs:compile" (requirejs) task
{ [Error: Error: optimizer with name of "closure" not found for this environment
at Object.optimize.js (C:\Users\Project\node_modules\requirejs\bin\r.js:24771:27)
]
originalError: [Error: optimizer with name of "closure" not found for this env
ironment] }
Closure是用java编写的,我的项目在nodejs中,我不知道如何设置它。
答案 0 :(得分:4)
The documentation states that Closure as an optimizer can only be used when running requirejs in Java。您在Node中运行requirejs是JavaScript,而不是Java。
您可以通过两个单独的步骤解决此问题:
You can use this Grunt package如果要在自己的计算机上运行Closure Java二进制文件。或者,您可以使用my Grunt Closure script that uses Closure REST API,它不需要在您的系统上安装Java或Closure二进制文件。