mathiasbynens / grunt-zopfli Goto Github PK
View Code? Open in Web Editor NEWA Grunt plugin for compressing files using Zopfli.
Home Page: http://git.io/grunt-zopfli
License: GNU General Public License v2.0
A Grunt plugin for compressing files using Zopfli.
Home Page: http://git.io/grunt-zopfli
License: GNU General Public License v2.0
Any ideas on how to make Travis run zopfli
correctly?
Could it be done by adding something like this to .travis.yml
?
before_script:
- "# commands to download and install Zopfli go here"
Or is there a better way for this sort of thing?
Getting these:
npm WARN [email protected] requires a peer of grunt@~0.4.1 but none was installed.
grunt-zopfli
is the only module I can't update to a version that lives happily with newer grunt. Would you mind making a new release?
If I run zopfli.exe (with same default options, or explicitly specifying gzip), I get a functional gzip compressed file. If I use this task (default options, or explicitly specifying gzip), I get a non-functional file that is 11 bytes longer and fails gzip CRC checks.
The content of the working and non-working files appears identical except that the one generated by this task has errant newlines throughout (the zopfli.exe output has 3 lines, the grunt-zopfli output has 12. Looks like a problem in how you're writing the output stream to disk.
Once Homebrew/legacy-homebrew#19435 gets accepted, the README should be amended with the following message (below the installation instructions):
With Homebrew, you can just run
brew update; brew install zopfli
instead.
Would make it easier for people to use this task.
Path expansion seem to pickup the name src
and places the file in the running directory.
'zopfli': {
'images': {
files: {
'src': ['build/img/cards/*'],
'dest': 'build/img/cards/compressed',
'expand': true,
'ext': '.png'
}
}
},
Gives
Running "zopfli:images" (zopfli) task
Filesrc
created.
Original: 122158 bytes.
Compressed: 121931 bytes.
Filesrc
created.
Original: 108372 bytes.
Compressed: 108142 bytes.
Filesrc
created.
Original: 114956 bytes.
Compressed: 114729 bytes.
[...]
This still works as intended though:
'zopfli': {
'images': {
files: {
'build/img/cards/compressed/479.png': 'build/img/cards/479.png'
}
}
},
See http://dontkry.com/posts/code/2013-04-24-use-this-files.html by @shama.
Currently I assume that only a single src
file will get Zopflinated and saved to a single dest
.
Perhaps allow any number of src
/dest
s, as long as they’re equal in length, to allow for stuff like:
grunt.initConfig({
'zopfli': {
'lolwat': {
'src': ['things/*'],
'dest': 'putaway/',
'expand': true
}
}
});
@sindresorhus suggested using execFile
instead of exec
, because that way the input wouldn’t need to be escaped (and we could get rid of the shellwords
dependency).
I tried changing this:
var zopfli = function(filePath, options, callback) {
var command = [
'zopfli',
'-c',
'--i' + options.iterations,
options.format == 'gzip' ? '--gzip'
: options.format == 'deflate' ? '--deflate'
: '--zlib',
options.splitLast ? '--splitlast' : '',
shellEscape(filePath)
].join(' ');
exec(command, function(error, stdout, stderr) {
if (error) {
grunt.log.warn(error);
return;
}
callback.call(this, error || stderr, stdout);
});
};
…into…
var zopfli = function(filePath, options, callback) {
var args = [
'-c',
'--i' + options.iterations,
options.format == 'gzip' ? '--gzip'
: options.format == 'deflate' ? '--deflate'
: '--zlib',
options.splitLast ? '--splitlast' : '',
filePath
];
execFile('zopfli', args, function(error, stdout, stderr) {
callback.call(this, error || stderr, stdout);
});
};
This seems to work fine except for the fourth test in this repo’s Gruntfile.js, for which
Zopfli now throws an error:
Invalid filename:
I have no idea why. I tried replacing the zopfli
command with echo
to see what the arguments looked like but they looked fine. As far as I can tell, here’s the full command that is executed for test-4
:
zopfli -c --i25 --deflate tests/fixtures/benchmark.js
I must be doing something really stupid.
Under some circumstances an option to use the same name of the source file could be a great time saving.
(ex. we're versioning our files before zopflin' them)
someting like
'': 'assets/js/*.scripts.min.js'
to get
*.scripts.min.js.gz
where *
here is a placeholder for the md5 hash
So, grunt-zopfli runs fine for all kinds of output formats, and the unit tests confirm that the grunt-zopfli’s gzipped output is correct (i.e. it gunzips to the original file).
It’s highly unlikely that grunt-zopfli doesn’t work correctly for Zopfli’s deflate
and zlib
settings, since it uses the same code paths and everything — only the argument in the shell command is different. But it would be nice to have tests that confirm this.
The disabled tests are here:
Lines 45 to 80 in dd6614f
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.