Require JS is ignoring my config

前端 未结 2 481
春和景丽
春和景丽 2020-12-09 18:07

I\'m having pretty simple directory structure for scripts:

/js/        <-- located in site root
    libs/
        jquery-1.10.1.min.js
        knockout-2.         


        
2条回答
  •  孤街浪徒
    2020-12-09 18:46

    Fixed the issue.

    My config was being loaded asynchronously, and therefore the config paths weren't set before my require statement was being called.

    As per the RequireJS docs Link here, I added a script call to my config before the require.js call. And removed the data-main attribute.

    var require = {
        baseUrl: '/js',
        paths: {
            'jquery':      'vendor/jquery/jquery-2.0.3.min',
            'picker':      'vendor/pickadate/picker.min',
            'pickadate':   'vendor/pickadate/picker.date.min'
        },
        shim: {
            'jquery': {
                exports: '$'
            },
            'picker':    ['jquery'],
            'pickadate': {
                deps:    ['jquery', 'picker'],
                exports: 'DatePicker'
            }
        }
    }
    

    All is now working

提交回复
热议问题