Building JavaScript components with Ant

Source: Internet
Author: User
Tags version root directory

Where Have we gone? In the first two stages of thinking too much stuff, have you ever been tired? Don't worry, this issue is easy, you just need to learn some syntax, write a few lines of configuration, you can drive the system in the way you preset to do some work automatically. Does it sound cozy? Let ' s go! Let's Go!

In this issue, we will use Ant to merge the code files written and collated in the previous period into a single source file in the order specified, and then compress the file. This is the basic step in building a JavaScript project. Ant is a top open source project in Apache, the introduction and installation of it on the Internet, there are many articles, here is no longer to repeat. Before we build, let's take a look at the existing file layouts:

Smart-queue//component's root directory
+---src//javascript source files directory
+---lang.js//"external file" referred to above
+---smart-queue.js//Smart Queue Master File

Now, we're going to make it "plump":

    • Component root directory Add:
      • README: Introducing the Smart Queue component
      • LICENSE: Authorization Information for components
      • Configuration files used by build.xml:Ant
    • Add Lib subdirectory under component root: Store external programs and library files that need to be used in the build process
      • LIB subdirectory add Yuicompressor.jar: We use YUI compressor compressed JavaScript
    • Add test subdirectory under Component root: Files required to store test components (next introduction)
    • Add intro.js to the SRC directory: Introduction to the component version and description information

Though small, spite. Now the Smart Queue looks like a more professional JavaScript project:

Smart-queue//component's root directory
+---lib//JavaScript external program and library file directory
+---yuicompressor.jar//YUI Compressor
+---Test//testing file directory
+---src//javascript source files directory
+---intro.js//Introduction and version information
+---lang.js//"external file" referred to above
+---smart-queue.js//Smart Queue Master File
+---Readme//Component Readme File
+---LICENSE//component licensing information

We plan to store the built files into the build subdirectory under the component root and create and destroy it through the build tools. Before attempting to build for the first time, it is advisable to have a general idea of the structure of the ANT configuration file--build.xml:

<project name= "MyProject" default= "Dist" basedir= "." >
<description>
Simple example Build file
</description>
<!--set global properties for this build-->
<property name= "src" location= "src"/>
<property name= "Build" location= "Build"/>
<property name= "Dist" location= "dist"/>

<target name= "Init" >
<!--Create the time stamp-->
<tstamp/>
<!--Create The build directory structure used by compile-->
<mkdir dir= "${build}"/>
</target>

<target name= "Compile" depends= "Init"
description= "Compile the source" >
<!--Compile the Java code from ${SRC} into ${build}-->
<javac srcdir= "${src}" destdir= "${build}"/>
</target>

<target name= "Clean"
description= "Clean up" >
<!--Delete the ${build} and ${dist directory trees-->
<delete dir= "${build}"/>
<delete dir= "${dist}"/>
</target>
</project>

Carefully observe that, except for name, description these names are easy to understand, and other laws that can be seen include:

    • The default property value of a project element corresponds to the Name property of a target element;
    • The depends attribute value of the target element corresponds to the Name property of some other target element;
    • ${somename} can refer to values defined in the property.



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.