I have without success been trying to combine some of my mostly redundant Rake file tasks. Even directing me towards some documentation on rake rules would be great, I've found very little.
All examples I've found have been files that were distinguished by their extensions, in my case I need something more specific.
file '.../bundle-a.js' => ['a.js','b.js','c.js']
file '.../bundle-b.js' => ['d.js','e.js','f.js']
rule ??? => ?开发者_开发问答?? do |f|
File.open( f.name, 'w' ) do |of|
of.write cat(f.prerequisites).concat('SPECIFIC TEXT TO EACH BUNDLE')
end
end
If I do a rule on .js => .js, I get recursive errors. If I look for /bundle/, it fails or I don't understand the processing that occurs. Also, I need to add that part about specific text, is there a solution via rules for this?
You can use Regexps in patterns and Procs in dependencies. Procs receive the filename as argument and should return a filename or an array of filenames.
rule %r{\A.../bundle-(.*)\.js\z} => proc{|fn| required_files_for(fn) } do |f|
...
end
If you use ".js" as the target and ".js" as the dependency, it means that a js file can be built from itself, which is a recursive rule.
精彩评论