【发布时间】:2017-06-21 15:22:04
【问题描述】:
我有一系列导出 JSON 的 JS 文件。我想只从每个文件中获取导出的 JSON,以便将其通过管道传输到另一个插件。如何访问流中每个文件的 module.exports?有这个插件吗?
示例 JS 文件:
let typographyFamilyFallback = 'Verdana, sans-serif';
let typographyFamily = 'Gotham, gotham, ' + typographyFamilyFallback;
let typographyFamilyFineprint = typographyFamily;
let typographyBaseSize = 15;
let typographyJSON = {
typographyFamilyFallback,
typographyFamily,
typographyFamilyFineprint,
typographyBaseSize
};
module.exports = typographyJSON;
gulpfile.js:
const gulp = require('gulp');
const jsonCss = require('gulp-json-css');
gulp.task('generate-less-vars', function() {
return gulp
.src(['./src/variables/*.js'])
// Get the module.export and convert to json for the next piped task.
.pipe(jsonCss({targetPre: 'less'}))
.pipe(gulp.dest('target/static-zsg/zsg/variables/'));
});
【问题讨论】:
标签: javascript json node.js gulp