cssdream / cssgrace

从今天起,写简单优雅面向未来的 CSS。From now on,writing brief,elegant,future-oriented CSS.
MIT License
593 stars 63 forks source link

Relative paths should start from file location, not project root #33

Open ericorruption opened 9 years ago

ericorruption commented 9 years ago

Hello,

I'm having an issue with relative paths. In a SCSS partial i'm declaring a background-image as url(../img/bg.jpg), however the plugin searches for this file at the root of the project (/Users/user/Sites/code/project-folder), not relative to the stylesheet path (should be /Users/user/Sites/code/project-folder/src/css - where my CSS is).

Stack trace is as follows:

message: 'ENOENT, no such file or directory \'/Users/user/Sites/code/img/bg.jpg\'',
stack: 'Error: ENOENT, no such file or directory \'/Users/user/Sites/code/img/bg.jpg\'
    at Error (native)
    at Object.fs.openSync (fs.js:500:18)
    at syncFileToBuffer (/Users/user/Sites/code/project-folder/node_modules/cssgrace/node_modules/image-size/lib/index.js:58:23)
    at module.exports (/Users/user/Sites/code/project-folder/node_modules/cssgrace/node_modules/image-size/lib/index.js:100:18)
    at imageSetMixin (/Users/user/Sites/code/project-folder/node_modules/cssgrace/lib/index.js:423:9)
    at /Users/user/Sites/code/project-folder/node_modules/cssgrace/lib/index.js:477:5
    at /Users/user/Sites/code/project-folder/node_modules/gulp-postcss/node_modules/postcss/lib/container.js:88:34
    at /Users/user/Sites/code/project-folder/node_modules/gulp-postcss/node_modules/postcss/lib/container.js:73:26
    at Rule.each (/Users/user/Sites/code/project-folder/node_modules/gulp-postcss/node_modules/postcss/lib/container.js:59:22)
    at Rule.walk (/Users/user/Sites/code/project-folder/node_modules/gulp-postcss/node_modules/postcss/lib/container.js:72:21)'
jglover commented 9 years ago

I've also run into this issue, the code looks like it has an option called opts.from but I don't know how to pass that in to the postcss CLI?

ghost commented 9 years ago

+1 Also having this problem

machwatt commented 8 years ago

+1

yuezk commented 8 years ago

I think this issue have been fixed in the new version 3.x, I changed the path resolve in the PR #39. Related code is here.

ericorruption commented 8 years ago

Resolved indeed.

DotCoyote commented 8 years ago

Nope, sincerely not, now it uses the path from the source-file:

/ css
/ img
  | image.png
/ src
  / scss
    | style.scss

style.scss:

.foo {
  background-image: url("../img/image.png");
}
Error: ENOENT: no such file or directory, open '/project/src/img/image.png'
yuezk commented 8 years ago

@CinKon , your source file is located in src/scss, and your built css is located in css folder. And now the plugin resolved path is relative to the source file path, so there should have a img folder under the src folder. I know your situation, and I think you should use some assets rebase plugins to handle this.

PFanz commented 7 years ago

+1 如果地址是非本地地址会报错