【问题标题】:Sencha CMD: 404 errors when running built production versionSencha CMD:运行构建的生产版本时出现 404 错误
【发布时间】:2013-02-07 15:57:23
【问题描述】:

我已将现有的 ExtJS 4.1.3 应用程序转换为使用 Sencha CMD 推荐的结构和工具。我先创建了结构,然后把我现有的app JS文件放在单页JS app应该放在的地方。

我目前在以下位置访问我的应用程序的开发版本:

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

其中swsSencha workspacedtSencha single-page app。到目前为止,我相信没有问题。然后我运行命令:

sencha app build

在我的app 的目录中。这完成了几个Yui Compressor Warning (Trailing comma is not legal in an ECMA-262 object initializer 警告,但没有错误。所以我 production index.jsp 页面(它使用all-classes.js 文件,它接收上面app build 命令的串联输出)在 URL:

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

all-classes.js 尝试加载几个理论上应该包含在自身中的文件时,就会出现问题。其中包括 app.js 中指定的控制器。

为什么这些文件没有在all-classes.js 中连接?下面是 Chrome 尝试从 all-classes.js 加载它们的屏幕截图,当然找不到它们。

我尝试了什么? 试图通过requires 调整我的app.js要求 控制器;或按照question/answer pair 的建议通过uses 提供所需的课程,但无济于事。

【问题讨论】:

  • 有些奇怪...我使用相同的结构,我使用sencha generate app 生成我的应用程序,它适用于我...在您的情况下,只有您的自定义类不加载?
  • @bhovhannes 除了我自己的模型类引用的名为belongsto.jshasmany.js 的文件之外,还有一些控制器和一些自定义类;实际上只有这些模型类 AppWindow 没有加载。会尝试与他们play,但我真的不明白为什么我在开发中看不到任何问题,而且在生产中它根本不起作用。

标签: extjs extjs4 sencha-cmd


【解决方案1】:

尝试在app.jsusesrequires 部分中包含您需要的所有类。

请注意,如果控制器需要一些视图,您可以在 app.js 的 require 部分中省略该视图,因为无论如何当 sencha 工具将解析您的控制器时它都会包含在内。

将文件添加到app.jsuses/requires 部分时,请尝试使用完整路径。也就是说,写MyApp.controller.pages.HomeMyApp.store.users.List 但现在写pages.Homeusers.List

您可以在 sencha 工具的 YUI 最小化阶段开始之前使用 -before-build-after-build Ant 目标来修改您的 app.js。
就我而言,我最终搜索了app/controller 文件夹中的所有控制器,并将它们的名称添加到app.jsuses 部分。这已经足够了,因为我的控制器中需要其他需要的类。

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

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

我的app.js

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

    controllers: [
        "main.App"
    ],

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

我的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>

【讨论】:

    【解决方案2】:

    我仍然不完全理解问题,但这是我为解决问题所做的。

    我有两个模型; App.jsWindow.js 分别具有 hasManybelongsTo 关系。在App.js:

    associations: [{
        type : 'hasMany',
        model: 'WD.model.Window',
        name : 'windows'
    }]
    

    Window.js 我有:

    associations: [{
        type : 'belongsTo',
        model: 'WD.model.App',
        associationKey: 'appId'
    }]
    

    我开始怀疑这些部分是导致问题的原因,因为它们是唯一提供404 的 ExtJS 模块;提供404 的其他模块取决于使用hasManybelongsTo 的模型文件。

    我只是删除了上面粘贴的associations sn-ps(因为现在我没有使用它们,因为它们并没有真正起作用,因为我仍然需要自己加载数据,而不是自动加载孩子)。然后重新运行sencha app build,生产版本工作正常!

    如果有人(尤其是 Sencha 的人)确切地知道我的笨拙修复工作的原因,请回答下面的问题或评论,我会更新答案。

    感谢@bhovhannes 的回答,这仍然导致对问题的有用洞察; +1ed。

    【讨论】:

    • 您是否尝试在App.js 的顶部添加Ext.require('WD.model.Window') 和在Window.js 的顶部添加Ext.require('WD.model.App')?也许煎茶工具没有通过associations ...
    • @bhovhannes 是的,我做到了;没用,如果有效,那就太丑了……因为它应该通过它们。
    【解决方案3】:

    我也有同样的问题,, 为了解决这个问题,我只需更改类的名称。我使用 SenchaCmd 3.1.xx 和 Sencha Touch 2.2 构建

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-11-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多