requirejs:模块加载(require)及定义(define)时的路径小结

2020-05-09 00:00:00 by 【6yang】, 117 visits, 收藏 | 返回
参考:https://www.cnblogs.com/lcngu/p/5712098.html
/**
 * main
 */
 
requirejs.config({
  baseUrl: 'https://xxxx.com/js',
  paths: {
    acecdn: 'https://xxxx.com/js', // 引入 cdn域路径
  },
  shim: {
    facebook: {
      export: 'FB',
    },
    colorpicker: ['jquery-ui'],
    timepicker: ['jquery-ui'],
  },
})
 
requirejs(extraJS, function () {
  for (var key in extraJS) {
    var execJS = arguments[key]
    console.log(typeof execJS, execJS['init'])
    if (!execJS) {
      continue
    }
 
    if (typeof execJS == 'function') {
      execJS()
      continue
    }
 
    if (typeof execJS == 'object' && execJS['init']) {
      execJS['init']()
      continue
    }
  }
})


// 模块引入 

define([
  'acecdn/libs/jquery.pagenation',
  'acecdn/libs/gridsort',
  'jquery-ui',
  'validate',
  'acecdn/libs/jquery.remaining-chars',
  'acecdn/libs/jquery.daterange',
  'acecdn/libs/jquery.fullscreen',
  /*'timepicker',*/
  'acecdn/libs/jquery.datetimerange',
  'uploader',
], function ( module, Gridsort) {

  /*Init*/
  var Init = {
    Modules: $.noop,
    //init game list
    index: function () {
      var that = this
    },
  }

  return {
    init: function () {
      Init.index()
    },
  }
})
分享到:
share

    图片原图

    loading

    loading