[removed] get package.json data in gulpfile.js

前端 未结 4 1227
时光说笑
时光说笑 2020-12-07 19:44

Not a gulp-specific question per-se, but how would one get info from the package.json file within the gulpfile.js; For instance, I want to get the homepage or the name and u

4条回答
  •  感情败类
    2020-12-07 20:08

    Don't use require('./package.json') for a watch process, as using require will resolve the module as the results of the first request.

    So if you are editing your package.json those edits won't work unless you stop your watch process and restart it.

    For a gulp watch process it would be best to re-read the file and parse it each time that your task is executed, by using node's fs method

    var fs = require('fs')
    var json = JSON.parse(fs.readFileSync('./package.json'))
    

提交回复
热议问题