Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including gulp-minify-inline-json with all npm packages installed. Try it out:

var gulpMinifyInlineJson = require("gulp-minify-inline-json")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

gulp-minify-inline-json v1.3.2

Gulp plugin to minify inline JSON.

gulp-minify-inline-json

NPM

npm version Build Status

Minifies inline <script> tags containing JSON data, i.e. application/json and application/ld+json.

Installation

npm i --save-dev gulp-minify-inline-json

Usage

const minifyInlineJSON = require('gulp-minify-inline-json');

gulp.task('minifyInlineJSON', () =>
  gulp.src('*.html')
    .pipe(minifyInlineJSON())
    .pipe(gulp.dest('dist/')));

Options

mimeTypes Array<string>

Provide custom mime types to specify which <script> tags to minify.

default: [ 'application/json', 'application/ld+json' ]
Example: Minify only tags with type="application/ld+json"
HTML Layout
<html>
  <head><!-- ... --></head>
  <body>
    <!-- ... -->
    <script type="application/json">{
      "some": "json"
    }</script>
    <script type="application/ld+json">{
      "foo": "bar"
    }</script>
  </body>
</html>
Gulp task
  const minifyJSON = require('gulp-minify-inline-json');

  gulp.task('minifyJSON', () =>
    gulp.src('*.html')
      .pipe(minifyJSON({
        mimeTypes: [
          'application/ld+json'
        ]
      }))
      .pipe(gulp.dest('dist/')));
Output
<html>
  <head><!-- ... --></head>
  <body>
    <!-- ... -->
    <script type="application/json">{
      "some": "json"
    }</script>
    <script type="application/ld+json">{"foo":"bar"}</script>
  </body>
</html>

Changelog

License

Metadata

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free