Sencha CMD:运行内置生产版本时出现404错误 [英] Sencha CMD: 404 errors when running built production version

查看:114
本文介绍了Sencha CMD:运行内置生产版本时出现404错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经转换了我现有的ExtJS 4.1.3应用程序,以使用Sencha CMD推荐的结构和工具。我先创建了这个结构,然后将我现有的应用程序JS文件放在单页JS应用程序所在的位置。



我目前访问我的开发版本应用程序:

  {my-server-side-app-url} /sws/dt/index.jsp 

其中 sws 是,这是由问题/答案对,但无效。

解决方案

尝试包括所有类需要 使用 需要 部分您的 app.js



请注意,如果控制器需要某些视图,则可以在 app.js 的require部分中省略该视图,因为它将包含在内当sencha工具将解析你的控制器。



尝试使用完整路径添加文件到使用 / REQ uires 部分 app.js 。也就是说,写 MyApp.controller.pages.Home MyApp.store.users.List 但现在 pages.Home users.List



您可以使用 -before-build -after-build Ant目标在sencha工具的YUI最小化阶段启动之前修改你的app.js 。

在我的情况下,我最终搜索 app / controller 文件夹中的所有控制器,并将其名称添加到使用部分 app.js 。因为这是足够的,因为我的控制器中需要其他需要的课程。



为了能够找到app.js的使用部分,我使用了特殊注释

  / * ant-generated-content-start * / / * ant-generated-content-end * / 

我的 app.js

  Ext.application({
name:'MyApp',
appFolder:'app',

controllers:[
main .App
],

使用:[
/ * ant-generated-content-start * / / * ant-generated-content-end * /
],
autoCreateViewport:true,
});

我的 build.xml

 <?xml version =1.0encoding =utf-8?> 
< project name =MyAppdefault =。help>
< import file =$ {basedir} /。sencha / app / build-impl.xml/>

< target name = - before-build>

< echo message =收集应用程序类属性中的所有控制器/>
< fileset id =app_controllersdir =$ {app.dir} / app / controllercaseensitive =yes>
< include name =** / *。js/>
< / fileset>
< pathconvert pathsep =,property =app_controller_namesrefid =app_controllerstargetos =unix>
< chainedmapper>
< globmapper from =$ {app.dir} / app / *to =$ {ant.project.name} / *caseensitive =nohandlingirsep =yes/>
< chainedmapper>
< regexpmapper from =^(。*)\.js $$to ='\1'/>
< filtermapper>
< replacestring from =/to =。/>
< replacestring from =\to =。/>
< / filtermapper>
< / chainedmapper>
< / chainedmapper>
< / pathconvert>
< echo message =收集的控制器:$ {app_controller_names}/>

< echo message =注入app.js .../>
< replaceregexp file =$ {app.dir} /app/app.js
match =/ \ * ant-generated-content-start\ * /(。*)/ \ * ant-generated-content-end\ * /
replace =/ * ant-generated-content-start * / $ {app_controller_names} / * ant-generated-content-end * /
byline =true
/>
< / target>

< target name = - after-build>
< echo message =还原到原始app.js .../>
< replaceregexp file =$ {app.dir} /app/app.js
match =/ \ * ant-generated-content-start\ * /(。*)/ \ * ant-generated-content-end\ * /
replace =/ * ant-generated-content-start * / / * ant-generated-content-end * /
byline =true
/>
< / target>

< / project>


I have converted my existing ExtJS 4.1.3 application to use the Sencha CMD recommended structure and tools. I created the structure first, then put my existing app JS files at the place where the single-page JS app should be located.

I currently access the development version of my application at:

{my-server-side-app-url}/sws/dt/index.jsp

where sws is the Sencha workspace and dt is the Sencha single-page app. So far, no problems I believe. Then I run the command:

sencha app build

within my app's directory. This completes with several Yui Compressor Warning (Trailing comma is not legal in an ECMA-262 object initializer warnings, but no errors. So I the production index.jsp page (which uses all-classes.js file, which receives the concatenated output of the app build command above) at URL:

{my-server-side-app-url}/sws/build/dt/production/index.jsp

The issue occurs when all-classes.js attempts to load several files which in theory should be included within itself. These include the controllers which are specified in app.js.

Why are these files not being concatenated in all-classes.js? Below is a screenshot of Chrome attempting to load them from all-classes.js, and of course not finding them.

What did I try? Tried to tweak my app.js to require the controllers via requires; or to make the classes required available via uses as recommended by this question/answer pair, but to no avail.

解决方案

Try to include all classes you need inside uses or requires section of your app.js.

Note, that if controller is requiring some views, you may omit that view in require section of app.js, since it will be included anyway when sencha tool will be parsing your controller.

Try to use full paths when adding files to uses/requires section of app.js. That is, write MyApp.controller.pages.Home or MyApp.store.users.List but now pages.Home or users.List.

You can use -before-build and -after-build Ant targets to modify your app.js just before sencha tool's YUI minimizer phase start.
In my case I ended up with searching for all controllers inside app/controller folder and adding their names to uses section of app.js. For it that was enough, since other needed classes were required from within my controllers.

In order to be able to find uses section of app.js, I've used special comment

/*ant-generated-content-start*/ /*ant-generated-content-end*/

My app.js

Ext.application({
    name: 'MyApp',
    appFolder: 'app',

    controllers: [
        "main.App"
    ],

    uses: [
        /*ant-generated-content-start*/ /*ant-generated-content-end*/
    ],
    autoCreateViewport: true,
});

My build.xml

<?xml version="1.0" encoding="utf-8"?>
<project name="MyApp" default=".help">
    <import file="${basedir}/.sencha/app/build-impl.xml"/>

    <target name="-before-build">

        <echo message="Collecting all controllers in application class property ... "/>
        <fileset id="app_controllers" dir="${app.dir}/app/controller" casesensitive="yes">
            <include name="**/*.js"/>
        </fileset>
        <pathconvert pathsep="," property="app_controller_names" refid="app_controllers" targetos="unix">
            <chainedmapper>
                <globmapper from="${app.dir}/app/*" to="${ant.project.name}/*" casesensitive="no" handledirsep="yes"/>
                <chainedmapper>
                    <regexpmapper from="^(.*)\.js$$" to='"\1"'/>
                    <filtermapper>
                        <replacestring from="/" to="."/>
                        <replacestring from="\" to="."/>
                    </filtermapper>
                </chainedmapper>
            </chainedmapper>
        </pathconvert>
        <echo message="Collected controllers: ${app_controller_names}"/>

        <echo message="Injecting into app.js ..."/>
        <replaceregexp file="${app.dir}/app/app.js"
                       match="/\*ant-generated-content-start\*/(.*)/\*ant-generated-content-end\*/"
                       replace="/*ant-generated-content-start*/ ${app_controller_names} /*ant-generated-content-end*/"
                       byline="true"
                />
    </target>

    <target name="-after-build">
        <echo message="Reverting to original app.js ..."/>
        <replaceregexp file="${app.dir}/app/app.js"
                       match="/\*ant-generated-content-start\*/(.*)/\*ant-generated-content-end\*/"
                       replace="/*ant-generated-content-start*/ /*ant-generated-content-end*/"
                       byline="true"
                />
    </target>

</project>

这篇关于Sencha CMD:运行内置生产版本时出现404错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆