Skip to content

Commit

Permalink
feat(build): speed-up stylesheet building
Browse files Browse the repository at this point in the history
  • Loading branch information
pimenovoleg committed Aug 1, 2018
1 parent a4956a1 commit f60dcbb
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 32 deletions.
9 changes: 5 additions & 4 deletions tools/gulp/tasks/mosaic-release.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ const {sourceDir, outputDir} = mosaicPackage;
/** Path to the directory where all releases are created. */
const releasesDir = join(distDir, 'releases');

// Matches all SCSS files in the different packages.
const allScssGlob = join(buildConfig.packagesDir, '**/*.scss');
// Matches all SCSS files in the different packages. Note that this glob is not used to build
// the bundle. It's used to identify Sass files that shouldn't be included multiple times.
const allScssDedupeGlob = join(buildConfig.packagesDir, '**/*.scss');


// Path to the release output of mosaic.
Expand Down Expand Up @@ -55,7 +56,7 @@ task('mosaic:bundle-theming-scss', () => {
// Instantiates the SCSS bundler and bundles all imports of the specified entry point SCSS file.
// A glob of all SCSS files in the library will be passed to the bundler. The bundler takes an
// array of globs, which will match SCSS files that will be only included once in the bundle.
return new Bundler().Bundle(themingEntryPointPath, [allScssGlob]).then((result) => {
return new Bundler().Bundle(themingEntryPointPath, [allScssDedupeGlob]).then((result) => {
// The release directory is not created yet because the composing of the release happens when
// this task finishes.
mkdirpSync(releasePath);
Expand All @@ -74,7 +75,7 @@ task('mosaic:bundle-visual-scss', () => {
// Instantiates the SCSS bundler and bundles all imports of the specified entry point SCSS file.
// A glob of all SCSS files in the library will be passed to the bundler. The bundler takes an
// array of globs, which will match SCSS files that will be only included once in the bundle.
return new Bundler().Bundle(visualEntryPointPath, [allScssGlob]).then((result) => {
return new Bundler().Bundle(visualEntryPointPath, [allScssDedupeGlob]).then((result) => {
// The release directory is not created yet because the composing of the release happens when
// this task finishes.
mkdirpSync(releasePath);
Expand Down
15 changes: 15 additions & 0 deletions tools/packages/gulp/build-scss-pipeline.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { src } from 'gulp';
import { join } from 'path';


/* tslint:disable:no-var-requires */
const gulpSass = require('gulp-sass');
const gulpIf = require('gulp-if');
const gulpCleanCss = require('gulp-clean-css');
/* tslint:enable:no-var-requires */

export function buildScssPipeline(sourceDir: string, minifyOutput = false) {
return src(join(sourceDir, '**/*.scss'))
.pipe(gulpSass().on('error', gulpSass.logError))
.pipe(gulpIf(minifyOutput, gulpCleanCss()));
}
18 changes: 0 additions & 18 deletions tools/packages/gulp/build-scss-task.ts

This file was deleted.

16 changes: 7 additions & 9 deletions tools/packages/gulp/build-tasks-gulp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { inlineResourcesForDirectory } from '../inline-resources';

import { composeRelease } from '../build-release';

import { buildScssTask } from './build-scss-task';
import { buildScssPipeline } from './build-scss-pipeline';
import { sequenceTask } from './sequence-task';


Expand All @@ -29,7 +29,7 @@ export function createPackageBuildTasks(buildPackage: BuildPackage, preBuildTask
const dependencyNames = buildPackage.dependencies.map((p) => p.name);

// Glob that matches all style files that need to be copied to the package output.
const stylesGlob = join(buildPackage.sourceDir, '**/*.+(scss|css)');
const stylesGlob = join(buildPackage.sourceDir, '**/*.css');

// Glob that matches every HTML file in the current package.
const htmlGlob = join(buildPackage.sourceDir, '**/*.html');
Expand Down Expand Up @@ -68,17 +68,15 @@ export function createPackageBuildTasks(buildPackage: BuildPackage, preBuildTask

task(`${taskName}:assets`, [
`${taskName}:assets:scss`,
`${taskName}:assets:es5-scss`,
`${taskName}:assets:copy-styles`,
`${taskName}:assets:html`
]);

task(`${taskName}:assets:scss`, buildScssTask(
buildPackage.outputDir, buildPackage.sourceDir, true)
);

task(`${taskName}:assets:es5-scss`, buildScssTask(
buildPackage.esm5OutputDir, buildPackage.sourceDir, true)
task(`${taskName}:assets:scss`, () => {
buildScssPipeline(buildPackage.sourceDir, true)
.pipe(dest(buildPackage.outputDir))
.pipe(dest(buildPackage.esm5OutputDir));
}
);

task(`${taskName}:assets:copy-styles`, () => {
Expand Down
2 changes: 1 addition & 1 deletion tools/packages/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ export * from './copy-files';


export * from './gulp/build-tasks-gulp';
export * from './gulp/build-scss-task';
export * from './gulp/build-scss-pipeline';
export * from './gulp/sequence-task';

0 comments on commit f60dcbb

Please sign in to comment.