【问题标题】:requireJs: dependencies not getting loaded for jseprequireJs:没有为 jsep 加载依赖项
【发布时间】:2015-03-11 11:29:51
【问题描述】:

这是我的配置

requirejs.config({
    baseUrl : 'vassets/lib/',
    shim : {
        'knockout' : [ 'jquery' ]
    },
    paths : {
        jquery : 'jquery/jquery.min',
        knockout : 'knockout/knockout',
        selectize : 'selectize.js/js/standalone/selectize.min',
        main : '/vassets/js/koapp/main',
        jsep : '/vassets/js/jsep/jsep.min'
    }
});

jsep 是 javascript 表达式解析器,可在此处获得 http://jsep.from.so/

这是我的模块定义:

define ()->
     require ['jsep'],(jsep)->
        console.log jsep
        # does not work, jsep is undefined

     ()->
        console.log jsep
        # does not work, jsep is available. but HOW????
        # I dont see this type of usage in api documnentation. How does this work?

另外下面的模块定义也不行

   define ['jsep'], (jsep)->
     console.log jsep
     # does not work
     # this is the normal usage I find in documentation, why this does not work???

可以

【问题讨论】:

标签: javascript coffeescript requirejs


【解决方案1】:

添加垫片,解决了问题。对于不实现定义功能的模块,如require js所要求的那样。垫片配置中需要导出配置。下面的配置使它工作。

requirejs.config({
    baseUrl : 'vassets/lib/',
    shim : {
        'knockout' : [ 'jquery' ],
    'jsep': {
      exports: 'jsep'
    }
    },
    paths : {
        jquery : 'jquery/jquery.min',
        knockout : 'knockout/knockout',
        selectize : 'selectize.js/js/standalone/selectize.min',
        main : '/vassets/js/koapp/main',
        jsep : '/vassets/js/jsep/jsep.min'
    }
});

【讨论】:

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