-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[UI Framework] Spawn compileCss as a child process to prevent a node-sass fatal error from killing the watch process #13222
Changes from 2 commits
847cc25
6c50b8f
4f75e7f
ea7e67e
98055bf
6c87d76
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,6 +44,11 @@ module.exports = function (grunt) { | |
Promise.all([uiFrameworkWatch(), uiFrameworkServerStart()]).then(done); | ||
}); | ||
|
||
grunt.registerTask('uiFramework:compileCss', function () { | ||
const done = this.async(); | ||
uiFrameworkCompile().then(done); | ||
}); | ||
|
||
function uiFrameworkServerStart() { | ||
const serverCmd = { | ||
cmd: isPlatformWindows ? '.\\node_modules\\.bin\\webpack-dev-server.cmd' : './node_modules/.bin/webpack-dev-server', | ||
|
@@ -77,27 +82,47 @@ module.exports = function (grunt) { | |
} | ||
|
||
function uiFrameworkCompile() { | ||
sass.render({ | ||
file: 'ui_framework/components/index.scss' | ||
}, function (error, result) { | ||
if (error) { | ||
grunt.log.error(error); | ||
} | ||
|
||
postcss([postcssConfig]) | ||
.process(result.css, { from: 'ui_framework/components/index.scss', to: 'ui_framework/dist/ui_framework.css' }) | ||
.then(result => { | ||
grunt.file.write('ui_framework/dist/ui_framework.css', result.css); | ||
|
||
if (result.map) { | ||
grunt.file.write('ui_framework/dist/ui_framework.css.map', result.map); | ||
} | ||
}); | ||
return new Promise(resolve => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you show me what you mean? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thinking something like this:
|
||
sass.render({ | ||
file: 'ui_framework/components/index.scss' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can use |
||
}, function (error, result) { | ||
if (error) { | ||
grunt.log.error(error); | ||
} | ||
|
||
postcss([postcssConfig]) | ||
.process(result.css, { from: 'ui_framework/components/index.scss', to: 'ui_framework/dist/ui_framework.css' }) | ||
.then(result => { | ||
grunt.file.write('ui_framework/dist/ui_framework.css', result.css); | ||
|
||
if (result.map) { | ||
grunt.file.write('ui_framework/dist/ui_framework.css.map', result.map); | ||
} | ||
|
||
resolve(); | ||
}); | ||
}); | ||
}); | ||
} | ||
|
||
function uiFrameworkWatch() { | ||
const debouncedCompile = debounce(uiFrameworkCompile, 400, { leading: true }); | ||
const debouncedCompile = debounce(() => { | ||
// Compile the SCSS in a separate process because node-sass throws a fatal error if it fails | ||
// to compile. | ||
grunt.util.spawn({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you wanted to use a promise here you could as well, but I feel the callback is fine if you want to leave it.
|
||
cmd: 'npm', | ||
args: [ | ||
'run', | ||
'uiFramework:compileCss', | ||
], | ||
}, (error, result) => { | ||
if (error) { | ||
grunt.log.error(result.stdout); | ||
} else { | ||
grunt.log.writeln(result); | ||
} | ||
}); | ||
}, 400, { leading: true }); | ||
|
||
return new Promise(() => { | ||
debouncedCompile(); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Expanding on our conversation here. When would someone need to manually compile the CSS? I can understand creating a grunt task for it, but not sure it warrants an aliased npm task.