is it possible to configure content in the html file when using requirejs optimizer?

Go To StackoverFlow.com

1

I see it is possible to get the contents of the js files using onBuildWrite but I am needing a way to inject values into our root html page, is this possible? EG we would like to swap out our less file for a css version.

2012-04-03 19:52
by skinnybrit51


1

It's possible with 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');

Just add that as a part of your build script, along with calling r.js.

2012-04-09 06:26
by Yauheni Leichanok