当使用requirejs优化器时,有可能在html文件中configuration内容吗?

我发现可以使用onBuildWrite获取js文件的内容,但是我需要一种方法将值注入到根html页面,这可能吗? EG,我们想换一个css版本的less文件。

这是可能的node.js:

var fs = require('fs'); // read html file var fileContents = fs.readFileSync('index.html', 'utf8'); // replace rel attribute for less file with rel for css fileContents = fileContents.replace(/stylesheet\/less/gi, 'stylesheet'); // replace file name fileContents = fileContents.replace(/css\/application.less/gi, 'css/application.css'); // remove less runtime compiler (if needed) fileContents = fileContents.replace(/<script.*?\bless\b[^"']*?\.js.*?<\/script>/g, ''); // write file back fs.writeFileSync('index.html', fileContents, 'utf8'); 

只需将其添加为构build脚本的一部分,并调用r.js.