express-dart-sass

raw JSON →
1.0.4 verified Sat Apr 25 auth: no javascript maintenance

Express middleware for dart-sass (the primary Sass implementation, now deprecated in favor of the new JS API). Version 1.0.4 is the latest stable release (last updated in 2021). It recompiles .scss/.sass files automatically for Express-based HTTP servers. Key differentiators: uses dart-sass (which is faster and more feature-complete than node-sass), supports legacy options like outputStyle, prefix, and error handling. The package is in maintenance mode due to the deprecation of the legacy JS API (LibSass/Node Sass) and the move to the new embedded dart-sass API.

error Error: Cannot find module 'sass'
cause The package depends on dart-sass (the `sass` npm package) which is not installed.
fix
npm install sass --save
error TypeError: sassMiddleware is not a function
cause CommonJS require returns an object with a default property when using ESM-style import in a CJS environment? Actually, the package exports a function directly, but if you use `import sassMiddleware from 'express-dart-sass'` in a TypeScript project with esModuleInterop: false, it may cause issues.
fix
Use const sassMiddleware = require('express-dart-sass') or enable esModuleInterop in tsconfig.
deprecated The dart-sass legacy JS API (used by this middleware) is deprecated in favor of the new compile() API.
fix Consider migrating to sass (dart-sass) direct integration or use the new compile API in your own middleware.
gotcha Middleware must be placed before express.static to serve compiled CSS.
fix Ensure app.use(sassMiddleware(...)) precedes app.use(express.static(...)).
gotcha The 'dest' option is required; if omitted, compiled files may overwrite source .scss files (since default is src).
fix Always specify dest or use response: true if you don't need file output.
npm install express-dart-sass
yarn add express-dart-sass
pnpm add express-dart-sass

Sets up express-dart-sass middleware to compile SCSS files from src to dest with compressed output, then serves static files.

const express = require('express');
const sassMiddleware = require('express-dart-sass');
const path = require('path');
const app = express();

app.use(sassMiddleware({
    src: __dirname,
    dest: path.join(__dirname, 'public'),
    debug: true,
    outputStyle: 'compressed',
    prefix: '/prefix'
}));

app.use(express.static(path.join(__dirname, 'public')));

app.listen(3000, () => console.log('Server running on port 3000'));