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 with [email protected]:
$ spm install seajs-wrap
<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 中文文档.