繁体   English   中英

JSHint和grunt.js-未定义Highcharts

[英]JSHint and grunt.js - Highcharts is not defined

我正在使用Angular应用程序,一旦我对运行grunt.js的所有内容感到满意,就可以在所有内容都最小化的地方构建发行版,现在我的问题就开始了。 如果未缩小文件,则所有Highcharts都可以正常工作,一旦缩小js文件,我将得到错误Highcharts的定义。

highcharts的部分代码,在此我会提示有些错误,请参阅注释以获取错误:

function createDevicesChart (title) {
    Highcharts.setOptions ({ //error Highcharts is not defined, unresolved variable Highcharts, unresolved function setOptions
        lang: {rangeSelectorZoom: ''},
        colors: ['#F4D00B']
    });
    Highcharts.RangeSelector.prototype.render = (function (func) { //error Highcharts is not defined, unresolved variable Highcharts, unresolved variable RangeSelector
        return function () {
            func.apply (this, arguments);
            var leftPosition = this.chart.plotLeft,
            topPosition = this.chart.plotTop,
            space = 1;
            var widthChart = this.chart.chartWidth;
            var widthChartHolder = $ ('.highcharts-container >svg').width ();
            //console.log(widthChartHolder);
            for (var i = 0; i < this.buttons.length; i++) {
                this.buttons[i].attr ({
                    x: widthChartHolder - leftPosition - 41,
                    y: topPosition - 77
                });
                leftPosition += this.buttons[i].width + space;
            }
        };
    } (Highcharts.RangeSelector.prototype.render));//error Highcharts is not defined, unresolved variable RangeSelector

        .........//rest of the code 


    angular.element('#devices_chart').highcharts ('StockChart', chartingOptions); //unresolved function or method highcharts()

}

.jshintrc文件:

    {
      "node": true,
      "browser": true,
      "esnext": true,
      "bitwise": true,
      "camelcase": true,
      "curly": true,
      "eqeqeq": true,
      "immed": true,
      "indent": 2,
      "latedef": true,
      "newcap": true,
      "noarg": true,
      "quotmark": "single",
      "regexp": true,
      "undef": true,
      "unused": true,
      "strict": true,
      "trailing": true,
      "smarttabs": true,
      "globals": {
        "angular": false,
        "Highcharts"  : false
      }

}

有人可以帮帮我吗? 我在这里真的很挣扎:(非常感谢

编辑:即使我为Highcharts用错误的值更新了jshintr,当我运行grunt作业时,它会缩小所有代码,并且我再次在控制台中得到错误:

ReferenceError: Highcharts is not defined
    at m (http://localhost/myAPP/dist/scripts/scripts.js:1:3021)
    at link (http://localhost/myAPP/dist/scripts/scripts.js:1:3125)
    at http://localhost/myAPP/dist/scripts/vendor.js:4:20180
    at s (http://localhost/myAPP/dist/scripts/vendor.js:4:14727)
    at h (http://localhost/myAPP/dist/scripts/vendor.js:4:10779)
    at h (http://localhost/myAPP/dist/scripts/vendor.js:4:10796)
    at http://localhost/myAPP/dist/scripts/vendor.js:4:10402
    at http://localhost/myAPP/dist/scripts/vendor.js:7:19333
    at s (http://localhost/myAPP/dist/scripts/vendor.js:4:14727)
    at h (http://localhost/myAPP/dist/scripts/vendor.js:4:10779) <div id="devices_chart" class="ng-isolate-scope"> 

您必须告诉jshint如何处理此类全局变量。

在项目的根目录下创建一个.jshintrc配置文件,其中包含:

{
    // JSHint Default Configuration File (as on JSHint website)
    // See http://jshint.com/docs/ for more details

    //[...] // global conf ... see docs

    // Custom Globals
    "globals" : {
        "Highcharts"  : false //here is what you need
    }
}

参见http://jshint.com/docs/

这是Grunt配置中的jshintrc选项,您可能错过了。

grunt.initConfig({
    jshint: {
        options: {
            jshintrc: true
        }
    }
});

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM