-
Notifications
You must be signed in to change notification settings - Fork 380
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
Lazily require node-sass #748
Changes from all commits
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 |
---|---|---|
|
@@ -118,6 +118,9 @@ const gulpSass = (options, sync) => through.obj((file, enc, cb) => { // eslint-d | |
return cb(new PluginError(PLUGIN_NAME, error)); | ||
}; | ||
|
||
// eslint-disable-next-line global-require, import/no-extraneous-dependencies | ||
const compiler = gulpSass.compiler || require('node-sass'); | ||
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. Should not this be auto-detection? let compiler = gulpSass.compiler;
if (!compiler) {
try {
compiler = require('node-sass');
} catch (e) {
try {
compiler = require('sass');
} catch (e) {
return cb(new PluginError(
PLUGIN_NAME,
"No compiler found!\nPlease install one of the npm packages: node-sass or sass, or set compiler in code:\n const sass = require('gulp-sass');\n sass.compiler = require('sass');\n"
));
}
}
} So that user don't need to set dart-sass by hand. For reference, webpack's sass-loader does this kind of auto-detection. 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. That makes a lot of sense, however I'm not in a position to fix this at the moment. |
||
|
||
if (sync !== true) { | ||
////////////////////////////// | ||
// Async Sass render | ||
|
@@ -129,13 +132,13 @@ const gulpSass = (options, sync) => through.obj((file, enc, cb) => { // eslint-d | |
filePush(obj); | ||
}; | ||
|
||
gulpSass.compiler.render(opts, callback); | ||
compiler.render(opts, callback); | ||
} else { | ||
////////////////////////////// | ||
// Sync Sass render | ||
////////////////////////////// | ||
try { | ||
filePush(gulpSass.compiler.renderSync(opts)); | ||
filePush(compiler.renderSync(opts)); | ||
} catch (error) { | ||
return errorM(error); | ||
} | ||
|
@@ -157,8 +160,8 @@ gulpSass.logError = function logError(error) { | |
}; | ||
|
||
////////////////////////////// | ||
// Store compiler in a prop | ||
// Store compiler in a prop (node-sass is dynamically required if needed) | ||
////////////////////////////// | ||
gulpSass.compiler = require('node-sass'); | ||
gulpSass.compiler = null; | ||
|
||
module.exports = gulpSass; |
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.
Thoughts on changing this to:
This way, users can copy the one-liner they prefer?
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.
I think that makes sense. Perhaps we should also add some additional information on the differences?