generator-gulp-angular icon indicating copy to clipboard operation
generator-gulp-angular copied to clipboard

CSS / SCSS concatenation

Open danprime opened this issue 12 years ago • 2 comments

I used gulp-angular to seed the app but I have a moderately complex app structured in the following way where each state has its own scss/css file (to keep things modular):

├── src/ │ ├── app/ │ │ ├── state1/ │ │ │ ├── state1.controller.scss │ │ │ ├── state1.controller.js │ │ │ └── state1.html │ │ ├── state2/ │ │ │ ├── state2.controller.scss │ │ │ ├── state2.controller.js │ │ │ └── state2.html .... │ │ └── index.js │ │ └── index.(css|less|scss) │ │ └── vendor.(css|less|scss) │ ├── assets/ │ │ └── images/ │ └── index.html ....

I noticed that the styles task picks up the changes in the scss files but they're not concatenated into index.css (is this by intention? How do we refer to the compiled css files?)

I ended up trying to modify the build.js styles task like the following:

  1. Installing/Adding a dependency to gulp-concat https://www.npmjs.org/package/gulp-concat
  2. Modifying build.js styles task to the following:
gulp.task('styles', ['wiredep'],  function () {
  return gulp.src('src/{app,components}/**/*.scss')
    .pipe($.sass({style: 'expanded'}))
    .on('error', handleError)
    .pipe($.autoprefixer('last 1 version'))
    .pipe($.concat('app/index.css'))
    .pipe(gulp.dest('.tmp'))
    .pipe($.size());
});

This ends up overwriting index.css in the src and also eliminating vendor.css because it concatenates vendor.css with all the other files. Is there plans to concatenate CSS files? If not, did I structure things incorrectly?

danprime avatar Nov 15 '14 18:11 danprime

If your working with sass, you should include all your scss from one single app/index.scss and sass will automagically generate a single file.

In addition, the styles task is not responsible of the optimization / concatenation process. It's the html task which will concatenate files using gulp-useref.

Swiip avatar Nov 17 '14 16:11 Swiip

Thank you for the response. I made modifications to include all the scss and it now automatically generates the file I need. Thank you.

danprime avatar Nov 17 '14 17:11 danprime