Skip to content

seajs/seajs-wrap

Repository files navigation

seajs-wrap spm package Build Status

The Sea.js plugin for loading CommonJS modules directly.

It would wrap files with define(function(require, exports, module) {}) block so that you can load CommonJS modules without wrapping it first.

It could only load modules in the same domain, so please use it in developement environment.

Install

Install with spm@3.x:

$ spm install seajs-wrap

Usage

<script src="path/to/sea.js"></script>
<script src="path/to/seajs-wrap.js"></script>

<script>
seajs.use(['common'], function(Common) {
  var str = Common(); // 'CommonJS'
})
</script>
// common.js
// It is a CommonJS module
var example = 'CommonJS'
module.exports = function() {
  return example;
}
  • no wrap
<script>
seajs.use(['test.js?nowrap'], function() {
  // it would excute test.js without wrapping
})
</script>

For more details please visit 中文文档.