Last active
September 23, 2021 09:18
-
-
Save lifeart/60496cd75b21beea2f88aab5197f92e2 to your computer and use it in GitHub Desktop.
sass-hook
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
| const stew = require('broccoli-stew'); | |
| const themeName = process.env.EMBER_THEME || 'default'; | |
| module.exports = { | |
| _registers: [], | |
| setupPreprocessorRegistry(type, registry, isFinal = false) { | |
| if (themeName === 'default') { | |
| return; | |
| } | |
| this._registers.push([type, registry]); | |
| if (!isFinal) { | |
| return; | |
| } | |
| const sass = registry.load('css').find(({ name }) => name === 'ember-cli-sass'); | |
| if (!sass) { | |
| throw new Error('unable to find ember-cli-sass processor'); | |
| } | |
| registry.remove('css', sass); | |
| function SASSOwerridePlugin() { | |
| this.name = 'my-sass-owerride'; | |
| this.ext = ['scss', 'sass']; | |
| } | |
| SASSOwerridePlugin.prototype.toTree = function (tree, inputPath, outputPath, inputOptions) { | |
| tree = stew.rm(tree, `app/styles/config/themes/_current-theme.scss`); | |
| tree = stew.mv( | |
| tree, | |
| `app/styles/config/themes/_${themeName}.scss`, | |
| `app/styles/config/themes/_current-theme.scss` | |
| ); | |
| tree = stew.rm( | |
| tree, | |
| `${this.app.name}/styles/config/themes/_current-theme.scss` | |
| ); | |
| tree = stew.mv( | |
| tree, | |
| `${this.app.name}/styles/config/themes/_${themeName}.scss`, | |
| `${this.app.name}/styles/config/themes/_current-theme.scss` | |
| ); | |
| return sass.toTree(tree, inputPath, outputPath, inputOptions); | |
| }; | |
| registry.add('css', new SASSOwerridePlugin()); | |
| }, | |
| included() { | |
| this._super.included.apply(this, arguments); | |
| this._registers.forEach(([type, registry]) => { | |
| this.setupPreprocessorRegistry(type, registry, true); | |
| }); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment