Skip to content
This repository has been archived by the owner on Jul 24, 2024. It is now read-only.

Is there a way to resolve a dependency from a config file e.g. bower.json #966

Closed
rbhalla opened this issue May 18, 2015 · 6 comments
Closed

Comments

@rbhalla
Copy link

rbhalla commented May 18, 2015

My title might be slightly confusing so I will give an example. Right now I am installing bourbon using bower. I have set bower_components to be in my included paths, so then I can do @import 'bourbon'. The problem is the main file for bourbon is nested quite deeply (/app/assets/stylesheets/bourbon). This means when I import I have quite a long import string each time.

I frequently use webpack too, and they have quite a clean approach to this in the form of a resolver plugin. I'm not sure how well this translates over to the node-sass paradigm so I thought I'd ask. With webpack I can say new webpack.ResolverPlugin.DirectoryDescriptionFilePlugin("bower.json", ["main"]) and this automatically reads the bower.json file of an imported folder and resolves my import statement to the correct file.

Is there an equivalent in node-sass?

@xzyfer
Copy link
Contributor

xzyfer commented May 18, 2015

Sounds like you want loadPaths

@xzyfer xzyfer closed this as completed May 18, 2015
@xzyfer xzyfer reopened this May 18, 2015
@rbhalla
Copy link
Author

rbhalla commented May 18, 2015

I can't seem to find anything about that option in the documentation. Do you mind pointing me to the right place? Or just explaining how it works from your knowledge?

@xzyfer
Copy link
Contributor

xzyfer commented May 18, 2015

Apologies it's includePaths in node-sass, which maps to loadPaths in Ruby Sass - https://github.com/sass/node-sass#includepaths

@rbhalla
Copy link
Author

rbhalla commented May 18, 2015

Hi @xzyfer

As I mentioned in the first post, I already have setup my include paths correctly. The problem is that the necessary files aren't necessarily in the root of the folder. The actual location is stored in files such as bower.json and package.json, but there is no way to read that information and have it interpreted correctly.

@jameslnewell
Copy link
Contributor

You'd need to write an importer for that. I've done something similar but for npm modules. It resolves the npm module from the import path (e.g. @import "bourbon";) and looks at the "main.scss" key in the package.json to resolve the entry file.

You should write a plugin for sass-composer 😉.

@xzyfer
Copy link
Contributor

xzyfer commented Jun 11, 2015

You will need to write a custom importer.

@xzyfer xzyfer closed this as completed Jun 11, 2015
jiongle1 pushed a commit to scantist-ossops-m2/node-sass that referenced this issue Apr 7, 2024
# for free to subscribe to this conversation on GitHub. Already have an account? #.
Projects
None yet
Development

No branches or pull requests

3 participants