Anidetrix / rollup-plugin-styles

🎨 Universal Rollup plugin for styles: PostCSS, Sass, Less, Stylus and more.
https://anidetrix.github.io/rollup-plugin-styles
MIT License
243 stars 43 forks source link

JSON.parse() in MapModifier is feeded with png-file content #116

Closed dilyanpalauzov closed 4 years ago

dilyanpalauzov commented 4 years ago

When I set plugins:[ style({url: {resolve: console.log}})] my understanding is, that I will see with which parameters url.resolve is called. But apparently it is not called.

In my .css files I have url('..images/x.png'). rollup-plugin-style prints: Unresolved URL in url('..images/x.png') . I find no option how to resolve this, except setting plugins:[ style({url: false})]

With or without it, I get from Unexpected token in MapModifier/JSON.parse. The string that is passed to JSON parse is a png-file-content, so it cannot be parsed but somehow the system finds the file, yetit prints Unresolved url for png files. (it might be differnt pngs that are found and that are sent to JSON.parse())

Anidetrix commented 4 years ago

Hello @dilyanpalauzov, thanks for dedicating your time to this!

When I set plugins:[ style({url: {resolve: console.log}})] my understanding is, that I will see with which parameters url.resolve is called. But apparently it is not called.

Just tried it and could not reproduce your issue, for me it is indeed being called, printing out both url and basedir. It indeed causes URLs to be unresolved, since you do need to return the resolved file (as it is in API Reference)

In my .css files I have url('..images/x.png'). rollup-plugin-style prints: Unresolved URL in url('..images/x.png') . I find no option how to resolve this, except setting plugins:[ style({url: false})]

You probably forgot / after .., like this: ../images/x.png. You can also filter out unwanted warnings using Rollup's onwarn

With or without it, I get from Unexpected token in MapModifier/JSON.parse

Ok, I've added a check to skip sourcemap if is it not a valid JSON, thanks for catching that, please update, try again and let me know if it helps

dilyanpalauzov commented 4 years ago

Yes, this helps, But plugins:[ style({url: {resolve: console.log}})] is still not called. Can it be that I need any postcss configuration files to call url.resolve, otherwise it is skipped?

Anidetrix commented 4 years ago

Yes, this helps, But plugins:[ style({url: {resolve: console.log}})] is still not called. Can it be that I need any postcss configuration files to call url.resolve, otherwise it is skipped?

This is due to the fact that log is this-bound, try console.log.bind(console) instead. Does it work for you?

dilyanpalauzov commented 4 years ago

In fact I called

plugins:[
  style({
    url: {resolve: (x, y) => console.log("AAA " + x + ' :: ' + y)}
  })
]

and it was not called. However with version 3.0.1 it is called and the png files, reported previously as unfindable, are also found.

piotr-cz commented 4 years ago

By the way, there is new link to API Reference

Anidetrix commented 4 years ago

@piotr-cz updated the link