Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify style compiler code (scss) #13168

Merged
merged 1 commit into from
May 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion build/gulp/gulp-data-uri.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
const replace = require('gulp-replace');
const path = require('path');
const fs = require('fs');
const sass = require('sass');
const dataUriRegex = /data-uri\((?:'(image\/svg\+xml;charset=UTF-8)',\s)?['"]?([^)'"]+)['"]?\)/g;

const svg = (buffer, svgEncoding) => {
Expand All @@ -26,7 +27,18 @@ const handler = (_, svgEncoding, fileName) => {
return `url(${escapedString})`;
};

const sassFunction = (args) => {
const hasEncoding = args.getLength() === 2;
const encoding = hasEncoding ? args.getValue(0).getValue() : null;
const url = hasEncoding ? args.getValue(1).getValue() : args.getValue(0).getValue();

return new sass.types.String(handler(null, encoding, url));
};

module.exports = {
gulpPipe: () => replace(dataUriRegex, handler),
resolveDataUri: (content) => content.replace(dataUriRegex, handler)
resolveDataUri: (content) => content.replace(dataUriRegex, handler),
sassFunctions: {
'data-uri($args...)': sassFunction
}
};
45 changes: 15 additions & 30 deletions build/gulp/scss/compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,43 +2,28 @@

const sass = require('gulp-dart-sass');
const gulp = require('gulp');
const del = require('del');
const config = require('./config');
const dataUri = require('../gulp-data-uri').gulpPipe;
const functions = require('../gulp-data-uri').sassFunctions;
const cleanCss = require('gulp-clean-css');
const autoPrefix = require('gulp-autoprefixer');
const cleanCssOptions = require('../../../themebuilder/modules/clean-css-options');
const fiber = require('fibers');

const outputPath = config.outputPath;
const tmpPath = `${outputPath}/tmp`;

function compileBundle(bundleName) {
return gulp.src(bundleName)
.pipe(sass())
function compile() {
return gulp.src([
'scss/bundles/*',
'!scss/bundles/dx.ios7.default.scss'
])
.pipe(sass({
fiber,
functions
}).on('error', sass.logError))
.pipe(autoPrefix())
.pipe(cleanCss(cleanCssOptions))
.pipe(gulp.dest('artifacts/scss-css'));
}

function processDataUri() {
return gulp.src(`${outputPath}/**/*`)
.pipe(dataUri())
.pipe(gulp.dest(tmpPath));
}

function compile() {
return compileBundle([
`${tmpPath}/bundles/*`,
`!${tmpPath}/bundles/dx.ios7.default.scss`
]);
}

function clean() {
return del(`${tmpPath}`);
}
gulp.task('compile-scss', compile);

gulp.task('compile-scss', gulp.series(
processDataUri,
compile,
clean
));
gulp.task('compile-scss:watch', () => {
gulp.watch('scss/**/*.scss', compile);
});
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
"eslint-plugin-qunit": "^4.0.0",
"eslint-plugin-spellcheck": "0.0.11",
"exceljs": "3.3.1",
"fibers": "^5.0.0",
"globalize": "^1.3.0",
"gulp": "^4.0.2",
"gulp-autoprefixer": "^7.0.1",
Expand Down Expand Up @@ -109,6 +110,7 @@
"pre-commit": "^1.2.2",
"qunitjs": "^2.0.1",
"run-sequence": "^1.1.5",
"sass": "^1.26.5",
"shelljs": "^0.8.3",
"string-replace-loader": "^2.1.1",
"stylelint": "^13.1.0",
Expand Down