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

handle url() #4

Open
MoOx opened this issue Jan 12, 2015 · 11 comments
Open

handle url() #4

MoOx opened this issue Jan 12, 2015 · 11 comments

Comments

@MoOx
Copy link
Owner

MoOx commented Jan 12, 2015

css-loader handle import + url() as require
cssnext can handle import & will soon be able to handle url() has well (ref MoOx/postcss-cssnext#57)
what do you think about handling url() like css-loader ?

Meanwhile, since loaders are executed from right to left, the example should show style-loader, cssnext-loader then css-loader (so import + url() are done at the same time to avoid this kind of issues: webpack-contrib/css-loader#33 or webpack-contrib/css-loader#34)

@MoOx
Copy link
Owner Author

MoOx commented Jan 12, 2015

Or maybe, we should just disable import by default overhere so one module handle all of that. But that's not the best thing to do to benefit of shared variables :/

@MoOx
Copy link
Owner Author

MoOx commented Jan 30, 2015

postcss-url has been included in cssnext core (not released yet), but we might use that to make cssnext-loader a replacement for css-loader.

@vanwagonet
Copy link
Contributor

I would love for cssnext-loader to support running url() through webpack loaders, right now postcss-url custom url handler doesn't provide enough info to replicate what url-loader does.

If I get some time in the next week or two I'll try to put together a pull request.

@MoOx
Copy link
Owner Author

MoOx commented Mar 4, 2015

What would you need in the url callback to do what you want ? I can update postcss-url ;)

@vanwagonet
Copy link
Contributor

If the url custom function got not just the url, but also the file path of the containing style sheet, then it should be fairly straightforward to run it through loaders, or at least replicate what you would do with loaders. The custom function would also need to allow for async.

Right now custom functions can't even resolve relative paths since they only get the url.

I think it would be good for cssnext-loader to allow the url option to specify the loaders to use. Something like:

url: {
  url: 'inline',
  loaders: [
    { test:/\.(jpe?g|png)$/i, loader:'img?minimize' }
  ]
}

The loaders would probably need to end without converting to javascript though, which is probably why we couldn't just use the loaders in the main modules config. What do you think?

@vanwagonet
Copy link
Contributor

Also note that putting the css-loader to the right of cssnext-loader doesn't work properly because css-loader outputs javascript, which cssnext won't know how to handle.

@MoOx
Copy link
Owner Author

MoOx commented Mar 5, 2015

I can add an argument to the postcss callback: the postcss node itself. It contains a source property that contains filename (that is what is used by this plugin to rebase (default behavior)).

What we should do instead a doing a loaderception is to call webpack api in this callback, so normal loaders are used (I think css-loader is doing that).

@vanwagonet
Copy link
Contributor

That sounds simpler for the user. My only concern is trying to make sense of the resource. css-loader can handle js because its final output is js.

If cssnext-loader outputs js, you can't pipe it to url-loader.

I guess we could evaluate the module. I dunno I'll try some things and see.

@MoOx
Copy link
Owner Author

MoOx commented Mar 5, 2015

We don't need a url-loader.
css-loader handle css to js + url() + @import.
with cssnext-loader we can handle url + imports (imports are already handled)

@vanwagonet
Copy link
Contributor

I spent some time trying to pass the urls through the webpack loaders and didn't have any luck getting it to work. I think for now, just getting the postcss node in the custom url handler will help a lot, even if using loaders doesn't work out.

MoOx added a commit to postcss/postcss-url that referenced this issue Mar 12, 2015
@MoOx
Copy link
Owner Author

MoOx commented Mar 12, 2015

postcss-url 2.1.0 now offer 2 arguments. The one added is the related postcss declaration object.
It contains a .source property that might help (=> decl.source.input.filename).

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