SeaJS入门

Sea.js是一种模块加载工具

官网:http://seajs.org/docs/

使用步骤:

1、下载sea.js

2、引入sea.js

3、加入配置代码

// seajs 的简单配置
seajs.config({
  base: "../sea-modules/",
  alias: {
    "jquery": "jquery/jquery/1.10.1/jquery.js"
  }
})

4、加载入口模块

//开发环境
  if (location.href.indexOf("?dev") > 0) {
    seajs.use("../static/hello/src/main");
  }
  // 生产环境
  else {
    seajs.use("examples/hello/1.0.0/main");
  }

 5、建立模块js,这是Sea.js 推荐的 CMD 模块书写格式

// 所有模块都通过 define 来定义
define(function(require, exports, module) {

  // 通过 require 引入依赖
  var $ = require('jquery');
  var Spinning = require('./spinning');

  // 通过 exports 对外提供接口
  exports.doSomething = ...

  // 或者通过 module.exports 提供整个接口
  module.exports = ...

});

>>下载小实例,更直观!

官方实例>>

http://www.tuicool.com/articles/bmuaEb

原文地址:https://www.cnblogs.com/tinyphp/p/4863170.html