缩小后不会显示JavaScript错误

时间:2016-01-09 13:40:03

标签: javascript r.js

我使用r.js来缩小基于cordova的项目中的js文件。未经授权的代码工作正常,但在缩小后没有任何工作,甚至console.log工作(它被放置在从index.html文件加载的文件的第一行),甚至没有抛出单个错误。

所以,我想检查缩小代码是否会抛出任何错误,即使未经编译的代码有错误也是如此。所以,我更改了一些代码(通过从appp将对象名称更改为app,并调用app.initialize),以便我可以在控制台中获取错误(在未编译的版本中)。正如预期的那样,我在控制台中遇到了未经授权的代码版本的错误,因为相同代码的缩小版本(有错误)不会引发任何错误。

我应该在缩小的代码中遇到错误,即使错误是明白的。首先我没有得到任何错误。所以我不知道为什么在缩小之后没有任何工作,如果我得到一些错误然后我可以找到缩小代码的确切问题。我不知道为什么会发生这种情况。

我在这里做错了什么吗?

的index.html

<!DOCTYPE html>

<html>
    <head>
      <meta charset="utf-8" />
      <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, target-densitydpi=medium-dpi, user-scalable=0" />

      <meta http-equiv="Content-Security-Policy" content="default-src *; style-src 'self' 'unsafe-inline'; script-src 'self' https://* 'unsafe-inline' 'unsafe-eval'"/>

      <title>Title</title>

  </head>

    <body>
        <div id="mainContainer">
            <!-- rootviewTpl -->
        </div>
        <div id="modals-demo">
            <div class="row">
                <div class="col s12">
                    <div id="modal" class="modal"></div>
                </div>
            </div>
        </div>

        <div class="loader" id="loader">
        </div>

        <script type="text/javascript" src="cordova.js"></script>
        <script src="lib/js/lock-7.10.3.js"></script>
        <script src="lib/js/winstore-jscompat.js"></script>
        <script src="lib/js/jwt-decode.min.js"></script>
        <script type="text/javascript" src="js/config-variables.js"></script>
        <script data-main="js/index.js" src="lib/js/require-2.0.0.js"></script>

    </body>
</html>

index.js

define([
    "./config"
    ], function(){

    var app = {
        initialize: function() {
            this.bindEvents();
        },
        bindEvents: function() {
            document.addEventListener('deviceready', this.onDeviceReady, false);
        },
        onDeviceReady: function() {
            require(["js/database/FTMobileDatabase"]);
        }
};

app.initialize();

});

config.js:

&#13;
&#13;
requirejs.config({
  baseUrl: "lib/js",
  paths: {
    js: "../../js",
    templates:"../../templates",
    jquery:"jquery.min",
    underscore:"underscore.min",
    backbone:"backbone",
    handlebars:"handlebars",
    marionette:"backbone.marionette.min",
    d3: "d3",
    "d3.chart": "d3.chart",
    //materialze library
    velocity:"velocity.min",
    hammerjs:"hammer.min",
    materialize:"materialize.min",
    //date libraries
    moment:"moment",
    hbs: 'require-handlebars-plugin/hbs'
  },
  shim:{
    "jquery":{
      deps:[],
      exports:"jquery"
    },        
    "underscore": {
      deps:[],
      exports: "_"
    },
    "backbone": {
      deps: ["jquery", "underscore"],
      exports: "Backbone"
    },
    "marionette":{
      deps:["backbone"],
      exports:"Marionette"
    },
    "handlebars":{
      deps:[],
      exports:"Handlebars"
    },
    "d3": {
      deps:[],
      exports: "d3"
    },
    "d3.chart": {
      deps: ["d3"],
      exports: "d3Chart"
    },
    "materialize":{
      deps:["jquery","velocity","hammerjs"],
      exports:"materialize"
    },
    "moment":{
      deps:[],
      exports:"moment"
    },
    hbs: { // optional
      helpers: true,            // default: true
      templateExtension: 'hbs', // default: 'hbs'
      partialsUrl: ''           // default: ''
    }
  },
  waitSeconds: 0
});
&#13;
&#13;
&#13;

build.json:

({
    appDir: "./www",
    dir:"./www",
    mainConfigFile:"./www/js/config.js",
    modules:[
      {
        name:"js/index",
        include:[
          "js/database/FTMobileDatabase"
        ],
        exclude:[
          "js/config"
        ]
      }
    ],
    preserveLicenseComments: false,
    allowSourceOverwrites: true,
    keepBuildDir:true
})

0 个答案:

没有答案