Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Load JSON and listen to changes? #179

Open
frankandrobot opened this issue Apr 2, 2020 · 3 comments
Open

Load JSON and listen to changes? #179

frankandrobot opened this issue Apr 2, 2020 · 3 comments
Labels
question Further information is requested

Comments

@frankandrobot
Copy link

I create a PUG that loads a JSON file. The problem is that relaxedjs does not update when I make changes to this file.

Here's the PUG that loads a JSON file:

-
  const fs = require('fs');
  const data = JSON.parse(fs.readFileSync("./my.json"));
 
section
   p  #{data.foo} 

when I make changes to my.json, the console reports No process defined for file /my.json. and does NOT rebuild the document.

@DanielRuf
Copy link
Contributor

Hi @frankandrobot

const data = JSON.parse(fs.readFileSync("./my.json"));

This reads only once in NodeJS.

@DanielRuf
Copy link
Contributor

The file watching should work when you use the relaxed binary. When you use it as Node module you have to adjust your code.

https://github.com/RelaxedJS/ReLaXed/tree/master/test/samples/pug/data_require

https://github.com/RelaxedJS/ReLaXed/blob/master/README.md#getting-started

@DanielRuf DanielRuf added the question Further information is requested label Apr 2, 2020
@frankandrobot
Copy link
Author

frankandrobot commented Apr 3, 2020

Still not working... The problem is that it still reads the file fine on load but then does not scan for changes. If you make a change to file.json, it still says No process defined for file /file.json. What version of relaxed does this apply to?

npx relaxed file.pug -t ./ 
-
  const path = require('path');
  const data = require(path.join(basedir, 'file.json'));

section
   p  #{data.foo} 

UPDATE: upgraded to latest 0.2.4 and still seeing the same behavior, node version = 8.15.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants