This project is based on the requirements of my company project, may be applicable to many other projects.
Prepare the gulp environment.
First you can create a project using gulp, configure the Gulpfile.js file, I put gulpfile.js under the root directory
See here for specific configuration and installation command methods
My project directory
My project directory is like this:
==build// Project build directory | HTML//html file directory | Images //Picture file directory | javascripts//javascript file directory | Libs //JS Library File | stylesheets//Style file directory ==gulpfile.js
The AVALONJS used in the program can beOver hereSee, at the same time s used theMmrouter The main files are as follows
When you see the following you will find a slideout.js file, this is our mobile side of the sidebar, I was to take someone else's code to use their own, see here
Main.html
The build directory
<! DOCTYPE html>
Avalon.mobile.min.js in the build directory
The main main.jsUnder the Build/javascripts directory
require.config ({//config avalonjsbaseurl: ' javascripts ',//base path paths: { Avalon: '. /avalon.mobile.min.js '},shim: {avalon: {exports: ' Avalon '}},debug:false}); require ([' Avalon ', ' ready! ', ' libs/ Mmstate '], function (Avalon) {Console.log (Avalon);//define the top-level Vmavalon.define ({$id: ' main ', slideoutclose:function () { Slideout.close ();}}); /define various states, the internal will be converted to a routing table, to Mmrouter to handle avalon.state (' index ', {controller: ' main ', url: '/', Views: {': {templateurl: ' Templates/index.html '//templates under the index.html Fragment}},onbeforeenter:function () {require ([' index '], function (index) { Index.init ();});},onerror:function (err) {Avalon.log (err);}}); Avalon.state (' Test ', {controller: ' main ', url: '/test ', Views: {': {templateurl: ' templates/test.html '// Templates test.html Fragment}},onbeforeenter:function () {require ([' test '], function (test) {test.init ();});},onerror: function (Err) {Avalon.log (err);}}); /Start History Manager Avalon.history.start ({basepath: '/app '});//Start scanning Avalon.scan ();});
Path Build/templatesThe following two paragraphs are HTML fragmentsIndex.html Fragment
<div ms-controller= "index" id= "index" > <p ms-text= "TestName" ></p></div>
Test.html Fragment
<div ms-controller= "Test" > <p ms-text= "TestName" ></p></div>
Libs fileThe required JS files are delegated in Libs, including Mmstate, Mmhistory, Mmrouter, etc.
Finally, use the Gulp command to generate the assets directory referenceHttps://github.com/gulpjs/gulp
Https://github.com/baixiaosh/avalon
Https://github.com/RubyLouvre/mmRouter
Https://github.com/baixiaosh/slideout
If there is anything wrong with this article, I hope the gods will point it out so as not to mislead other men, thank you.
This address: http://www.cnblogs.com/baixiaosheng/p/4390253.html
Use Gulp to build Avalon-based mobile projects