I
I
int22h2017-11-03 12:54:53
Node.js
int22h, 2017-11-03 12:54:53

Gulp doesn't run task after changes, why?

Used gulp+webpack+coffee.
Gulp is configured to watch coffee files for changes and compile them to js.
Problem after running watch.
If you make a mistake in the coffee file in the client/ folder, it will appear in the console and everything is fine.
But after fixing the error, the gulp.run 'client coffee' task does not run.
I work with all this stuff for the first time, so I still can’t figure out what’s wrong.
Actually the code itself:

coffee  = require 'gulp-coffee'
concat  = require 'gulp-concat'
gutil   = require 'gulp-util'
gulp = require 'gulp'
babel = require('gulp-babel')
webpack = require('webpack')
path = require('path')
watch = require 'gulp-watch'
shell = require('gulp-shell')

isProduction = gutil.env.production

build = (watch, callback) ->
  plugins = [ new (webpack.DefinePlugin)('process.env.NODE_ENV': JSON.stringify(if isProduction then 'production' else 'development')) ]
  if isProduction
    plugins.push new (webpack.optimize.UglifyJsPlugin)

  webpack 
    plugins: plugins
    cache: true
    watch: watch
    module: {
      loaders: [
        { test: /\.json$/, loader: 'json-loader' }
        { test: /\.js?$/, exclude: /node_modules/, loader: 'babel-loader' }       
        {
          test: /\.scss$/,
          use: [
            {
              loader: 'style-loader'
            }, 
            {
              loader: 'css-loader'
              #query: {
              #  modules: true,
              #  localIdentName: '[name]__[local]___[hash:base64:5]'
              #}
            },
            {
              loader: "sass-loader" 
            }
          ]        
        }
      ]
    },
    devtool: '#source-map'
    entry: path.resolve(__dirname, 'client/js/app-route.js')
    output:
      filename: 'app.js'
      path: path.resolve(__dirname, 'client/dist')
  , (err, stats) ->
    console.log "Error: #{ err}" if err?
    if callback
      callback()
    return
  return



gulp.task 'common coffee', ->
  gulp.src ['common/**/*.coffee'], {sourcemaps: true}
  .pipe coffee {bare: true}
  .pipe gulp.dest "common/"
  .on 'error', gutil.log

gulp.task 'generate api', shell.task 'lb export-api-def --json -o ./client/js/api.json'
  
gulp.task 'server coffee', ->  
  gulp.src 'server/**/*.coffee', {sourcemaps: true}
  .pipe coffee {bare: true}
  .pipe gulp.dest "server/"
  .on 'error', gutil.log
  

gulp.task 'client coffee', ->
  console.log "client coffee task"
  gulp.src 'client/**/*.coffee', {sourcemaps: false}
  .pipe(coffee({bare: true, coffee: require 'coffeescript'}).on('error', gutil.log))
  .pipe(babel({presets: ['env']}))
  .pipe gulp.dest "client/"
  .on 'error', gutil.log
  .on 'finish', ->
    gulp.run 'webpack build'
    
gulp.task 'webpack build', ->
  build false, ->
    console.log "Build returned"  
    
gulp.task 'default', ->
  gulp.run 'common coffee'
  gulp.run 'server coffee'
  gulp.run 'generate api'
  gulp.run 'client coffee'

gulp.task 'client', ->
  gulp.run 'client coffee'  

gulp.task 'watch', ->
  watch ['common/**/*.coffee', 'common/**/*.json'], ->
    gulp.run 'common coffee'
    gulp.run 'generate api'  
  watch 'server/**/*.coffee', ->
    gulp.run 'server coffee'
  watch 'client/admin/**/*.coffee', ->
    console.log "ADMIN PANEL CHANGED"
    gulp.run 'client coffee'
  watch ['client/js/**/*.coffee', "client/js/**/*.scss"], ->
    console.log "client changed"
    gulp.run 'client coffee'

Answer the question

In order to leave comments, you need to log in

2 answer(s)
C
cache0, 2017-11-03
@cache0

after errors, the task with the watch must be restarted

I
int22h, 2017-11-03
@int22h

found a solution here
https://gist.github.com/floatdrop/8269868
suddenly someone will need

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question