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

adding to the buffer in an optimized file is not (always) synchronous #55

Closed
NetForce1 opened this issue Mar 27, 2013 · 4 comments
Closed

Comments

@NetForce1
Copy link
Contributor

css-builder writes async requires to the output file to call addBuffer. This causes extra loads for the css files because modules that define the css file as a dependency are loaded before the async require executes.
I fixed it by wrapping the call to addBuffer in a define(), but I'm not sure if that's really the way to go.

cssAPI.write = function(pluginName, moduleName, write, extension, parse) {
  // ....
  if (separateCSS)
    //...
  else 
    write.asModule(pluginName + '!' + moduleName, 'define(function(){' + 
        'require("css").addBuffer("' + moduleName + (parse ? '.less", true' : '.css"') + ')' + 
    '})');
}
@guybedford
Copy link
Owner

Ok, I removed the code that ensured synchronous injection previously because I thought that it wasn't possible to duplicate, but if you have code running directly after a layer that uses a css require, it seems to be happening in your case.

If you can explain more clearly what calls happen when to cause this that would be great to understand it better.

For now, I've added a sync injection code to the builder on the master branch. Try that and let me know if it sorts it?

@guybedford
Copy link
Owner

I'm not doing it in the define because it's trying to accomplish another task - namely to know which css is in the layer script, and then to inject it. In order to properly understand the css for the layer it needs to be a sync operation so the fix above is good. The easier way to do this is simply with a global variable, but I'm trying to be good and avoid that!

@NetForce1
Copy link
Contributor Author

Your fix seems to be working ok, thanks!

I have not created a stripped down test case (yet), but it happened in a multi-module build that had css.js (and some less) in the first module, and some other less in other modules.

@guybedford
Copy link
Owner

This is at least sorted, focusing on #56 now, the other side of this. I have an alternate fix to the merge I am testing right now.

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