Comments (11)
This makes a lot of sense. And thanks for var tasks = fs.readdirSync('./gulp/tasks/');
! I knew there was a way to do that, but I'm new to Node, and hadn't taken the time to figure that out. I'll play with this over the weekend.
from blendid.
Actually... I think I've been down this road already. I think that in order to add dependencies to a task, those tasks have to already exist. I'll double check, but I think this is true. If we're just looping through a bunch of files, there's no way to ensure that the tasks that open.js
depend on have already been created by the loop.
That's why in gulpfile.js
I'm creating my batch tasks (build
and default
) separately, once all the tasks they depend on have been created.
So the solution would be to change the task callback above into it's own dependency3
task, and move the 'open' task creation to gulpfile.js
// tasks/dependency3.js
var gulp = require('gulp');
var open = require("gulp-open");
gulp.task('dependency3', function() {
var options = {
url: "http://localhost:8080",
app: "google chrome"
};
return gulp.src("./index.html").pipe(open("", options));
};
// gulpfile.js
...
gulp.task('open', ['dependency1', 'dependency2', 'dependency3']);
Definitely adding fs.readdirSync
though!
from blendid.
Cool. I'm not sure if task definition order matters–definitely worth looking up. I'll post here if I figure anything out. Thanks for a great resource!
from blendid.
I'm just running dependencies using run-sequence
. It has the benefit of being able to run some tasks in series and others in parallel to find the fastest path.
module.exports = function (callback) {
runSequence('clean', 'static', 'html', ['javascripts', 'sass', 'templates', 'translations'], ['uglify', 'minify-css'], 'cachebust', 'manifest', function () {
gulp.src('src/foo/*.bar')
.pipe(whatever())
.on('end', callback);
});
};
from blendid.
@elcontraption - looks like you were totally right! Definition order doesn't seem to matter, so your proposed solution is pretty perfect. Gonna run it through the wringer, and if all goes well, I'll push these updates. Thanks for the insight.
from blendid.
I took a slightly different approach by modifying gulp/index.js
. Right now my quick-and-dirty variant looks like:
var gulp = require('gulp');
module.exports = function(tasks) {
tasks.forEach(function(task) {
task = (typeof task === 'string') ? { name: task } : task;
task.deps = task.deps || [];
gulp.task(task.name, task.deps, require('./tasks/' + task.name));
});
return gulp;
};
From gulpfile.js
, I can then:
var gulp = require('./gulp')([
'browserify',
'css',
'files',
'indexer',
'javascript',
{ name: 'screens', deps: ['build']},
'serve',
'templates',
'vendor',
'watch'
]);
Just another way to skin the cat. Seems to work in my case! The nice thing about this way is that I don't have to touch my existing task modules. But there may well be shortcomings I'm not thinking of.
from blendid.
@lyzadanger's method allows the task modules to be unaware of each other–which seems more modular–and all dependency configuration happens in one place. It's just a matter of where you prefer your dependencies to be declared.
from blendid.
@lyzadanger - that's a great solution too. I'm leaning towards @elcontraption's version only because I like the idea of automatically including tasks from ./gulp/tasks
. Saves from having to mange the task list manually, and reduces the gulpfile.js
to just one line . Take a look at #5 and let me know if you see any downsides. Once I get some input, I'll merge it and add a note to the blog post.
from blendid.
Ooh, I do like the fs-based auto-inclusion of tasks. Neato!
On Apr 15, 2014, at 4:57 PM, Dan Tello [email protected] wrote:
@lyzadanger - that's a great solution too. I'm leaning towards @elcontraption's version only because I like the idea of automatically including tasks from ./gulp/tasks. Saves from having to mange the task list manually, and reduces the gulpfile.js to just one line . Take a look at #5 and let me know if you see any downsides. Once I get some input, I'll merge it and add a note to the blog post.
—
Reply to this email directly or view it on GitHub.
from blendid.
#5 is looking good to me, and solves this issue. You might want to bounce it off someone more node and gulp savvy to be sure.
from blendid.
Updated and merged. Thanks for the input!
from blendid.
Related Issues (20)
- watch task will not compile more than 48 html files HOT 5
- Removing "comments" from public/html files HOT 1
- xlink:href being deprecated in SVG
- Additional Tasks information HOT 4
- Build issue: UglifyJs - Unexpected token: name (context)
- Build issue: UglifyJs - Unexpected token: name (context) HOT 5
- Fonts aren't copied over on build HOT 1
- additionalTasks access rev-manifest HOT 4
- Not bundle jquery in production HOT 1
- Current project status HOT 4
- 4.5.0 release not available through npm/yarn HOT 1
- Failed to mount component: template or render function not defined HOT 1
- upgrade to gulp 4
- empty prebuild and postbuild configs must be `null`/`false`, not `[]`. change this behavior?
- html watch task does not notice changes to files added after Blendid was started
- wrong generation of path for js-files in rev-manifest on windows HOT 1
- Configuration for swiper to work
- The engine "node" is incompatible with this module HOT 3
- 4.5.3 release not available through npm HOT 1
- ERROR in bundle.js from UglifyJs Unexpected token: name (ChangeDesc) [bundle.js:2900,6]
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from blendid.