Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to use Dart Sass command line version with web pack?

From the dart-sass documentation we see that the dart-sass has a command-line version and is more performant.

I want to know if we can somehow use that command-line version with the existing webpack set up to speed up our build-time performance.

I can install dart libraries in the build machine. But is there any webpack plugin which can leverage that and use the machine dependencies to build sass rather than dart-sass npm?

like image 893
AnandShiva Avatar asked May 17 '21 11:05

AnandShiva


People also ask

How do you use Dart Sass in Webpack?

For example, to use Dart Sass, you'd pass: module. exports = { module: { rules: [ { test: /\. s[ac]ss$/i, use: [ "style-loader", "css-loader", { loader: "sass-loader", options: { // Prefer `dart-sass` implementation: require.

Is Dart Sass the same as Sass?

Dart Sass is the primary implementation of Sass, which means it gets new features before any other implementation. It's fast, easy to install, and it compiles to pure JavaScript which makes it easy to integrate into modern web development workflows. Find out more or help out with its development on GitHub.


Video Answer


1 Answers

It seems as though the dart-sass team is working to support this case (see this issue). But the work isn't finished.

But is there any webpack plugin which can leverage that and use the machine dependencies to build sass rather than dart-sass npm?

Not that I can find. However, it would be possible to create your own loader which uses the dart executable (the source for sass-loader is a good point of reference, and not very complicated). Since the dart cli takes options to read from stdin (sass --stdin), you should be able to pipe to the cli and pass back the output.

There might be other ways to accomplish your aim with a webpack extension, but using a loader seems the most straightforward in my view.

Is this faster than using the js api that sass-loader uses? Well, according to the benchmarks, the advantage of the executable varies between 1.7 and 4.1 times faster (excluding the simplest case in which the executable runs 24 times faster, but is still sub-second execution for all cases). But there will be overhead for process generation, so you would have to measure to see what is faster in your case.

like image 198
msmith Avatar answered Oct 19 '22 22:10

msmith