Minifies inline <script>
tags containing JSON data, i.e. application/json
and application/ld+json
.
npm i --save-dev gulp-minify-inline-json
const minifyInlineJSON = require('gulp-minify-inline-json');
gulp.task('minifyInlineJSON', () =>
gulp.src('*.html')
.pipe(minifyInlineJSON())
.pipe(gulp.dest('dist/')));
Provide custom mime types to specify which <script>
tags to minify.
<html>
<head><!-- ... --></head>
<body>
<!-- ... -->
<script type="application/json">{
"some": "json"
}</script>
<script type="application/ld+json">{
"foo": "bar"
}</script>
</body>
</html>
const minifyJSON = require('gulp-minify-inline-json');
gulp.task('minifyJSON', () =>
gulp.src('*.html')
.pipe(minifyJSON({
mimeTypes: [
'application/ld+json'
]
}))
.pipe(gulp.dest('dist/')));
<html>
<head><!-- ... --></head>
<body>
<!-- ... -->
<script type="application/json">{
"some": "json"
}</script>
<script type="application/ld+json">{"foo":"bar"}</script>
</body>
</html>