Skip to content

Commit 080494c

Browse files
committed
🍕 Use dart-sass fallback for vueify sass compilation
When CLAYCLI_COMPILE_SCRIPTS_SKIP_STYLE_POSTCSS=true, compile vueify sass/scss blocks with the sass package so Browserify builds no longer fail on missing node-sass in staged rollout environments. Made-with: Cursor
1 parent a87f786 commit 080494c

1 file changed

Lines changed: 43 additions & 0 deletions

File tree

lib/cmd/compile/scripts.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,41 @@ function buildScripts(entries, options = {}) {
342342
babel: babelConfig
343343
};
344344

345+
function compileSassWithDartSass(source, cb, compiler, filePath) {
346+
let sass;
347+
const includePaths = [path.dirname(filePath)];
348+
349+
try {
350+
sass = require('sass');
351+
} catch (e) {
352+
cb(new Error('Sass styles require the "sass" package when CLAYCLI_COMPILE_SCRIPTS_SKIP_STYLE_POSTCSS=true'));
353+
return;
354+
}
355+
356+
try {
357+
const sassOptions = Object.assign({
358+
data: source,
359+
file: filePath,
360+
includePaths
361+
}, compiler.options.sass || {});
362+
363+
sassOptions.includePaths = sassOptions.includePaths
364+
? sassOptions.includePaths.concat(includePaths)
365+
: includePaths;
366+
367+
sass.render(sassOptions, (err, res) => {
368+
if (err) {
369+
cb(err);
370+
return;
371+
}
372+
373+
cb(null, res.css.toString());
374+
});
375+
} catch (e) {
376+
cb(e);
377+
}
378+
}
379+
345380
if (!skipVueStylePostcss) {
346381
vueifyTransformOptions.postcss = [
347382
cssImport(),
@@ -350,6 +385,14 @@ function buildScripts(entries, options = {}) {
350385
nested(),
351386
simpleVars()
352387
];
388+
} else {
389+
// Vueify's default sass/scss compiler requires node-sass.
390+
// During staged rollout we intentionally skip this postcss path and
391+
// compile sass/scss with dart-sass to avoid node-sass runtime failures.
392+
vueifyTransformOptions.customCompilers = {
393+
sass: compileSassWithDartSass,
394+
scss: compileSassWithDartSass
395+
};
353396
}
354397

355398
bundler.require(entries)

0 commit comments

Comments
 (0)