Convert js format to json format, mainly because line breaks in json format are cumbersome
npm install --save-dev gulp-js2json
Transform example.css
:
xxxxxx //Some logical processing
module.exports = {
title:"example",
content:`A long long long long long long long long and
broken paragraph`,
content2:'A long long long long long long long long and'+
'non-breaking paragraph'
}
Into example.json
:
{
"title":"example",
"content":"A long long long long long long long long and\n broken paragraph",
"content2":"A long long long long long long long long andnon-breaking paragraph"
}
Using gulpfile.js
:
var gulp = require('gulp');
var file2json = require('gulp-js2json');
gulp.task('js-json', function () {
return gulp.src('example/example.js')
.pipe(js2json())
.pipe(gulp.dest('example'));
});
Inspired by gulp-file-to-json (Gulp plugin to convert a file and its MD5 hash value into a JSON representation,Obviously, I just copied this project and modified a few lines of code.).
MIT © 2016 Vast.com, Inc.