Skip to content
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

task.source doesn't take effect after a yeild task #289

Open
stkevintan opened this issue Jul 24, 2017 · 1 comment
Open

task.source doesn't take effect after a yeild task #289

stkevintan opened this issue Jul 24, 2017 · 1 comment

Comments

@stkevintan
Copy link

I write a simple build task and a custom plugin usemin as following.
I thought the files argument of the generator function in the usemin plugin should be .tmp/index.html but, I found that I'm wrong, it contains all the files which returned by the html task.

so why things become so weird? (maybe I should post this question on stackoverflow. sorry ....

export async function compile(task) {
  await task.start('clear');
  await task.parallel(['script', 'style', 'image', 'font', 'other', 'html']);
}
export async function build(task) {
  await task.start('compile');
  await task.source('.tmp/index.html').usemin({
    staticDir: c.build,
  }).target(c.build);
}
module.exports = function (task, utils) {
 // ...
  task.plugin('usemin', { every: false }, function* (files, opts) {
    console.log(files.map(o=>o.dir).filter(o=>o.indexOf('.tmp')!==-1)); 
    // [] (empty array)
  });
}
@lukeed
Copy link
Owner

lukeed commented Jul 24, 2017

Hi! Unfortunately, this is the only quirky behavior that Taskr has. I haven't been able to spend time sorting it out yet.

Taskr's sub-tasks can get, uh, confused if trying to chain/start too many tasks from within tasks.

In this case, you can move task.start('compile') to after your usemin task:

export async function build(task) {
  await task.source('.tmp/index.html').usemin({
    staticDir: c.build,
  }).target(c.build);
  await task.start('compile');
}

But I recommend keeping all tasks unqiue/simple and then running them from the CLI (or npm script) like this:

export async function build(task) {
  await task.source('.tmp/index.html').usemin({
    staticDir: c.build,
  }).target(c.build);
}
// package.json
{
  "scripts": {
    "build": "taskr compile build"
  }
}

Either of those should work for you. Your plugin is fine 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants