4 ms·
Running non-converted files through babel is not an issue, they will just come out looking the exact same. That said we have a high number of JS files (that I a
by joshstrange 12y ago
Running non-converted files through babel is not an issue, they will just come out looking the exact same. That said we have a high number of JS files (that I am slowly pruning down) so it was a worry (time-wise it takes ~30 sec to transpile all our JS) to run them all through babel. I considered trying to add a:
"use babel";
at the top of files that should be transpiled but I couldn't find a good "gulp way" to check for that. I also considered using a "filename.es6.js" structure but following file renames in SVN is a bitch and a half (not my only reason) so I didn't want to have to change those all back when es6 was widespread enough to use directly. I settled on running them all though so our "gulp build" takes 30 seconds or so but for our "gulp watch" (which starts off by building everything) I implemented caching so that only changed files had to be re-transpiled before getting concated into our "app.js" file. With this change it takes <1sec to transpile changed JS. Since our JS dev's use "gulp watch" everything works out quite nice so that they can edit a file and reload their browser to see the change immediately (30 sec times would have killed babel in it's crib for us and I assume most other places).
For caching we used the gulp-cached [0] plugin. It's important to note that if you plan on concat-ing your files that you are caching then you will also need to use gulp-remember [1] which re-introduces cached files into your file stream after the intensive parts of are done so for example:
var customJSStream = gulp.src('webroot/source/js/**/*.js'))
.pipe(cache('app-custom-js'))
.pipe(babel())
.pipe(remember('app-custom-js'))
...
(NOTE: I've left out stuff from our gulpfile and simplified it for display here)
We then combine that stream with 2 others and concat them all together but that's not important for this example. Let me know if you have any other questions!
[0] https://www.npmjs.com/package/gulp-cached https://www.npmjs.com/package/gulp-cached
[1] https://www.npmjs.com/package/gulp-remember https://www.npmjs.com/package/gulp-remember
- tracker1 12y agoIf you break up your application into separate npm modules, each module's transpile time can be reduced quite a bit to where you're unlikely to even notice.
- joshstrange 12y agoI have no doubt of that, this is for all front-end code ATM (we don't used node except for gulp). It was hard enough to move us to what we are doing now it will be some time before we get nice npm modules :(. I am looking into the options for front-end modules (CommonJS and friends) because I would like to break our stuff up a little better. It's leaps and bounds over what we started with (separation of interests-wise) but I have to be careful not to push the envelope too far and have the other devs throw up their hands and give up. Gulp was a HUGE step and it hasn't even been a full year on that yet. Bower was pretty hard as well but the team seems to have gotten over that now.
- tracker1 12y agoIt's probably easiest to start with any 3rd party modules already in npm.. jquery & plugins etc... from there it gets easier... assuming you're requiring in your classes and exporting already.
- drinchev 12y agoI would suggest adding FrontMatter [1], which will try to read a so-called YAML-header from the file, which is ignored later by gulp. You can combine it with gulp-if, to isolate those files that need compilation. 1: https://www.npmjs.com/package/gulp-front-matter https://www.npmjs.com/package/gulp-front-matter
- joshstrange 12y agoOooo, I haven't seem that, that's pretty neat. If our current method doesn't end up working out (been doing well for over a month now) and/or I get the time to address the initial 30 sec build then I will look into this. My only concern is our sourcemaps which have been.... finicky... at best. They work fine now that I've got them working but I had a hard time getting them to correctly spit everything out. Adding YAML to the files the yanking it out may have adverse effects on our sourcemaps but the only way to know is to try it out! Thanks for the suggestion, I've got it bookmarked now!
- ksherlock 12y agoI'm always amazed at what people go through to use gulp/grunt/etc instead of make.
- joshstrange 12y agosigh I'm really not sure how to reply to you, I want to say don't feed the trolls but.... make does not suit our needs and so we don't use it. Period. Also good luck getting source maps + babel + bower + etc to work under make, I honestly don't believe it's possible or if it is it would be so convoluted that it would be impossible to extend or understand. Gulp may not be a perfect tool (I don't believe such a tool exists) but it's leaps and bounds above make and a better choice than grunt IMHO.
- drinchev 12y agoMakefiles are great. But if you follow the principle "using the right tool for the right job", you'll most certainly in the end choose the building system of your infrastructure. It would be the same if you suggest Java codebase to switch from maven to make. Yes ... it would be far difficult to do that.