Mini-define
A simple front-end modular framework based on require implementation. If you don't want to spend time learning require.js, and don't want to look at long CMD/AMD specifications, then this mini-define is a good choice for you. If you've used Sea.js or require.js before, then mini-define is more efficient, lighter, and easier to use. Project Address: GitHub
Usage
First define the module
Defining modules
One: Define the module with define function
1.1 Depending on whether there are dependencies, there are two situations:
1.1.1: No dependent modules
Copy Code code as follows:
Define (' id ', function () {
Put your code here
});
1.1.2: A dependent module
Copy Code code as follows:
Define (' id ', [' Modea ', ' Modeb '],function (a,b) {
Put your code here
});
1.2 Depending on the need to return processing results to external use, but also can be divided into two cases:
1.2.1 Have returned objects:
Copy Code code as follows:
Define (' id ', function () {
return {
Put your code here
}
});
1.2.2 does not return an object
Copy Code code as follows:
Define (' id ', function () {
Put your code here
});
Second: Calling the module with the Require () function
2.1 Depending on the number of modules requested, there are two possible scenarios:
2.1.1. Call a single module
Require (' Modeid ')
2.1.2. Calling multiple modules
Require ([' Modea ', ' modeb ']);
2.2 According to whether there is callback processing, but also can be divided into two cases:
2.2.1 has callback handler function
Copy Code code as follows:
Require (' Modeid ', function (mode) {
Put your code here
});
Require ([' Modea ', ' Modeb '],function (a,b) {
Put your code here
});
2.2.2 No callback processing
Require (' Modeid ');
Then in the Index.html page, refer to the desired module in turn
Copy Code code as follows:
<!--core module-->
<script src= "Lib/core/require.js" ></script>
<!--module--> for demonstration
<script src= "Lib/main.js" ></script>
<script src= "Lib/config.js" ></script>
<script src= "Lib/init.js" ></script>
The last is to use the way you like the Lib directory to merge compression, generate a min.js file. In the release of the application, the corresponding index.html also need to adjust:
Copy Code code as follows:
<script src= "Lib/min.js" ></script>
Advantages:
In contrast to Seajs.js or original require.js, the addition of comments to Hiberai lines of code used lightweight to describe all fat, is completely bone.
There is no advanced content, there is no complex skills, almost zero learning costs.