Code Monkey home page Code Monkey logo

angular-pc-demo's Introduction

运行此项目

  1. 克隆项目到本地
  2. 全局安装 gulp:npm install gulp -g
  3. 安装 gulp 插件:npm install
  4. 开发环境只要运行gulp less 然后在 web 服务器中打开 [app/index.html]
  5. 正式环境先运行gulp less再运行 gulp,然后在 web 服务器中打开 [build/index.html]。(即以 file:// 协议打开)是无效的。

项目结构

app:项目源码。开发的时候代码写在这里。
 |--directives:整个网站公用的指令写在这里面
 |--images:存放图片
 |--modules:用于存放各个模块,例如一个网站可以分成主页、用户中心等模块
 |--services:整个网站公用的服务写在这里面
 |--styles:整个网站公用的样式
 |--vendor:存放第三方代码库
 |--views:存放并不属于某个模块的模板,例如整个网站都会用到的页头和页脚
 |--app.js:路由表、config()、run()等代码块写在这里面
 |--bootstrap.js:程序的启动文件,用于配置 requireJS 的配置及启动应用
 |--index.html:应用入口页面

gulpfile.js:根据 app 文件夹里的源码生成适合生产环境使用的代码。会精简文件并重命名为 md5 文件名
package.json:用于声明 gulpfile.js 会用到的各种模块

[app/modules]里面的子模块包含各自的模板、指令等代码。如果某个指令、服务等会在其他模块里用到,你应该考虑把它加入到 [app/directives]等文件夹中。

若一个子模块也包含子模块,那么也应该根据此规则进行分割。例如项目有 用户中心 模块,但这个模块还包含 基本信息收货地址好友列表 等模块,那么就应该是这样的结构:

app/modules/customer:用户中心模块
 |--basic:基本信息模块
 |--address:收货地址模块
 |--friends:好友列表模块
 |--common.js:上面这些模块都用得到的代码,比如 API 接口

这样的结构易于将项目拆分,但是在声明路由的时候会比较麻烦:因为公用文件必须得先加载。上面的结构可能就需要这样声明路由:

$stateProvider
  .state( 'nav.customer' , { // 一个父状态用来加载公用文件
    abstract : true ,
    template : '<div ui-view></div>' ,
    resolve : {
      loadModule : asyncLoad( [ 'modules/customer/common' ] ) // 公用文件
    }
  } )
  .state( 'nav.customer.basic' , { // 子状态来加载各自的模板与代码
    url : '/customer/basic' ,
    templateUrl : 'modules/customer/basic/index.html' ,
    controller : 'CustomerBasicController' ,
    resolve : {
      loadModule : asyncLoad( [ 'modules/customer/basic/index' ] ) // 子状态自己的代码
    }
  } )
  // ...

angular-pc-demo's People

Contributors

danhonghai avatar wuyf123 avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.