|
| 1 | +// Copyright 2015 Google Inc. |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +/** |
| 16 | + * @fileoverview Gulp tasks for processing stylesheets. |
| 17 | + */ |
| 18 | +import browserSync from 'browser-sync'; |
| 19 | +import gulp from 'gulp'; |
| 20 | +import gulpAutoprefixer from 'gulp-autoprefixer'; |
| 21 | +import gulpFilter from 'gulp-filter'; |
| 22 | +import gulpMinifyCss from 'gulp-minify-css'; |
| 23 | +import gulpSourcemaps from 'gulp-sourcemaps'; |
| 24 | +import gulpSass from 'gulp-sass'; |
| 25 | +import path from 'path'; |
| 26 | +import gulpConcat from 'gulp-concat'; |
| 27 | + |
| 28 | +import conf from './conf'; |
| 29 | + |
| 30 | + |
| 31 | +/** |
| 32 | + * Compiles stylesheets and places them into the serve folder. Each stylesheet file is compiled |
| 33 | + * separately. |
| 34 | + */ |
| 35 | +gulp.task('styles', function () { |
| 36 | + let sassOptions = { |
| 37 | + style: 'expanded' |
| 38 | + }; |
| 39 | + |
| 40 | + let cssFilter = gulpFilter('**/*.css', { restore: true }); |
| 41 | + |
| 42 | + return gulp.src(path.join(conf.paths.frontendSrc, '**/*.scss')) |
| 43 | + .pipe(gulpSass(sassOptions)) |
| 44 | + .pipe(cssFilter) |
| 45 | + .pipe(gulpSourcemaps.init({ loadMaps: true })) |
| 46 | + .pipe(gulpAutoprefixer()) |
| 47 | + .pipe(gulpSourcemaps.write()) |
| 48 | + .pipe(cssFilter.restore) |
| 49 | + .pipe(gulp.dest(conf.paths.serve)) |
| 50 | + // If BrowserSync is running, inform it that styles have changed. |
| 51 | + .pipe(browserSync.stream()); |
| 52 | +}); |
| 53 | + |
| 54 | + |
| 55 | +/** |
| 56 | + * Compiles stylesheets and places them into the prod tmp folder. Styles are compiled and minified |
| 57 | + * into a single file. |
| 58 | + */ |
| 59 | +gulp.task('styles:prod', function () { |
| 60 | + let sassOptions = { |
| 61 | + style: 'compressed' |
| 62 | + }; |
| 63 | + |
| 64 | + return gulp.src(path.join(conf.paths.frontendSrc, '**/*.scss')) |
| 65 | + .pipe(gulpSass(sassOptions)) |
| 66 | + .pipe(gulpAutoprefixer()) |
| 67 | + .pipe(gulpConcat('app.css')) |
| 68 | + .pipe(gulpMinifyCss()) |
| 69 | + .pipe(gulp.dest(conf.paths.prodTmp)) |
| 70 | +}); |
0 commit comments