dependents / dependents/node-dependency-tree

Sass imports from node_modules

Open
#132 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
777
Forks
83
PR merge metrics
No merged PRs in 30d

Description

Howdy! In sass, you can use `sass-loader` with Webpack to resolve Sass imports from node modules. This can look something like the following:

```sass
@import 'npm-package/stylesheet'

// etc
```

This should resolve to `node_modules/npm-package/stylesheet.scss`. Unfortunately, cabinet + sass-lookup doesn't quite handle this use case. You can get it to resolve using _just_ cabinet, by passing `node_modules` as a directory, but dependency tree doesn't accept multiple directories in general, so that won't work for our use case. I was wondering what a good path would be towards implementing support.

A really naive implementation could be something like this as the [lookup function for sass in cabinet](https://github.com/dependents/node-filing-cabinet/blob/754d3889e8ba53283a126eb69f08c71b760c8c2b/index.js#L30).

```js
function sassResolver(options) {
let { directory } = options;
if (typeof directory === 'string') {
directory = [ directory ];
}
directory.push( 'node_modules' );
return sassLookup({ ...options, directory })
}
```

This does work, but it wouldn't be able to handle different node_modules locations, such as in monorepos. One could also add a custom resolver like this: https://github.com/Automattic/wp-calypso/blob/6ef9f9278aaf368cd629ba69c33c4768dc7ea08d/bin/render-stylesheet.js#L16-L23. But I'm not sure where exactly to put that -- would the sass-lookup package be a good fit?

What are your thoughts?

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.