Skip to content

Commit ee9800b

Browse files
authored
feat: resolve "~" scss import statements to nearest node_modules (#352)
Uses 'node-sass-tilde-importer' to resolve imports during scss transformation. See https://www.npmjs.com/package/node-sass-tilde-importer Resolves #346
1 parent df5c271 commit ee9800b

File tree

3 files changed

+13
-10
lines changed

3 files changed

+13
-10
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
"less": "^2.7.2",
3636
"lodash": "^4.17.4",
3737
"node-sass": "^4.5.3",
38+
"node-sass-tilde-importer": "^1.0.0",
3839
"postcss": "^6.0.2",
3940
"read-file": "^0.2.0",
4041
"rimraf": "^2.6.1",

src/lib/steps/assets.ts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import * as autoprefixer from 'autoprefixer';
99
import * as browserslist from 'browserslist';
1010
import * as postcss from 'postcss';
1111
import * as sass from 'node-sass';
12+
import * as nodeSassTildeImporter from 'node-sass-tilde-importer';
1213
import * as less from 'less';
1314
import * as stylus from 'stylus';
1415

@@ -99,7 +100,7 @@ async function renderPreProcessor(filePath: string, srcPath: string): Promise<st
99100
case '.scss':
100101
case '.sass':
101102
log.debug(`rendering sass from ${filePath}`);
102-
return await renderSass({ file: filePath, importer: sassImporter });
103+
return await renderSass({ file: filePath, importer: nodeSassTildeImporter });
103104

104105
case '.less':
105106
log.debug(`rendering less from ${filePath}`);
@@ -118,15 +119,6 @@ async function renderPreProcessor(filePath: string, srcPath: string): Promise<st
118119

119120
}
120121

121-
// TODO: use node-sass-magic-importer
122-
const sassImporter = (url: string): any => {
123-
if (url[0] === '~') {
124-
url = path.resolve('node_modules', url.substr(1));
125-
}
126-
127-
return { file: url };
128-
}
129-
130122
const renderSass = (sassOpts: any): Promise<string> => {
131123

132124
return new Promise((resolve, reject) => {

yarn.lock

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1146,6 +1146,10 @@ find-index@^0.1.1:
11461146
version "0.1.1"
11471147
resolved "https://registry.yarnpkg.com/find-index/-/find-index-0.1.1.tgz#675d358b2ca3892d795a1ab47232f8b6e2e0dde4"
11481148

1149+
find-parent-dir@^0.3.0:
1150+
version "0.3.0"
1151+
resolved "https://registry.yarnpkg.com/find-parent-dir/-/find-parent-dir-0.3.0.tgz#33c44b429ab2b2f0646299c5f9f718f376ff8d54"
1152+
11491153
find-up@^1.0.0:
11501154
version "1.1.2"
11511155
resolved "https://registry.yarnpkg.com/find-up/-/find-up-1.1.2.tgz#6b2e9822b1a2ce0a60ab64d610eccad53cb24d0f"
@@ -2197,6 +2201,12 @@ node-pre-gyp@^0.6.39:
21972201
tar "^2.2.1"
21982202
tar-pack "^3.4.0"
21992203

2204+
node-sass-tilde-importer@^1.0.0:
2205+
version "1.0.0"
2206+
resolved "https://registry.yarnpkg.com/node-sass-tilde-importer/-/node-sass-tilde-importer-1.0.0.tgz#653d048a270464a1865ef9a99cc80ee2d80f9c97"
2207+
dependencies:
2208+
find-parent-dir "^0.3.0"
2209+
22002210
node-sass@^4.5.3:
22012211
version "4.7.2"
22022212
resolved "https://registry.yarnpkg.com/node-sass/-/node-sass-4.7.2.tgz#9366778ba1469eb01438a9e8592f4262bcb6794e"

0 commit comments

Comments
 (0)