3

I've some problems with adding bootstrap to my node project. I installed bootstrap-sass-official via bower then I added gulp task for compiling bootstrap.

I ran task which compiles bootstrap directly from a console and it was finished successfully. My gulpfile.coffee

gulp = require 'gulp'
$ = (require 'gulp-load-plugins')()
livereload = require 'gulp-livereload'
nodemon = require 'gulp-nodemon'
concat = require 'gulp-concat'
express = require 'express'
path = require 'path'
sass = require 'gulp-ruby-sass'
app = express()

gulp.task 'bootstrap-sass', =>
  gulp.src './bower_components/bootstrap-sass-official/assets/stylesheets/**/*.scss'
  .pipe $.plumber()
  .pipe $.sass({
    outputStyle: 'compressed'
    sourceComments: 'map'
    includePaths : ['./bower_components/bootstrap-sass-official/assets/stylesheets']
  })
  .on 'error', (err) =>
    console.log err
  .pipe gulp.dest 'dist/stylesheets/bootstrap'


gulp.task 'compass', =>
  gulp.src './src/stylesheets/*.sass'
  .pipe $.plumber()
  .pipe $.compass {
    css: 'dist/stylesheets'
    sass: 'src/stylesheets'
  }
  .pipe gulp.dest 'dist/stylesheets'
#  .pipe livereload()


gulp.task 'coffee', =>
  gulp.src 'src/scripts/main.coffee', {read: false}
  .pipe $.plumber()
  .pipe $.browserify {
    debug: true
    insertGlobals: false
    transform: ['coffeeify']
    extensions: ['.coffee']
  }
  .pipe $.rename 'app.js'
  .pipe gulp.dest 'dist/scripts'
  .pipe livereload()


gulp.task 'images', =>
  gulp.src './src/images/**/*'
  .pipe gulp.dest './dist/images/'
  .pipe livereload()

gulp.task 'templates', =>
  gulp.src 'src/*.jade'
  .pipe $.plumber()
  .pipe $.jade {
    pretty: true
  }
  .pipe gulp.dest 'dist/'
  .pipe livereload()

gulp.task 'express', =>
  app.use express.static(path.resolve './dist')
  app.listen 1337
  $.util.log 'Listening on port: 1337'

gulp.task 'watch', =>
  livereload.listen()
  gulp.watch 'src/stylesheets/*.sass', ['compass']
  gulp.watch 'src/scripts/*.coffee', ['coffee']
  gulp.watch 'src/*.jade', ['templates']
  gulp.watch './src/images/**/*', ['images']
  $.notify {message: "Reload"}


gulp.task 'default', ['images', 'watch', 'express', 'demon']
gulp.task 'demon', =>
  nodemon {
    script: 'dist/scripts/app.js'
    env: {'NODE_ENV': 'development'}
    nodeArgs: ['--debug=9999']
  }

Have you some idea how to solve this problem ?

BILL
  • 4,711
  • 10
  • 57
  • 96

1 Answers1

2

Instead of using gulp to include **/*.scss from bootstrap-sass, create an SCSS file that "imports" the bootstrap-sass files via @import statements.

It's important to do it this way, because there's actually an order in which the bootstrap-sass files need to be included, and you can control that order by using the @import statements.

For example, here's an example of how to do this. Notice that app.scss is the single file that includes everything else; app.scss becomes the only thing that Gulp needs to process.

Then your gulp command would do this:

gulp.src './app.scss'
  .pipe blah blah sass stuff
  .pipe gulp.dest 'dist/stylesheets/'

FWIW, the Gulp task that I use to process SCSS is the styles:scss task here.

Chris Clark
  • 1,439
  • 2
  • 17
  • 25
  • Very good solution! I wants to know how do you work with the bootstrap `/fonts/` and `/js/` when using bower. Can you tell me, please? – Vinicius Garcia Jun 29 '17 at 18:48