kaiqigong / gulp-cdnify Goto Github PK
View Code? Open in Web Editor NEWA gulp plugin that converts local URLs to CDN ones.
A gulp plugin that converts local URLs to CDN ones.
I see in source code support for custom patterns: https://github.com/kaiqigong/gulp-cdnify/blob/master/index.js#L72
But extend function overwrite html params even if it was passed.
img,back-end build page~
Is there a way to make the plugin work with just relative (not root-relative) links? E.g. src="images/picture.jpg"
instead of src="/foo/bar/images/picture.jpg"
when referenced from /foo/bar/index.html
.
I have script tags within IE conditional comments which are not being cdnified thus:
<!--[if lt IE 9]>
<script src="scripts/polyfills-2796740d48.js"></script>
<style>
.ng-hide {
display: none !important;
}
</style>
<![endif]-->
is not converted.
It would be great if the plugin dealt with srcset as well, e.g. <img src="small.jpg" srcset="medium.jpg 1000w, large.jpg 2000w">
or <img src="picture.jpg" srcset="picture-2x.jpg 2x">
. Any chance to make it happen? :-)
Since the original code is heavily copied from there (BTW you should mention this somewhere), we should backport from there.
Hi,
I set my sources path to:
<link rel="stylesheet" href="css/main.css">
<script src="js/bundle.js"></script>
after running cdnify:
gulp.src(config.source.index)
.pipe($.cdnify({
base: 'http://my.cdn.path-cdn.com/'
}))
.pipe(gulp.dest(config.dist.root));
The output:
<link rel="stylesheet" href="http://my.cdn.path-cdn.com\css\main.css">
<script src="http://my.cdn.path-cdn.com\js\bundle.js"></script>
It would be useful if gulp-cdnify supported different CDN hosts for different asset extensions. For example, assets with font extensions and image assets. Something like:
cdnify({
base: 'http://mycdn.com/',
negate: {
'/eot]ttf|woff|woff2/$': 'http://myfontcdn.com/'
}
});
Is there a way to make the plugin work with the code like this:
<div style="background-image: url(/path/to/img.png);">
</div>
thanks!
the process is terminated halfway looks like some malformed source file but the stacktrace didn't tell. Anyway I can fix this?
[09:42:46] Changed HTML file: "c:\wamp\www\2.0_dist_tmp\js\couponListAll.e83a3cea.js"
[09:42:46] Changed HTML file: "c:\wamp\www\2.0_dist_tmp\js\date.a7536e5a.js"
[09:42:46] Changed HTML file: "c:\wamp\www\2.0_dist_tmp\js\DOMWindow.509189ec.js"
c:\wamp\www\node_modules\gulp-cdnify\node_modules\soup\lib\soup.js:62
if (correspondingOpeningTag.start === 1 && _this._string.charAt(1) !
^
TypeError: Cannot read property 'start' of undefined
at Object.htmlparser.Parser.onclosetag (c:\wamp\www\node_modules\gulp-cdnify\node_modules\soup\lib\soup.js:62:38)
at Parser.onend (c:\wamp\www\node_modules\gulp-cdnify\node_modules\soup\node_modules\htmlparser2\lib\Parser.js:274:14)
at Tokenizer.end (c:\wamp\www\node_modules\gulp-cdnify\node_modules\soup\node_modules\htmlparser2\lib\Tokenizer.js:813:12)
at Parser.end (c:\wamp\www\node_modules\gulp-cdnify\node_modules\soup\node_modules\htmlparser2\lib\Parser.js:306:18)
at Soup.module.exports.Soup._build (c:\wamp\www\node_modules\gulp-cdnify\node_modules\soup\lib\soup.js:81:12)
at Soup.module.exports.Soup.setAttribute (c:\wamp\www\node_modules\gulp-cdnify\node_modules\soup\lib\soup.js:110:10)
at DestroyableTransform._transform (c:\wamp\www\node_modules\gulp-cdnify\index.js:119:26)
at DestroyableTransform.Transform._read (c:\wamp\www\node_modules\gulp-cdnify\node_modules\through2\node_modules\readable-stream\lib_stream_transform.js:184:10)
at DestroyableTransform.Transform._write (c:\wamp\www\node_modules\gulp-cdnify\node_modules\through2\node_modules\readable-stream\lib_stream_transform.js:172:12)
at doWrite (c:\wamp\www\node_modules\gulp-cdnify\node_modules\through2\node_modules\readable-stream\lib_stream_writable.js:237:10)
Process finished with exit code 1
The repo needs tests, otherwise we are living on the edge :P
The module currently doesn’t affect URLs in <picture>
element. Would be great if that was added to the functionality.
Edit: Doesn't affect the srcset
attribute within <picture>
element.
The default sources are not applied so that without sources explicitly given in the options object cdnify fails to change any urls.
Thus this passes:
pipe($.cdnify({
base: 'http://cdn.com/',
html: {
'img[src]': 'src',
'link[rel=stylesheet]': 'href',
'script[src]': 'src',
'video[poster]': 'poster',
'source[src]': 'src'
}
}));
And this fails:
pipe($.cdnify({
base: 'http://cdn.com/'
}));
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.