haensl / gulp-minify-inline-json Goto Github PK
View Code? Open in Web Editor NEWMinifies inline <script> tags containing JSON data, i.e. application/json and application/ld+json.
License: MIT License
Minifies inline <script> tags containing JSON data, i.e. application/json and application/ld+json.
License: MIT License
Since cheerio has side effects when parsing, e.g. mustache templates, we need to exchange the engine.
Hi, I get an error after run gulp minifyInlineJSON
E:\YUDY\WEB PROJECT\TIA\PROD\mm>gulp minifyInlineJSON
[15:23:53] Using gulpfile E:\YUDY\WEB PROJECT\TIA\PROD\mm\gulpfile.js
[15:23:53] Starting 'minifyInlineJSON'...
[15:23:53] Finished 'minifyInlineJSON' after 13 ms
events.js:112
throw er; // Unhandled 'error' event
^
SyntaxError: Unexpected token
in JSON at position 867
at JSON.parse (<anonymous>)
at Node.<anonymous> (E:\YUDY\WEB PROJECT\TIA\PROD\mm\node_modules\gulp-minify-inline-json\index.js:37:45)
at initialize.exports.each (E:\YUDY\WEB PROJECT\TIA\PROD\mm\node_modules\gulp-minify-inline-json\node_modules\cheerio\lib\api\traversing.js:300:24)
at DestroyableTransform.through.obj [as _transform] (E:\YUDY\WEB PROJECT\TIA\PROD\mm\node_modules\gulp-minify-inline-json\index.js:31:8)
at DestroyableTransform.Transform._read (E:\YUDY\WEB PROJECT\TIA\PROD\mm\node_modules\through2\node_modules\readable-stream\lib\_stream_transform.js:184:10)
at DestroyableTransform.Transform._write (E:\YUDY\WEB PROJECT\TIA\PROD\mm\node_modules\through2\node_modules\readable-stream\lib\_stream_transform.js:172:83)
at doWrite (E:\YUDY\WEB PROJECT\TIA\PROD\mm\node_modules\through2\node_modules\readable-stream\lib\_stream_writable.js:418:64)
at writeOrBuffer (E:\YUDY\WEB PROJECT\TIA\PROD\mm\node_modules\through2\node_modules\readable-stream\lib\_stream_writable.js:407:5)
at DestroyableTransform.Writable.write (E:\YUDY\WEB PROJECT\TIA\PROD\mm\node_modules\through2\node_modules\readable-stream\lib\_stream_writable.js:334:11)
at write (E:\YUDY\WEB PROJECT\TIA\PROD\mm\node_modules\vinyl-fs\node_modules\readable-stream\lib\_stream_readable.js:623:24)
This is my gulpfile.js
const minifyInlineJSON = require('gulp-minify-inline-json');
gulp.task('minifyInlineJSON', () =>
gulp.src('public/**/*.html')
.pipe(minifyInlineJSON())
.pipe(gulp.dest('public/./')));
Try with option below then run gulp minifyJSON
the result is the same
const minifyJSON = require('gulp-minify-inline-json');
gulp.task('minifyJSON', () =>
gulp.src('public/**/*.html')
.pipe(minifyJSON({
mimeTypes: [
'application/ld+json'
]
}))
.pipe(gulp.dest('public/./')));
this is sample from my inline json
<script type="application/ld+json">
{ "@context": "http://schema.org",
"@type": "BlogPosting",
"headline": "Lorem ipsum",
"image": "http://localhost:1313//image/content/2018/02/lorem.jpg",
"wordcount": "1025",
"url": "http://localhost:1313/lorem/",
"datePublished": "2018-2-24",
"dateCreated": "2018-2-24",
"dateModified": "2018-2-26",
"description": "Lorem ipsum dolor amet vice PBR&B selfies farm-to-table wayfarers craft beer hashtag. Offal skateboard neutra copper mug ",
"articleBody": " Lorem ipsum dolor amet vice PBR&B selfies farm-to-table wayfarers craft beer hashtag. Offal skateboard neutra copper mug asymmetrical brooklyn. Yuccie mustache occupy disrupt meggings hot chicken. Photo booth 8-bit skateboard hoodie. ๐
Tilde vegan health goth, knausgaard austin 90's ethical williamsburg beard shabby chic vexillologist. Man braid green juice taxidermy, organic paleo pinterest hella. Ugh meggings tacos kogi palo santo banh mi. + Tilde vegan health goth, knausgaard austin 90's ethical williamsburg beard shabby chic vexillologist. Man braid green juice taxidermy, organic paleo pinterest hella. Ugh meggings tacos kogi palo santo banh mi.",
"author": {
"@type": "Person",
"name": "John Doe"
},
"mainEntityOfPage": "True",
"publisher": {
"@type": "Organization",
"name": "example.com",
"logo": {
"@type": "imageObject",
"url": "http://localhost:1313/image/asset/banner.jpg"
}
}
}
</script>
any clue?
Thanks
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.