我看到可以使用onBuildWrite获取js文件的内容,但是我需要一种将值注入到我们的html根页面中的方法,这可能吗? EG,我们希望将我们的less文件换成CSS版本。

最佳答案

使用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');


只需将其与调用r.js一起添加到构建脚本中即可。

关于node.js - 使用requirejs优化器时是否可以在html文件中配置内容?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/10000333/

10-09 22:26