2017-03-27 19:34:02 +00:00
|
|
|
const fs = require('fs');
|
2017-03-22 22:13:37 +00:00
|
|
|
module.exports = function (gulp, plugins, config, env) {
|
|
|
|
return function html() {
|
|
|
|
return gulp.src(env.production() ? config.build + '/*.html' : 'html/*.html')
|
|
|
|
.pipe(plugins.inject(gulp.src(['config.json']), {
|
|
|
|
starttag: '<!-- inject:config -->',
|
2017-03-29 22:21:41 +00:00
|
|
|
transform: function (filePath, customConfig) {
|
|
|
|
var defaultConfig = fs.readFileSync('config.default.json', 'utf8');
|
|
|
|
var buildConfig = Object.assign(
|
|
|
|
JSON.parse(JSON.minify(defaultConfig)),
|
|
|
|
JSON.parse(JSON.minify(customConfig.contents.toString('utf8')))
|
|
|
|
);
|
2017-03-22 22:13:37 +00:00
|
|
|
return '<script>var jsonData =' +
|
2017-03-29 22:21:41 +00:00
|
|
|
JSON.stringify(buildConfig)
|
2017-03-22 22:13:37 +00:00
|
|
|
.replace('<!-- inject:cache-breaker -->',
|
|
|
|
Math.random().toString(12).substring(7)) +
|
|
|
|
';</script>'
|
|
|
|
;
|
|
|
|
}
|
|
|
|
}))
|
|
|
|
.pipe(env.production(plugins.kyhInlineSource({ compress: false })))
|
2017-03-27 19:34:02 +00:00
|
|
|
.pipe(plugins.realFavicon.injectFaviconMarkups(JSON.parse(fs.readFileSync(config.faviconData)).favicon.html_code))
|
2017-03-22 22:13:37 +00:00
|
|
|
.pipe(plugins.cacheBust({
|
|
|
|
type: 'timestamp'
|
|
|
|
}))
|
|
|
|
.pipe(plugins.htmlmin({
|
|
|
|
removeComments: true,
|
|
|
|
collapseWhitespace: true,
|
|
|
|
minifyJS: true
|
|
|
|
}))
|
|
|
|
.pipe(gulp.dest(config.build));
|
|
|
|
};
|
|
|
|
};
|