使用 JSBuilder 或 Apache ANT 构建 Sencha Touch 应用程序

发布于 2024-11-28 01:58:45 字数 430 浏览 2 评论 0原文

假设您已经使用一堆视图、控制器、模型、存储、实用程序等构建(编码)了 MVC Sencha Touch 应用程序...

“构建”用于生产用途的应用程序的最佳方法是什么?

任务是:

  • 合并并缩小所有 JS 源文件
  • 合并并缩小样式表(基本上在生产环境中运行 Compass)
  • 删除不需要的文件夹

有人使用 JSBuilder 或 Apache Ant 完成过此操作吗?我发现与 Sencha Touch lib 集成的 JSBuilder 解决方案有很多错误并且没有文档记录。 Apache Ant 非常适合像 Jenkins 这样的“更大”构建或 CI 系统,但我错过了一个如何使用 Sencha Touch 应用程序实现这一目标的好例子。

所以问题是,Sencha Touch 的构建脚本应该是什么样的?

Assume you have built (coded) your MVC Sencha Touch App with a bunch of Views, Controllers, Models, Stores, Utils etc...

Whats the best way to "build" the application for production use?

Tasks would be:

  • Concat and minify all JS Source Files
  • Concat and minify Stylesheets (basically running Compass with production environment)
  • Remove not needed folders

Has anyone done this yet with either JSBuilder or Apache Ant? I find the JSBuilder solution integrated with the Sencha Touch lib quite buggy and undocumented. Apache Ant would perfectly fit in with "bigger" build- or CI-systems like Jenkins but I miss a good example how to achive this with a Sencha Touch app.

So the question is, how should a build script for Sencha Touch look like?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

转身泪倾城 2024-12-05 01:58:45

编辑:警告:这是一个旧答案,今天可能有更好的方法来做到这一点。自 2011 年以来,现代 javascript 构建工具已经取得了长足的进步

。我今天实际上就是这样做的。

首先我考虑使用 sprockster,因为我喜欢定义脚本依赖项的 c/c++ include 风格。

我最终使用了 Apache ant,因为我的一些团队成员有点害怕 ruby​​。
Apache ant 似乎也是一个更通用且文档齐全的工具。

我还没有弄清楚如何自动构建 sass 文件,但这应该不会太困难。

我使用的过程很简单:

  1. 连接所有js文件并将它们放在build文件夹中
  2. 缩小build文件夹中的所有js文件并将它们重命名为*-min.js
  3. 将所有必需的文件复制到dist文件夹(包括图像,sencha- touch.js、索引文件等)

这就是我最终得到的结果:

<project name="ProjectApp" default="dist" basedir=".">
    <description>
        Project Manager build file
        dist-debug is the target that's best for debugging
        Run ant dist-debug to build the project
    </description>
    <!-- set global properties for this build -->
    <property name="src" location="src"/>
    <property name="lib" location="lib"/>
    <property name="build" location="build"/>
    <property name="dist"  location="dist"/>
    <property name="utils"  location="utils"/>
    <property name="img"  location="img"/>

    <target name="init">
        <!-- Create the build directory structure used by compile -->
        <mkdir dir="${build}"/>
    </target>

    <target name="concatenate" depends="init" description="Concatenate all js files">
        <concat destfile="${build}/application.js" fixlastline="yes">
            <fileset file="${src}/js/app.js" />
            <fileset file="${src}/js/observablize.js" />
            <fileset file="${src}/js/config.js" />

            <!-- Models -->
            <fileset file="${src}/js/models/Project.js" />
            <fileset file="${src}/js/models/ProjectInformation.js" />
            <fileset file="${src}/js/models/Picture.js" />
            <fileset file="${src}/js/models/Milestone.js" />
            <fileset file="${src}/js/models/Risk.js" />
            <fileset file="${src}/js/models/data.js" />
            <fileset file="${src}/js/models/Invoice.js" />
            <fileset file="${src}/js/models/Customer.js" />
            <fileset file="${src}/js/models/OpenItem.js" />
            <fileset file="${src}/js/models/favorites.js" />
            <fileset file="${src}/js/models/mockObjects.js" />

            <!-- Database -->
            <fileset file="${src}/js/database/createTables.js" />
            <fileset file="${src}/js/database/database.js" />
            <fileset file="${src}/js/database/projectObserver.js" />

            <!-- Network -->
            <fileset file="${src}/js/network/network.js" />
            <fileset file="${src}/js/network/queries.js" />
            <fileset file="${src}/js/network/parseProjectServiceProject.js" />
            <fileset file="${src}/js/network/parseQueryEngineProjects.js" />
            <fileset file="${src}/js/network/parseDocArchiveSearchResponse.js" />
            <fileset file="${src}/js/network/parseDocArchiveDataResponse.js" />
            <fileset file="${src}/js/network/parseQueryEngineInvoices.js" />
            <fileset file="${src}/js/network/parseQueryEngineCustomer.js" />

            <!-- Views -->
            <fileset file="${src}/js/views/Viewport.js" />
            <fileset file="${src}/js/views/XTemplates.js" />
            <fileset file="${src}/js/views/Login.js" />
            <fileset file="${src}/js/views/ProjectList/ActionSheet.js" />
            <fileset file="${src}/js/views/ProjectList/ProjectView.js" />
            <fileset file="${src}/js/views/ProjectList/ProjectList.js" />
            <fileset file="${src}/js/views/ProjectList/ProjectsLists.js" />
            <fileset file="${src}/js/views/ProjectInfo.js" />
            <fileset file="${src}/js/views/ProjectRisks.js" />
            <fileset file="${src}/js/views/ProjectMilestones.js" />
            <fileset file="${src}/js/views/ProjectDetail.js" />
            <fileset file="${src}/js/views/Overlays.js" />

            <!-- Controllers -->
            <fileset file="${src}/js/controllers/login.js" />
            <fileset file="${src}/js/controllers/projects.js" />
        </concat>
    </target>

    <target name="compress" depends="concatenate" description="Compress application.js to application-min.js">
        <apply executable="java" parallel="false">
            <filelist dir="${build}" files="application.js" />
            <arg line="-jar" />
            <arg path="${utils}/yuicompressor-2.4.6.jar" />
            <srcfile />
            <arg line="-o" />
            <mapper type="glob" from="*.js" to="${build}/*-min.js" />
            <targetfile />
        </apply>
    </target>

    <target name="dist-debug" depends="concatenate" description="generate the distribution">
        <!-- Create the distribution directory -->
        <mkdir dir="${dist}"/>

        <!-- copy over the required files -->

        <!-- required libraries -->
        <!-- sencha touch -->
        <copy file="${lib}/sencha-touch/sencha-touch.js" todir="${dist}"/>

        <!-- stylesheet -->
        <copy file="${build}/application.css" todir="${dist}"/> 

        <!-- index file -->
        <copy file="${src}/index.html" todir="${dist}"/>

        <!-- manifest file -->
        <copy file="${src}/cache.manifest" todir="${dist}"/>

        <!-- app javascript -->
        <copy file="${build}/application.js" tofile="${dist}/application.js"/>

        <!-- images -->
        <copy file="${img}/icon.png" todir="${dist}"/>
        <copy file="${img}/startup.png" todir="${dist}"/>
        <copy file="${img}/disclosure.png" todir="${dist}"/>

    </target>

    <target name="dist" depends="dist-debug,compress" description="generate minified distribution"> 
        <!-- app javascript -->
        <copy file="${build}/application-min.js" tofile="${dist}/application.js"/>  
    </target>   

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

</project>

如您所见,我指定了项目中的每个文件。这只是为了得到正确的顺序。如果您的代码写得比我的好,并且没有任何依赖项,您可以只包含整个源文件夹。

EDIT: Warning: this is an old answer, today there might be better ways to do this. Modern build tools for javascript have come a long way since 2011.

I actually did just this today.

First I considered using sprockster, since I liked the c/c++ include style of defining script dependencies.

I ended up using Apache ant because some of my team members are somewhat afraid of ruby.
Apache ant also seemed like a more universal and well documented tool.

I haven't figured out how to build the sass files automatically just yet, but that shouldn't be too difficult.

The process i use is kind of simple:

  1. concatenate all js files and place them in the build folder
  2. minify all js files in the build folder and rename them *-min.js
  3. copy all required files to the dist folder (including images, sencha-touch.js, index file etc)

This is what i ended up with:

<project name="ProjectApp" default="dist" basedir=".">
    <description>
        Project Manager build file
        dist-debug is the target that's best for debugging
        Run ant dist-debug to build the project
    </description>
    <!-- set global properties for this build -->
    <property name="src" location="src"/>
    <property name="lib" location="lib"/>
    <property name="build" location="build"/>
    <property name="dist"  location="dist"/>
    <property name="utils"  location="utils"/>
    <property name="img"  location="img"/>

    <target name="init">
        <!-- Create the build directory structure used by compile -->
        <mkdir dir="${build}"/>
    </target>

    <target name="concatenate" depends="init" description="Concatenate all js files">
        <concat destfile="${build}/application.js" fixlastline="yes">
            <fileset file="${src}/js/app.js" />
            <fileset file="${src}/js/observablize.js" />
            <fileset file="${src}/js/config.js" />

            <!-- Models -->
            <fileset file="${src}/js/models/Project.js" />
            <fileset file="${src}/js/models/ProjectInformation.js" />
            <fileset file="${src}/js/models/Picture.js" />
            <fileset file="${src}/js/models/Milestone.js" />
            <fileset file="${src}/js/models/Risk.js" />
            <fileset file="${src}/js/models/data.js" />
            <fileset file="${src}/js/models/Invoice.js" />
            <fileset file="${src}/js/models/Customer.js" />
            <fileset file="${src}/js/models/OpenItem.js" />
            <fileset file="${src}/js/models/favorites.js" />
            <fileset file="${src}/js/models/mockObjects.js" />

            <!-- Database -->
            <fileset file="${src}/js/database/createTables.js" />
            <fileset file="${src}/js/database/database.js" />
            <fileset file="${src}/js/database/projectObserver.js" />

            <!-- Network -->
            <fileset file="${src}/js/network/network.js" />
            <fileset file="${src}/js/network/queries.js" />
            <fileset file="${src}/js/network/parseProjectServiceProject.js" />
            <fileset file="${src}/js/network/parseQueryEngineProjects.js" />
            <fileset file="${src}/js/network/parseDocArchiveSearchResponse.js" />
            <fileset file="${src}/js/network/parseDocArchiveDataResponse.js" />
            <fileset file="${src}/js/network/parseQueryEngineInvoices.js" />
            <fileset file="${src}/js/network/parseQueryEngineCustomer.js" />

            <!-- Views -->
            <fileset file="${src}/js/views/Viewport.js" />
            <fileset file="${src}/js/views/XTemplates.js" />
            <fileset file="${src}/js/views/Login.js" />
            <fileset file="${src}/js/views/ProjectList/ActionSheet.js" />
            <fileset file="${src}/js/views/ProjectList/ProjectView.js" />
            <fileset file="${src}/js/views/ProjectList/ProjectList.js" />
            <fileset file="${src}/js/views/ProjectList/ProjectsLists.js" />
            <fileset file="${src}/js/views/ProjectInfo.js" />
            <fileset file="${src}/js/views/ProjectRisks.js" />
            <fileset file="${src}/js/views/ProjectMilestones.js" />
            <fileset file="${src}/js/views/ProjectDetail.js" />
            <fileset file="${src}/js/views/Overlays.js" />

            <!-- Controllers -->
            <fileset file="${src}/js/controllers/login.js" />
            <fileset file="${src}/js/controllers/projects.js" />
        </concat>
    </target>

    <target name="compress" depends="concatenate" description="Compress application.js to application-min.js">
        <apply executable="java" parallel="false">
            <filelist dir="${build}" files="application.js" />
            <arg line="-jar" />
            <arg path="${utils}/yuicompressor-2.4.6.jar" />
            <srcfile />
            <arg line="-o" />
            <mapper type="glob" from="*.js" to="${build}/*-min.js" />
            <targetfile />
        </apply>
    </target>

    <target name="dist-debug" depends="concatenate" description="generate the distribution">
        <!-- Create the distribution directory -->
        <mkdir dir="${dist}"/>

        <!-- copy over the required files -->

        <!-- required libraries -->
        <!-- sencha touch -->
        <copy file="${lib}/sencha-touch/sencha-touch.js" todir="${dist}"/>

        <!-- stylesheet -->
        <copy file="${build}/application.css" todir="${dist}"/> 

        <!-- index file -->
        <copy file="${src}/index.html" todir="${dist}"/>

        <!-- manifest file -->
        <copy file="${src}/cache.manifest" todir="${dist}"/>

        <!-- app javascript -->
        <copy file="${build}/application.js" tofile="${dist}/application.js"/>

        <!-- images -->
        <copy file="${img}/icon.png" todir="${dist}"/>
        <copy file="${img}/startup.png" todir="${dist}"/>
        <copy file="${img}/disclosure.png" todir="${dist}"/>

    </target>

    <target name="dist" depends="dist-debug,compress" description="generate minified distribution"> 
        <!-- app javascript -->
        <copy file="${build}/application-min.js" tofile="${dist}/application.js"/>  
    </target>   

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

</project>

As you can see, I specify every single file in my project. This is just to get the order right. If your code is better written than mine, and don't have any dependencies, you could just include an entire source folder.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文