Last active
September 18, 2021 09:16
-
-
Save ethanve/598b614f2d0f1b8530c27757cdc08b21 to your computer and use it in GitHub Desktop.
Custom Webpack loader that prepends a Sass import to each imported Sass file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Loader that automatically prepends a reference to sassIncludes in the Webpack configuration files | |
| */ | |
| import fs from 'fs'; | |
| import path from 'path'; | |
| import config from './config'; | |
| let fileFound = true; | |
| if (!config.sassIncludes || !fs.existsSync(config.sassIncludes)) { | |
| console.warn('Can not find the sassIncludes files'); | |
| fileFound = false; | |
| } | |
| module.exports = function (content) { | |
| this.cacheable && this.cacheable(); | |
| if (!fileFound) { | |
| return content; | |
| } | |
| const relativePath = path.relative(path.dirname(this.resourcePath), config.sassIncludes); | |
| return `import "${relativePath}"; ${content}`; | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@ethanve: Please, change
fs.existstofs.existsSync.fs.existsreturnsundefined.