nDmitry / grunt-autoprefixer

Parse CSS and add vendor-prefixed CSS properties using the Can I Use database. Based on Autoprefixer.
MIT License
795 stars 60 forks source link

map location #26

Closed mihai-vlc closed 10 years ago

mihai-vlc commented 10 years ago

Is there any reason for this limitation ?

You cannot specify a path where to save a map file, it will be saved at the same directory as the output CSS file.
ai commented 10 years ago

We think about this case, but we didn’t find real user cases, when map file will be in another dir.

What is your user case? :)

mihai-vlc commented 10 years ago

Well i want to specify this

/*# sourceMappingURL=main.css.map */

to be on a remote server, or on a different location on the file system. in my setup i have like this

src/assets/scss
and my compiled css goes to
dist/assets/css

ai commented 10 years ago

But your map files already does to dist/assets/css. All of current compilators with map support put map file in same dir with CSS file.

mihai-vlc commented 10 years ago

yes i was looking at the problem the wrong way, thank you

CathyMacars commented 10 years ago

In my case, since I use grunt-contrib-watch, if I make autoprefixer run in the same file at the same location, it will loop. To fix that, I make sass compile from a sass folder to a build folder, and then autoprefixer runs from the build folder and outputs in a css folder, which is where the files are linked from on index.html. Except the .map file was created on the build folder w/ the unprefixed .css file (through the sass task) and thus, it isn't in the final css folder. And, if I just move it w/ some kind of copy/sync task, the mapping will obviously be wrong. So... how do I fix this workflow?

mihai-vlc commented 10 years ago

@CathyMacars i don't understand if you run autoprefixer after sass finishes why would it loop ? You should have something similar to this: you add a watch on the sass files and you run sass compile then autoprefixer on the generated css files. There should be no watch on the actual css file.

nDmitry commented 10 years ago

@CathyMacars as @ionutvmi said, you should watch for Sass files and run tasks like so: ['sass', 'autoprefixer']. Here is an example.

CathyMacars commented 10 years ago

@ionutvmi I guess it was looping bc I was running both tasks separate on watch. Like, first sass on scss and then autoprefixer on css. @nDmitry thanks for the example. I updated my workflow as follows, but the mapping is still wrong. It points to the wrong file &/or wrong line. What am I missing?

sassCfg =
    main:
        options:
            sourceComments: 'map'
        files: 'target/project/css/alpha.css':'src/main/sass/alpha.scss'
autoprefixerCfg =
    main:
        options:
            map: true
        src: 'target/project/css/alpha.css'
watchCfg =
    css:
        files: 'src/main/sass/**'
        tasks: ['sass', 'autoprefixer']
CathyMacars commented 10 years ago

I should state that the map source path seems right this time around, so now I really don't understand whats wrong. :/ This is the folder structure:

root
  src
  |  main
  |    sass 
  target
    project
      css

And this is the map source path: "sources": ["../../../src/main/sass/etc"]

CathyMacars commented 10 years ago

It seems like autoprefixer isn't updating the .map file, since if I take it (autoprefixer) out of the equation, it works.

nDmitry commented 10 years ago

And this is the map source path: "sources": ["../../../src/main/sass/etc"]

And it's correct (relative to alpha.css), so I don't really get what's wrong now. If you cannot see Sass sources in your browser, make sure your dev server serves /src dir (if you have one).

CathyMacars commented 10 years ago

That's the thing, I can see the sass sources, they're just wrong. They point to the wrong sass file. And If I don't run autoprefixer, it works. I use grunt-sass, btw (instead of grunt-contrib-sass). Don't know if that matters, but hey...

nDmitry commented 10 years ago

I can't reproduce it with the same folder structure, plugin configuration and Sass 3.3.7.

CathyMacars commented 10 years ago

Since you mentioned your sass version, I tried updating it (sass) and autorpefixer's and it works now. I haven't thought of it before bc I installed it recently, but hey... Time flies I guess. Thanks for the help and sorry for the trouble. :)