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

Is there a recommended solution for re-writing relative paths? #22

Open
colllin opened this issue Jan 14, 2016 · 1 comment
Open

Is there a recommended solution for re-writing relative paths? #22

colllin opened this issue Jan 14, 2016 · 1 comment

Comments

@colllin
Copy link

colllin commented Jan 14, 2016

When I @import from an npm package whose stylesheet includes a relative link to a font, the font link is broken upon import.

@Sarah4VT
Copy link

Sarah4VT commented Mar 8, 2016

I had a similar issue (described here in more detail) and found rework-npm to not be handling relative paths well. Playing around with what would fix it, if I change this line in getImport

contents = parse(contents, { source: path.relative(root, file) });

to call path.resolve instead, it works fine for me.

The problem I saw was that by the time the file was being read here (if you follow the node modules down it's in atomify -> atomify-css -> rework -> css -> source-map-resolve in the lib/source-map-resolve-node.js file)

mapData.map = parseMapToJSON(String(read(mapData.url)))

mapData.url is "../node_modules/bootstrap/dist/css/bootstrap.css.map" which would be right if it's read relative to the root directory that got passed into rework-npm. I verified the root directory that got passed in was my styles directory, where my css file lives. However, by the time the read happened, that root directory isn't used and instead was run using the cwd from the process which was my project root, so it's trying to find a node_modules directory as a peer to my project directory.

My directory structure for reference:

  • project
    • node_modules
      • bootstrap
        • dist
          • css
            • bootstrap.css
            • bootstrap.css.map
    • styles
      • main.css

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