From 281b73251358a8e82f1b44f8f5671ded7db7e3f6 Mon Sep 17 00:00:00 2001 From: Paul Gschwendtner Date: Thu, 20 Apr 2017 13:20:53 +0200 Subject: [PATCH 1/2] build: dedupe theming scss bundle * Updates to a more recent version of SCSS-bundle that has support for deduping. The dedupe process is very naive and only disallows importing a file multiple times. * Switches to the programmatic API of `scss-bundle` * Removes unused functions and imports / leftovers. Fixes #3931 --- package.json | 2 +- tools/gulp/tasks/release.ts | 36 +++++++++++++----------------------- 2 files changed, 14 insertions(+), 24 deletions(-) diff --git a/package.json b/package.json index 5978d3a5b274..84e7aa091f74 100644 --- a/package.json +++ b/package.json @@ -106,7 +106,7 @@ "rollup": "^0.41.6", "run-sequence": "^1.2.2", "sass": "^0.5.0", - "scss-bundle": "^1.0.1", + "scss-bundle": "^2.0.1-beta.7", "selenium-webdriver": "^3.1.0", "sorcery": "^0.10.0", "stylelint": "^7.8.0", diff --git a/tools/gulp/tasks/release.ts b/tools/gulp/tasks/release.ts index 4674fbd65190..3432a410ef59 100644 --- a/tools/gulp/tasks/release.ts +++ b/tools/gulp/tasks/release.ts @@ -1,23 +1,18 @@ import {spawn} from 'child_process'; -import {existsSync, readFileSync, statSync, writeFileSync} from 'fs-extra'; -import {basename, join} from 'path'; +import {existsSync, statSync, writeFileSync} from 'fs-extra'; +import {join} from 'path'; import {dest, src, task} from 'gulp'; -import {inlineMetadataResources} from '../util/inline-resources'; -import {execNodeTask, execTask, sequenceTask} from '../util/task_helpers'; +import {execTask, sequenceTask} from '../util/task_helpers'; import {composeRelease} from '../util/package-build'; +import {Bundler} from 'scss-bundle'; import { COMPONENTS_DIR, - DIST_BUNDLES, DIST_MATERIAL, DIST_RELEASES, - DIST_ROOT, - LICENSE_BANNER, - PROJECT_ROOT, } from '../constants'; import * as minimist from 'minimist'; // There are no type definitions available for these imports. -const glob = require('glob'); const gulpRename = require('gulp-rename'); /** Parse command-line arguments for release task. */ @@ -32,6 +27,10 @@ const themingEntryPointPath = join(COMPONENTS_DIR, 'core', 'theming', '_all-them // Output path for the scss theming bundle. const themingBundlePath = join(releasePath, '_theming.scss'); +// Glob that matches all files that might be imported multiple times. +// Necessary for deduping inside of scss-bundle. +const themingBundleDedupeGlob = join(COMPONENTS_DIR, '**/*.scss'); + // Matches all pre-built theme css files const prebuiltThemeGlob = join(DIST_MATERIAL, '**/theming/prebuilt/*.css'); @@ -51,13 +50,11 @@ task(':package:theming', [':bundle:theming-scss'], () => { }); /** Bundles all scss requires for theming into a single scss file in the root of the package. */ -task(':bundle:theming-scss', execNodeTask( - 'scss-bundle', - 'scss-bundle', [ - '-e', themingEntryPointPath, - '-d', themingBundlePath - ], {silentStdout: true} -)); +task(':bundle:theming-scss', () => { + new Bundler().Bundle(themingEntryPointPath, [themingBundleDedupeGlob]).then(result => { + writeFileSync(themingBundlePath, result.bundledContent); + }); +}); /** Make sure we're logged in. */ task(':publish:whoami', execTask('npm', ['whoami'], { @@ -65,13 +62,6 @@ task(':publish:whoami', execTask('npm', ['whoami'], { errMessage: 'You must be logged in to publish.' })); -/** Create a typing file that links to the bundled definitions of NGC. */ -function createTypingFile() { - writeFileSync(join(releasePath, 'material.d.ts'), - LICENSE_BANNER + '\nexport * from "./typings/index";' - ); -} - task(':publish:logout', execTask('npm', ['logout'])); From d364b6e97dd67951f1949dd2082403f2e1bb3e69 Mon Sep 17 00:00:00 2001 From: Paul Gschwendtner Date: Thu, 20 Apr 2017 21:27:46 +0200 Subject: [PATCH 2/2] Address feedback --- tools/gulp/tasks/release.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/tools/gulp/tasks/release.ts b/tools/gulp/tasks/release.ts index 3432a410ef59..24eef8e6e066 100644 --- a/tools/gulp/tasks/release.ts +++ b/tools/gulp/tasks/release.ts @@ -27,9 +27,8 @@ const themingEntryPointPath = join(COMPONENTS_DIR, 'core', 'theming', '_all-them // Output path for the scss theming bundle. const themingBundlePath = join(releasePath, '_theming.scss'); -// Glob that matches all files that might be imported multiple times. -// Necessary for deduping inside of scss-bundle. -const themingBundleDedupeGlob = join(COMPONENTS_DIR, '**/*.scss'); +// Matches all SCSS files in the library. +const allScssGlob = join(COMPONENTS_DIR, '**/*.scss'); // Matches all pre-built theme css files const prebuiltThemeGlob = join(DIST_MATERIAL, '**/theming/prebuilt/*.css'); @@ -51,7 +50,10 @@ task(':package:theming', [':bundle:theming-scss'], () => { /** Bundles all scss requires for theming into a single scss file in the root of the package. */ task(':bundle:theming-scss', () => { - new Bundler().Bundle(themingEntryPointPath, [themingBundleDedupeGlob]).then(result => { + // 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. + new Bundler().Bundle(themingEntryPointPath, [allScssGlob]).then(result => { writeFileSync(themingBundlePath, result.bundledContent); }); });