ahomu / grunt-data-uri Goto Github PK
View Code? Open in Web Editor NEWConvert to data-uri from image path
License: MIT License
Convert to data-uri from image path
License: MIT License
OK:
/grunt.js
/css/style.css
/img/embed.png
NG:
/build/grunt.js
/css/style.css
/img/embed.png
in NG case, grunt.js is shown below:
dataUri: {
dist: {
src: ['../css/style.css'],
dest: '../css/test',
options: {
target: [
'../img/embed.png'
],
fixDirLevel: true
}
}
grunt-data-uri found uri in CSS, but Ignore IMG path.
Is there a solution?
I use a version number in my paths:
dataUri: {
dist: {
// src file
src: ['build/v<%= pkg.version %>/css/wimp.css'],
// output dir
dest: 'build/v<%= pkg.version %>/css',
options: {
// specified files are only encoding
target: ['build/v<%= pkg.version %>/img/*.*']
}
}
}
This fails for 'dest' since it is not read by a grunt method.
Proposed change to data-uri.js:
Line 26:
destDir = path.resolve(this.data.dest),
to:
destDir = grunt.file.expandDirs(this.data.dest),
And line 33:
outputTo = destDir+'/'+path.basename(src),
to:
outputTo = destDir+path.basename(src),
(I have not tested if this requires changes to the path renaming part of the code, as I'm not using that.)
Only JPEG is supported? SVG & PNG path will only be adjusted
dist: {
src: [ "cache/views/index.css" ],
dest: "cache/views/index.css",
}
➜ grunt dataUri
Running "dataUri:dist" (dataUri) task
[TypeError: Cannot read property 'indexOf' of undefined]
Warning: Cannot read property 'indexOf' of undefined Use --force to continue.
➜ uname -a
Darwin MacBook-Pro--Monolithed.local 14.1.0 Darwin Kernel Version 14.1.0:
Mon Dec 22 23:10:38 PST 2014; root:xnu-2782.10.72~2/RELEASE_X86_64 x86_64
Running through this error every time i run grunt dataUri
Using grunt 0.4.0 and grunt-data-uri 0.1.1, i'm getting this error:
"Warning: Arguments to path.join must be strings Use --force to continue."
Which is caused by calling grunt.file.expand({filter: 'isFile'}, files); without "cwd" option
In my work flow using grunt-usemin, first all styles will be concatenate in a new file in the dist folder, so to use your task I need a way to tell the task whats the root for the images paths in this concatenated files.
In my grunt process I use grunt.file.setBase("../")
in order to include my entire repo in the grunt process.
The module uses setBase()
to allow for computing adjustment base URLs, etc (understandable), but at the end it sets the base back to a stored base path of path.resolve('./')
which may not actually be the original base path (it only MIGHT be if no setBase()
was called after the module initialized).
This can be corrected by adding this line to the beginning of the multi-task:
var originalCWD = process.cwd();
and then replacing the grunt.file.setBase(gruntfileDir);
at the end with:
grunt.file.setBase(originalCWD);
This ensures that any setBase called by the grunt setup process will be properly respected at the beginning and restored at the end of each task.
needle C:!WORK\project\img\common\prev.png
Ignore: ../../img/common/prev.png
data-uri.js line around 90
if (haystack.indexOf(needle) !== -1) {
// never here
}
Using Grunt 0.4.1, and the following settings:
the exception below is thrown.
Warning: u is not defined Use --force to continue.
ReferenceError: u is not defined
at module.exports.path.relative.split.forEach.resolvedPath (/Users/mars/Dropbox/interactive-suite/node_modules/grunt-data-uri/tasks/data-uri.js:99:27)
at Array.forEach (native)
at /Users/mars/Dropbox/interactive-suite/node_modules/grunt-data-uri/tasks/data-uri.js:78:12
at Array.forEach (native)
at Object.<anonymous> (/Users/mars/Dropbox/interactive-suite/node_modules/grunt-data-uri/tasks/data-uri.js:42:14)
at Object.task.registerMultiTask.thisTask (/Users/mars/Dropbox/interactive-suite/node_modules/grunt/lib/grunt/task.js:258:15)
at Object.task.registerTask.thisTask.fn (/Users/mars/Dropbox/interactive-suite/node_modules/grunt/lib/grunt/task.js:78:16)
at Object.Task.start._running (/Users/mars/Dropbox/interactive-suite/node_modules/grunt/lib/util/task.js:282:30)
at Task.runTaskFn (/Users/mars/Dropbox/interactive-suite/node_modules/grunt/lib/util/task.js:235:24)
at Task.<anonymous> (/Users/mars/Dropbox/interactive-suite/node_modules/grunt/lib/util/task.js:281:12)
Due to an update in the datauri module, grunt-data-uri no longer works. Please could you either update grunt-data-uri, or pin your dependency to a working version (<= 0.8)
I'm posting this issue to let you know that we will be publishing Grunt 0.4 on Monday, February 18th.
If your plugin is not already Grunt 0.4 compatible, would you please consider updating it? For an overview of what's changed, please see our migration guide.
If you'd like to develop against the final version of Grunt before Monday, please specify "grunt": "0.4.0rc8"
as a devDependency in your project. After Monday's release, you'll be able to use "grunt": "~0.4.0"
to actually publish your plugin. If you depend on any plugins from the grunt-contrib series, please see our list of release candidates for compatible versions. All of these will be updated to final status when Grunt 0.4 is published.
Also, in an effort to reduce duplication of effort and fragmentation in the developer community, could you review the grunt-contrib series of plugins to see if any of your functionality overlaps significantly with them? Grunt-contrib is community maintained with 40+ contributors—we'd love to discuss any additions you'd like to make.
Finally, we're working on a new task format that doesn't depend on Grunt: it's called node-task. Once this is complete, there will be one more conversion, and then we'll never ask you to upgrade your plugins to support our changes again. Until that happens, thanks for bearing with us!
If you have any questions about how to proceed, please respond here, or join us in #grunt on irc.freenode.net.
Thanks, we really appreciate your work!
file: tasks/data-uri.js
line: 99
is: replacement = u;
shuld be: replacement = uri;
When used with grunt-newer
, plugin throws error "Warning: Cannot read property 'indexOf' of undefined Use --force to continue.". It is probably caused by non-standard src-dest mappings used by grunt-data-uri
.
Problem is, grunt-newer
always passes files
in options, even though src
and dest
were set. It assumes, that whatever plugin it calls, it supports files array format.
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.