coffeescript - 如何用 gulp 编译 bootstrap-sass?

标签 coffeescript bootstrap-sass gulp-sass

我在将 Bootstrap 添加到我的节点项目时遇到了一些问题。 我通过 bower 安装了 bootstrap-sass-official,然后我添加了 gulp 任务来编译 bootstrap。

我运行了直接从控制台编译 bootstrap 的任务并成功完成。 我的 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']
  }

你知道如何解决这个问题吗?

最佳答案

不是使用 gulp 从 bootstrap-sass 中包含 **/*.scss,而是创建一个“导入”bootstrap-sass< 的 SCSS 文件 文件通过 @import 语句。

这样做很重要,因为实际上需要包含 bootstrap-sass 文件的顺序,您可以使用 @import< 控制该顺序 语句。

例如,here's如何做到这一点的例子。请注意,app.scss 是包含其他所有内容的单个文件; app.scss 成为 Gulp 唯一需要处理的东西。

然后你的 gulp 命令会这样做:

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

FWIW,我用来处理 SCSS 的 Gulp 任务是 styles:scss 任务 here .

关于coffeescript - 如何用 gulp 编译 bootstrap-sass?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26815089/

相关文章:

javascript - gulp-sass @import CSS 文件

javascript - 模板事件未在 Meteor 中触发

javascript - Backbone View 事件在父 View 重新渲染时失去委托(delegate)

angularjs - Protractor 从 Promise 返回一个值

ruby-on-rails - 如何在 Rails 应用程序中使用 twitter bootstrap 和 bootstrap-sass?

javascript - 无法覆盖 SASS !默认变量?

javascript - PassportJS 重定向循环

css - 如何处理 bootstrap-sass 和 compass 中的字体?如何在页面上正确包含字体?

css - 如何配置 Cakephp 和 Bootstrap-sass?

node.js - 找不到模块 "lodash"