Step 1: Download SeaJS

  1. Download it at github.com/seajs/seajs
  2. Find sea-.js in the dist folder

Step 2: Import sea-.js and use the main entry file

Seajs specifies the main entry file

<script src="sea.js"></script>
<script>
    seajs.use('./index.js');
</script>
Copy the code

Entry file:

define(function(require.exports.module) {
    require('./bar')})Copy the code

The js module to be exported is written as follows:

define(function(require.exports.module) {
    const name = 'Arvin';
    const age = 18;
    
    // The following two methods can be used, similar to the common.js specification
    // exports.name = name;
    // exports.age = age;
	
    module.exports = {
        name,
        age
    }
})
Copy the code

The js module to be imported is written as follows:

define(function(require.exports.module) {
    const foo = require('./foo');
    console.log(foo.name);  //Arvin
    console.log(foo.age);  / / 18
})
Copy the code