Skip to content

Commit

Permalink
feat: support sass field in package.json (#647)
Browse files Browse the repository at this point in the history
  • Loading branch information
evilebottnawi authored Dec 14, 2018
1 parent ff90dd6 commit a8709c9
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
});
}
Expand Down
2 changes: 2 additions & 0 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () =>
Expand Down
2 changes: 2 additions & 0 deletions test/node_modules/sass-sass-field/nested/style.sass

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions test/node_modules/sass-sass-field/package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions test/node_modules/scss-sass-field/nested/style.scss

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions test/node_modules/scss-sass-field/package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions test/sass/import-sass-field.sass
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@import "~sass-sass-field"
1 change: 1 addition & 0 deletions test/scss/import-sass-field.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@import "~scss-sass-field";
22 changes: 22 additions & 0 deletions test/tools/createSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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)
Expand Down

0 comments on commit a8709c9

Please sign in to comment.