Skip to content

Commit 03a8e0d

Browse files
fix: improved sass watcher
1 parent 917ecaa commit 03a8e0d

File tree

1 file changed

+21
-13
lines changed

1 file changed

+21
-13
lines changed

src/commands/serve.ts

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import {
1010
EnvPlugin,
1111
WebIndexPlugin
1212
} from 'fuse-box'
13-
import { exec, task, watch } from 'fuse-box/sparky'
1413
import { resolve } from 'path'
1514
import { NgProdPlugin } from '../fusebox/ng.prod.plugin'
1615
import { NgPolyfillPlugin } from '../fusebox/ng.polyfill.plugin'
@@ -20,8 +19,8 @@ import { NgAotFactoryPlugin } from '../fusebox/ng.aot-factory.plugin'
2019
import { main as ngc } from '@angular/compiler-cli/src/main'
2120
import { CompressionPlugin } from '../fusebox/compression.plugin'
2221
import { appEnvironmentVariables } from '../utilities/environment-variables'
23-
import { renderSingleSass, renderSassDir } from '../utilities/sass'
24-
import { SparkyFile } from 'fuse-box/sparky/SparkyFile'
22+
import { renderSassDir } from '../utilities/sass'
23+
import { exec } from 'child_process'
2524
import clearTerminal from '../utilities/clear'
2625
import readConfig_ from '../utilities/read-config'
2726

@@ -66,7 +65,7 @@ function serve(isProdBuild = false) {
6665
const serverOutput = resolve(config.fusebox.server.outputDir)
6766
const browserOutput = resolve(config.fusebox.browser.outputDir)
6867
const modulesFolder = resolve(process.cwd(), 'node_modules')
69-
const watchDir = `${homeDir}/src/**`
68+
const watchDir = resolve(`${homeDir}/src/**`)
7069
const browserModule = isAotBuild
7170
? config.fusebox.browser.aotBrowserModule
7271
: config.fusebox.browser.browserModule
@@ -181,17 +180,26 @@ function serve(isProdBuild = false) {
181180
.instructions(` !> [${browserModule}]`)
182181
.splitConfig({ dest: '../js/modules' })
183182

184-
task('scss.watch', () =>
185-
watch('src/**/**.*').file('*.scss', (f: SparkyFile) => {
186-
f.homePath && renderSingleSass(f.homePath)
187-
})
188-
)
189-
190-
exec('scss.watch')
191-
192183
logInfo('Bundling your application, this may take some time...')
193184

194185
renderSassDir()
195-
fuseBrowser.run({ chokidar: { ignored: /.scss/g } })
186+
187+
const sass = exec(
188+
'node_modules/.bin/node-sass --watch src/**/*.scss --output-style compressed --output src/**'
189+
)
190+
sass.on('error', err => {
191+
console.log(err)
192+
process.exit(1)
193+
})
194+
sass.on('message', err => {
195+
console.error(err)
196+
process.exit(1)
197+
})
198+
sass.stderr.on('data', err => {
199+
console.log(err)
200+
process.exit(1)
201+
})
202+
203+
fuseBrowser.run({ chokidar: { ignored: /^(.*\.scss$)*$/gim } })
196204
})
197205
}

0 commit comments

Comments
 (0)