Skip to content

Commit ee64320

Browse files
marvinsideAkryum
authored andcommitted
feat: Config Option for other .scss/.sass import paths. (#346)
* Added config option to package.json to find imports Scss imports in imports are often broken as the paths there may be absolute to node_modules (at least in the case of @Material packages). To fix this, there is now a config option in package.json: vue.css.loaderOptions.sass.includePaths (array of Strings) * replaced tab caracter with spaces * fixed indention
1 parent aba08eb commit ee64320

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

packages/vue-sass/vue-sass.js

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,27 @@ function resolveImport (dependencyManager) {
1818
let currentDirectory = path.dirname(prev === 'stdin' ? this.options.outFile : prev)
1919
resolvedFilename = path.resolve(currentDirectory, url)
2020
}
21+
const importPaths = [ resolvedFilename ]
22+
const pjson = require("package.json") // can not be moved outside. Reqired here to get the package.json of the project that is being run
2123

22-
resolvedFilename = discoverImportPath(resolvedFilename)
23-
if (resolvedFilename === null) {
24+
try {
25+
// get the package.json config option and create paths for the requested file.
26+
pjson.vue.css.loaderOptions.sass.includePaths.forEach( (str) => {
27+
importPaths.push(path.resolve(str, url))
28+
})
29+
} catch (e) {
30+
// Ignore error. package.json option is not set.
31+
}
32+
33+
const resolvedNames = importPaths.map( discoverImportPath ).filter((fileName) => fileName !== null && typeof fileName !== "undefined");
34+
35+
if (resolvedNames.length < 1) {
2436
done(new Error('Unknown import (file not found): ' + url))
2537
} else {
26-
dependencyManager.addDependency(resolvedFilename)
38+
dependencyManager.addDependency(resolvedNames[0])
2739

2840
done({
29-
file: resolvedFilename,
41+
file: resolvedNames[0],
3042
})
3143
}
3244
}

0 commit comments

Comments
 (0)