我正在寻找一种方式,以增加一些信息,以最小化文件。
我已经找到了选项这里,但是它对我没有什么用处,因为uglifier是在添加了包装代码之后运行的。
发布于 2014-06-29 20:27:42
您可以通过钥匙对文件进行后处理。通过设置此选项,结果将不会自动写入文件,因此您必须自己编写。例如:
({
// Let's optimize mainApp.js
name: "mainApp",
optimize: "uglify",
out: function(text) {
// Transform the compiled result.
text = '// Stuff to prepend \n' + text;
var filename = 'outputfile.js';
// By default, the name is resolved to the current working directory.
// Let's resolve it to the directory that contains this .build.js:
filename = path.resolve(this.buildFile, '..', filename);
// Finally, write the transformed result to the file.
file.saveUtf8File(filename, text);
}
})注意:在前面的片段中,是内部RequireJS API。和path是从Node.js标准库导入的模块 (仅当您使用Node.js运行r.js,而不是使用Rhino或浏览器运行r.js时)。
如果将前面的文件保存为test.build.js,创建一个名为mainApp.js的空文件并运行`r.js -o test.build.js,那么将创建一个名为"outputfile.js“的文件,其内容如下:
// Stuff to prepend
define("mainApp",function(){});https://stackoverflow.com/questions/24479368
复制相似问题