vitejs / vite

Next generation frontend tooling. It's fast!
http://vitejs.dev
MIT License
65.17k stars 5.77k forks source link

Allow usage of sass-embedded instead of sass package #6734

Open TomTomB opened 2 years ago

TomTomB commented 2 years ago

Clear and concise description of the problem

Now that sass-embedded hit stable it would be nice to have it as an option for compiling sass/scss since it's a lot faster. Currently if you try to use it as a replacement for the sass package, you'll get the following error:

[vite] Internal server error: Preprocessor dependency "sass" not found. Did you install it?

Suggested solution

Add support for the sass-embedded package to be used instead of sass.

Alternative

No response

Additional context

No response

Validations

pbowyer commented 2 years ago

I tried aliasing the package:

npm i -D sass@npm:sass-embedded@latest

which resulted in errors:

vite v2.7.13 building for production...
✓ 36 modules transformed.
[vite:css] TypeError: Cannot read property 'url' of undefined
   ╷
14 │ @import '~material-design-icons-iconfont/src/material-design-icons';
   │         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   ╵
  assets\css\admin.scss 14:9  root stylesheet
file: D:/projects/example/assets/css/admin.scss
Error: TypeError: Cannot read property 'url' of undefined
   ╷
14 │ @import '~material-design-icons-iconfont/src/material-design-icons';
   │         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   ╵
  assets\css\admin.scss 14:9  root stylesheet
error during build:
Error: Error: TypeError: Cannot read property 'url' of undefined
   ╷
14 │ @import '~material-design-icons-iconfont/src/material-design-icons';
   │         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   ╵
  assets\css\admin.scss 14:9  root stylesheet
    at handleCompileResponse (D:\projects\example\node_modules\sass\dist\lib\src\compile.js:213:15)
    at compileRequestAsync (D:\projects\example\node_modules\sass\dist\lib\src\compile.js:101:16)
    at processTicksAndRejections (internal/process/task_queues.js:95:5)
danieka commented 2 years ago

@pbowyer @nex3 Webpack sass-loader seems to encounter the exact same error here: https://github.com/webpack-contrib/sass-loader/pull/1012#issuecomment-1025156034

ygj6 commented 2 years ago

FYI, I made a simple attempt to support SASS modern API #7170

Lucide commented 2 years ago

I'm having severe performance issues with sass (js) and carbon-components. Being able to choose the compiler implementation, like with common Svelte, Rollup pre-processing plugins would help a lot.

cawa-93 commented 1 year ago
npm i -D sass@npm:sass-embedded@latest

Actually works for me. One you may need configure paths

- @import "node_modules/bootstrap/scss/variables";
+ @import "../../node_modules/bootstrap/scss/variables";
sapphi-red commented 1 year ago

FYI there is a case when sass-embedded is slower than sass. These are the reasons: https://github.com/sass/sass/issues/3296, https://github.com/sass/embedded-host-node/issues/140#issuecomment-1124196534.

bluwy commented 1 year ago

We've discussed this in the last meeting, where the slower speed of sass-embedded in some cases makes it tricky for us to have builtin support for now. Until that's fix, we could probably revisit this again.

For now, you can use npm i -D sass@npm:sass-embedded@latest as recommended above to try it.

segevfiner commented 3 months ago

Maybe with this it will actually be faster instead: https://github.com/sass/dart-sass/blob/main/CHANGELOG.md#1700

nex3 commented 3 months ago

With the new compiler classes, Embedded Sass should be pretty much universally faster than the sass package if you're using it right.