cssgrace icon indicating copy to clipboard operation
cssgrace copied to clipboard

Relative paths should start from file location, not project root

Open ericorruption opened this issue 9 years ago • 8 comments

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)'

ericorruption avatar Sep 02 '15 16:09 ericorruption

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?

jglover avatar Sep 30 '15 01:09 jglover

+1 Also having this problem

ghost avatar Oct 01 '15 01:10 ghost

+1

machwatt avatar Oct 30 '15 14:10 machwatt

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.

yuezk avatar Nov 11 '15 15:11 yuezk

Resolved indeed.

ericorruption avatar Dec 08 '15 16:12 ericorruption

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'

DotCoyote avatar Dec 10 '15 14:12 DotCoyote

@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.

yuezk avatar Dec 11 '15 05:12 yuezk

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

PFanz avatar Oct 21 '16 07:10 PFanz