jquery - Problems with Ant to minimize JS files -
I am using ant to reduce all JS files in my project. It compiles my different JS files (i.e.: file1.js, file2.js, file3.js) in a file (i.e.: file.min.js) and then this minimum version is a build with my html source files Creates a copy in the folder.
This works great, but the HTML source files that are copied to the build folder, still reference the old non-minimized versions (file1.js, file2.js, etc ...)
So my question is, when I run an ant, there is a function / feature to convert any related file reference to HTML source code?
The easiest way is to use only the minimum JS. It works great until you need to run your JS through a debugger or you do not need to get a recognizable bacterium.
A technique called "source map" resolves this problem. If you use source maps, then you can always use the minimum version, and when you need to debug it, The debugger loads the non-minimized version on-demand. Unfortunately, as of this article (March 2013) the source maps are too , and the technology requires support from both browser and minifiers. If your HTML template is better for you to pass a setting in the template, you should say that you are developing a development or production, and then change the header text accordingly. has given. If none of the above solutions is suitable, then you have a solution to your problem, that you have to mark different comments in your HTML like this: Then the anti-virus runs some scripts to comment on some developing statements and add production statements: I recommend placing this command in a shell script and running script with ant execfile. Antirex for these types of replacement or other places may also have third party functions, but their use is a pain for all those who make your code, because they will have to use the same extension that you use We do. If you are building on a non-Unix-like system that has a lack of sed (Windows), then you might be able to use the Windows version of sed from the gnuwin32 project. Or just create virtualboxes in VM on Linux
& Lt ;! - BEGIN development - & gt; & Lt; Script src = "src / js / file1.js" & gt; & Lt; / Script & gt; & Lt; Script src = "src / js / file2.js" & gt; & Lt; / Script & gt; & Lt; Script src = "src / js / file3.js" & gt; & Lt; / Script & gt; & Lt ;! - End development - & gt; & Lt ;! - BEGIN production & lt; Script src = "dist / js / file.js.min" & gt; & Lt; / Script & gt; End production - & gt;
# to create a production version of this project Run this command. HTML cat src / html / project.html \ | Sed -e's / & lt ;! - BEGIN development - & gt; / & Lt ;! - BEGIN development / '\ | Sed -e's / & lt ;! - End development - & gt; / End development - & gt; / '\ | Sed -e's / & lt ;! - BEGIN production / & lt ;! - BEGIN PRODUCTION - & gt; / '\ | Sed -e / end product - & gt; / & Lt ;! - End production - & gt; / '\ & Gt; Dist / html / project.html
Comments
Post a Comment