diff --git a/lib/loader.js b/lib/loader.js index dea681b1..fa926375 100644 --- a/lib/loader.js +++ b/lib/loader.js @@ -40,6 +40,7 @@ function sassLoader(content) { // Supported since v4.27.0 if (this.getResolve) { resolve = this.getResolve({ + mainFields: ['sass', 'main'], extensions: ['.scss', '.sass', '.css'], }); } diff --git a/test/index.test.js b/test/index.test.js index cfc7da0d..63c99a92 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -169,6 +169,8 @@ implementations.forEach((implementation) => { }, } )); + it('should resolve sass field correctly', () => + execTest(`import-sass-field`)); }); describe('custom importers', () => { it('should use custom importer', () => diff --git a/test/node_modules/sass-sass-field/nested/style.sass b/test/node_modules/sass-sass-field/nested/style.sass new file mode 100644 index 00000000..d3e4216c --- /dev/null +++ b/test/node_modules/sass-sass-field/nested/style.sass @@ -0,0 +1,2 @@ +a + display: block diff --git a/test/node_modules/sass-sass-field/package.json b/test/node_modules/sass-sass-field/package.json new file mode 100644 index 00000000..d87b94a8 --- /dev/null +++ b/test/node_modules/sass-sass-field/package.json @@ -0,0 +1,12 @@ +{ + "name": "sass-sass-field", + "version": "1.0.0", + "description": "test", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "", + "license": "MIT", + "sass": "nested/style.sass" +} diff --git a/test/node_modules/scss-sass-field/nested/style.scss b/test/node_modules/scss-sass-field/nested/style.scss new file mode 100644 index 00000000..d1308905 --- /dev/null +++ b/test/node_modules/scss-sass-field/nested/style.scss @@ -0,0 +1,3 @@ +a { + display: block; +} diff --git a/test/node_modules/scss-sass-field/package.json b/test/node_modules/scss-sass-field/package.json new file mode 100644 index 00000000..e26bfaa8 --- /dev/null +++ b/test/node_modules/scss-sass-field/package.json @@ -0,0 +1,12 @@ +{ + "name": "scss-sass-field", + "version": "1.0.0", + "description": "test", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "", + "license": "MIT", + "sass": "nested/style.scss" +} diff --git a/test/sass/import-sass-field.sass b/test/sass/import-sass-field.sass new file mode 100644 index 00000000..c81411ac --- /dev/null +++ b/test/sass/import-sass-field.sass @@ -0,0 +1 @@ +@import "~sass-sass-field" diff --git a/test/scss/import-sass-field.scss b/test/scss/import-sass-field.scss new file mode 100644 index 00000000..b8453330 --- /dev/null +++ b/test/scss/import-sass-field.scss @@ -0,0 +1 @@ +@import "~scss-sass-field"; diff --git a/test/tools/createSpec.js b/test/tools/createSpec.js index 2361d6be..62d0b743 100644 --- a/test/tools/createSpec.js +++ b/test/tools/createSpec.js @@ -38,6 +38,26 @@ function createSpec(ext) { basePath, path.resolve(testFolder, ext, 'another', `alias.${ext}`) ); + const pathToScssSassField = path.relative( + basePath, + path.resolve( + testFolder, + 'node_modules', + 'scss-sass-field', + 'nested', + 'style.scss' + ) + ); + const pathToSASSSassField = path.relative( + basePath, + path.resolve( + testFolder, + 'node_modules', + 'sass-sass-field', + 'nested', + 'style.sass' + ) + ); fs.readdirSync(path.join(testFolder, ext)) .filter( @@ -57,6 +77,8 @@ function createSpec(ext) { if (/\.css$/.test(url) === false) { // eslint-disable-next-line no-param-reassign url = url + .replace(/^~scss-sass-field/, pathToScssSassField) + .replace(/^~sass-sass-field/, pathToSASSSassField) .replace(/^~bootstrap-sass/, pathToBootstrap) .replace(/^~@org\/pkg/, pathToScopedNpmPkg) .replace(/^~module/, pathToModule)