-
Notifications
You must be signed in to change notification settings - Fork 106
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Is there any way to pre-process files and send the output as stdin for live to refresh? #50
Comments
Interesting. 😁 What about just using a app
.watch('*.less', { interval: 300, usePolling: true })
.live()
.on('watch', function(type, file) {
if (path.extname(file) === '.less') {
less('./main.less').then(function (css) {
fs.writeFile('main.css', css, function (err) {
if (err) {
// handle error nicely
} else {
app.reload('main.css');
}
});
});
}
}) |
@mattdesl that is a nice idea, however it can get a bit confusing? specially when you have a production build process based on real file names? I would be amazing if there could be a way to handle that as gracefully We've managed to get a similar result for on BrowserSync/browser-sync#411 |
hey @mattdesl, Basically I have managed to achieve what I wanted by adding a new event to the api called When adding adding a Have a look on how the /*jslint node:true*/
var less = require('less'),
fs = require('fs'),
url = require('url'),
path = require('path'),
budo = require('budo')('app.js', { live: true, stream: process.stdout });
budo.watch('**/*.less')
.on('watch', function (type, file) {
if (path.extname(file) === '.less') {
//trick to get live LESS injection
//even though `main.css` does not exists ;)
budo.reload(file.replace(/\.less$/, '.css'));
}
})
.on('request', function (req, res) {
// this method will only be called to new extensions
// declared on budo.watch method
var file = url.parse(req.url).pathname;
file = path.join(process.cwd(), file);
if (path.extname(file) === '.less') {
fs.readFile(file, function (err, o) {
less.render(o.toString(), function (err, o) {
//setting headers (optional)
res.setHeader('content-type', 'text/css');
res.setHeader('content-length', o.css.length);
res.end(o.css);
});
});
}
}); Now the trick to get live reload injection for LESS files was asking Budo to reload the same file, but with
Also, note that this new approach would allow users to have complete freedom on what they would like to do with the files. It can be pre-processed with SASS, Stylus, etc, in fact, the possibilities are huge since you could also create files in JADE, HAML or any other HTML pre-processor and it could also be rendered as html straight away. 👍 I am quite happy I was be able to achieve this with budo since and am amazed on how great module already is. Also, I am looking forward to hear your thoughts about it and perhaps we could think on a way to add that feature in All the best. |
Very cool @zanona. I have been wanting to make use of budo for some non-static sites as well, and maybe the I have a pretty busy week coming up, and on Wednesday I start vacation in Europe for a couple of weeks. After that, I will take a closer look at this and hopefully get it working for the 5.0 release. |
Great to hear you like the idea @mattdesl. |
hey @mattdesl, just to let you know I've been using https://github.com/zanona/budo-less which is based on the request functionality added through my fork of budo to achieve live less file reload. It's been working nicely so far. you can try it out via Let me know if you would like a PR. |
Just FYI I have not forgotten about this. 😄 I'm adding something that should allow this feature in budo@5. You will be able to pass a See here for example: A tool like budo that has LESS (or SASS) built-in could work very similarly to the way eg:
Now your index.html: <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<link rel="stylesheet" type="text/css" href="main.css">
<title>budo</title>
</head>
<body>
<script src="bundle.js"></script>
</body>
</html> And any requests to |
that sounds a good idea @mattdesl. |
One approach:
This will cause LiveReload to re-request A more sophisticated approach would be to use a LESS file watcher that is aware of the |
sounds great @mattdesl. It will definitely be nice to see this implemented. |
There is now an experimental / proof-of-concept CLI tool for quick prototyping with LESS and proper LiveReload. It is mostly just a thin wrapper around budo's API. For more complex pre-processors or features outside the scope of that CLI, I would still suggest using the budo API directly (example here). |
Cool. Thanks a lot for that @mattdesl. Is there any option if I want to keep the file name with |
You can specify the URL for the budo-less index.js --less main.less --css main.less Curious what you mean by "re-mapped" ? |
Thanks. That was exactly what I meant ;) |
Define this as |
@MadebyAe that didn't work for me on OSX. I had to use "&", instead of ";" for stylus to rebuild onchange.
"scripts": {
"dev": "budo --install --css ./app.css --title App index.js --live --verbose --open -t babelify & stylus -w -u nib stylus/index.styl -o ./app.css"
} |
I am trying to think on a way that would allow budo requests to
*.less,*.sass
files to activate the pre-processor, run the output throughauto-prefixer
and render the outcome as text, directly injected into a page without the need to generate a physical file, basically the same as it does by default with javascript files.Would that be somehow possible to achieve with budo?
The way it works is genius, but I only missing CSS pre-processors to really improve my workflow.
Ideally this would be achievable if the
reload
method accepted the file contents instead of its path only, like:main.less
main.less compiled into .css and made available for rendering in-browser
Thanks a lot
The text was updated successfully, but these errors were encountered: