dougludlow/plugin-sass

Nested import failed to be fetch

davinkevin opened this issue · 5 comments

Hi,

I have a specific behavior and I would like to see if it's a bug.

I have a project with a JS file importing one scss in the folder /config/style/bootstrap.js :

import angular from 'angular';
import './bootstrap.scss!';

export default angular.module('app.config.bootstrap', []);

And in my ./bootstrap.scss I have the following :

@import "myvar";
@import "/jspm_packages/github/twbs/bootstrap-sass@3.3.5/assets/stylesheets/bootstrap";

The file _myvar.scss is correctly loaded like the file _bootstrap.scss located in jspm_packages.
But the file _bootstrap.scss contains some relative @import too (https://github.com/twbs/bootstrap-sass/blob/master/assets/stylesheets/_bootstrap.scss).

The result is the sass plugin tries to load all the file relative to the location of my JS instead of using the jspm_package path.

The result of the console is the following :
image

You can see the folder tree of the project (i'm serving from /public and ./ when running in browser-sync)
image

I don't know I to handle this problem, could you help ?

Thanks

PS : I've changed some folder name to simplify the example (and avoid having multiple bootstrap folder at different location, this is why in the github project I have another folder name for the bootstrap.js)

I believe you have to modify paths. Maybe @phenomnomnominal knows a trick for this?

I've tracked this problem down to 2 issues in sass-inject.js

urlBase is being set and persisted on line 64 then used on line 29. All subsequent calls to load partials use the urlBase of the parent scss.

The result is that if I have /scss/modules/module1.scss that imports partials from /scss/partials/_variables.scss, sass-inject will set the urlBase=/scss/modules/ when loading module1.scss and use it when looking for the partials which will not exist there. e.g. _variables.scss will be looked for in /scss/module/partials/_variables.scss

Any pull requests to fix this are welcome 😎

@screendriver I believe I've got a fix for the issue, if you wouldn't mind reviewing.

Fixed with pull request #24