From d8931f31a56c0b37e34a35334b55f923ba1561d1 Mon Sep 17 00:00:00 2001 From: Jorrit Schippers Date: Sun, 5 Jul 2015 18:31:49 +0200 Subject: [PATCH] Fix importing css files from sass/scss Fixes #101 --- CHANGELOG.md | 4 ++++ LICENSE | 0 index.js | 2 +- test/prepare.js | 7 ++++--- test/sass/import-other-style.sass | 1 + test/scss/import-other-style.scss | 1 + 6 files changed, 11 insertions(+), 4 deletions(-) mode change 100755 => 100644 LICENSE diff --git a/CHANGELOG.md b/CHANGELOG.md index 5ce70320..d31dccb3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,10 @@ Changelog --------- +### ???? + +- Fix importing css files from scss/sass + ### 1.0.2 - Fix a bug where files could not be imported across language styles [#73](https://github.com/jtangelder/sass-loader/issues/73) diff --git a/LICENSE b/LICENSE old mode 100755 new mode 100644 diff --git a/index.js b/index.js index 0788a663..d6174842 100644 --- a/index.js +++ b/index.js @@ -27,7 +27,7 @@ module.exports = function (content) { var isSync = typeof callback !== 'function'; var self = this; var resourcePath = this.resourcePath; - var extensionMatcher = /\.(sass|scss)$/; + var extensionMatcher = /\.(sass|scss|css)$/; var fileExt; var opt; var contextMatch; diff --git a/test/prepare.js b/test/prepare.js index 7ed4a144..4b8b2c1b 100644 --- a/test/prepare.js +++ b/test/prepare.js @@ -6,12 +6,13 @@ var path = require('path'); var error = 'error'; var filesWithTildeImports = [ - 'imports', 'underscore-imports' + 'imports', 'underscore-imports', 'import-other-style' ]; ['scss', 'sass'].forEach(function (ext) { var files = []; var basePath = path.join(__dirname, ext); + var nodeModulesPath = path.join(__dirname, 'node_modules') + '/'; fs.readdirSync(path.join(__dirname, ext)) .filter(function (file) { @@ -27,7 +28,7 @@ var filesWithTildeImports = [ // We need to replace all occurrences of '~' with relative paths // so node-sass finds the imported files without webpack's resolving algorithm fileContent = fs.readFileSync(fileName, 'utf8'); - fileContent = fileContent.replace('~', '../node_modules/'); + fileContent = fileContent.replace('~', nodeModulesPath); fs.writeFileSync(fileName, fileContent, 'utf8'); } @@ -43,7 +44,7 @@ var filesWithTildeImports = [ if (filesWithTildeImports.indexOf(fileWithoutExt) > -1) { // Revert back our changes and add '~' again fileContent = fs.readFileSync(fileName, 'utf8'); - fileContent = fileContent.replace('../node_modules/', '~'); + fileContent = fileContent.replace(nodeModulesPath, '~'); fs.writeFileSync(fileName, fileContent, 'utf8'); } diff --git a/test/sass/import-other-style.sass b/test/sass/import-other-style.sass index 7d022f58..62d31dee 100644 --- a/test/sass/import-other-style.sass +++ b/test/sass/import-other-style.sass @@ -1,2 +1,3 @@ // Importing the other language style requires the file extension to be set explicitly @import ../scss/another/module.scss +@import ~some-module.css diff --git a/test/scss/import-other-style.scss b/test/scss/import-other-style.scss index bfdfccb0..273bbcd1 100644 --- a/test/scss/import-other-style.scss +++ b/test/scss/import-other-style.scss @@ -1,2 +1,3 @@ // Importing the other language style requires the file extension to be set explicitly @import "../sass/another/module.sass"; +@import "~some-module.css";