R
R
rapkin2015-03-06 00:38:16
JavaScript
rapkin, 2015-03-06 00:38:16

How to reload json config when restarting a task in Gulp?

The ./res/lvl_1.json file contains some configuration that needs to be processed, and the result of processing is sent as a local variable to the jade template. Configured to restart the jade task when changing in the config.
The problem is that restarting the task and recompiling the jade template is successful, but the changes made to the configuration file are not picked up.
For example, in the ./res/lvl_1.json file there is a width field, when I change it, the task is restarted and the page is reloaded, but there were no changes on the page. And when you restart gulp, all the changes are there.

gulp.task 'jade', ->
  lvl = require './res/lvl_1.json'
  console.log lvl.width # выводит одно и то же число, хотя я его изменяю
  gulp.src 'jade/index.jade'
    .pipe jade
      pretty: true
      locals:
        game_file: game_file
        barrier: make_barrier(lvl.barrier)
        width: lvl.width
        height: lvl.height

    .pipe gulp.dest 'dist'
    .pipe livereload()

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
rapkin, 2015-03-06
@rapkin

Instead I
wrote
and started.
I hope this is useful to someone

A
Andrey, 2015-03-06
@standy

You can remove the required module from require.cache , this will cause it to be reloaded the next time you connect.
The problem can be solved even easier, upload the file manually, for example, fromfs.readFile

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question