You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feature #517 Allow to use Dart Sass instead of Node Sass (Lyrkan, weaverryan)
This PR was merged into the master branch.
Discussion
----------
Allow to use Dart Sass instead of Node Sass
This PR closes#422 by allowing `sass` (Dart Sass) as an alternative choice to `node-sass`.
---
The `sass-loader` allows to set the implementation that should be used to process Sass files. It currently accepts either `sass` or `node-sass` (default):
In theory this can already be used by setting the related option when calling `Encore.enableSassLoader()`, but Encore then throws an error asking you to install `node-sass`, even if you already have `sass` installed.
One way to prevent that could be to detect when `options.implementation` is set but in its next version the `sass-loader` will [automatically detect](webpack-contrib/sass-loader@ff90dd6) which implementation is installed and use it accordingly.
So, instead of doing that, this PR allows to define alternative packages in our `feature.js` file, for instance:
```js
const features = {
sass: {
method: 'enableSassLoader()',
packages: [
{ name: 'sass-loader', enforce_version: true },
[{ name: 'node-sass' }, { name: 'sass' }] // Will allow both `node-sass` and `sass`
],
description: 'load Sass files'
},
// ...
}
```
If neither `node-sass` or `sass` is available, the error message will display both choices, and recommend the first one in the `yarn add` advice:

Note that for now using Dart Sass still requires the `implementation` option to be set:
```js
Encore.enableSassLoader(options => {
options.implementation = require('sass');
});
```
This shouldn't be a big issue since the default recommendation is still to use `node-sass`.
Commits
-------
4e90bf8 clarifying comment
1346ee5 Allow to use Dart Sass instead of Node Sass
`Webpack Encore requires version ${chalk.green(packageConfig.version)} of ${chalk.green(packageConfig.name)}. Your version ${chalk.green(version)} is too new. The related feature *may* still work properly. If you have issues, try downgrading the library, or upgrading Encore.`
116
-
);
155
+
];
117
156
}else{
118
-
badVersionMessages.push(
157
+
return[
119
158
`Webpack Encore requires version ${chalk.green(packageConfig.version)} of ${chalk.green(packageConfig.name)}, but your version (${chalk.green(version)}) is too old. The related feature will probably *not* work correctly.`
120
-
);
159
+
];
121
160
}
122
-
}
161
+
};
123
162
124
-
returnbadVersionMessages;
163
+
returnprocessPackagesConfig(packagesConfig);
125
164
}
126
165
127
166
functionaddPackagesVersionConstraint(packages){
128
167
constpackageJsonData=require('../package.json');
168
+
constaddConstraint=(packageData)=>{
169
+
if(Array.isArray(packageData)){
170
+
returnpackageData.map(addConstraint);
171
+
}
129
172
130
-
returnpackages.map(packageData=>{
131
173
constnewData=Object.assign({},packageData);
132
174
133
175
if(packageData.enforce_version){
@@ -143,7 +185,10 @@ function addPackagesVersionConstraint(packages) {
0 commit comments