README.md 3.38 KB
Newer Older
wangcong committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
###app模板工程介绍

####目录结构

> demo  
  > ├─config `构建脚本`  
  > ├─public  
  > ├─src  
  > │ ├─assets  
  > │ ├─utils  
  > │ ├─views  
  > ├─.eslintrc.js  
  > ├─.gitignore  
  > ├─.gitlab-ci.yml  
  > ├─.npmignore   
  > ├─app.config.json  `nr-os平台APP配置文件,收集APP所有信息`  
  > ├─babel.config.js  
  > ├─index.demo.js  `nr.os下模块打包入口`  
  > ├─package.json  
  > ├─README.md  
  > └─vue.config.js  

####创建APP工程
- dev.config.js 和 pro.config.js
```js
const path = require('path')
var config = {
    configureWebpack: {
        entry: {
          app: './index.demo.js',   //*****模块打包入口文件
        },
        devtool: 'source-map',     
        output: {
            filename: '[name].bundle.js',
            library: 'portal_application',
            libraryTarget: 'umd',
            libraryExport: 'default',
            umdNamedDefine: true,
            globalObject: 'this'
        },
        externals: {
          'vue': {
              root: 'Vue',
              commonjs: 'vue',
              commonjs2: 'vue',
              amd: 'vue'
          },
          jquery: 'jQuery',
          ['$']: 'jQuery',
          'vue-router': 'VueRouter',
          vuex: 'Vuex',
          iview: 'iview',
          iviewex: 'iviewex'
        },
        module: {
            rules: [
                {
                    test: /\.(mp4|flv|swf)(\?v=[0-9]\.[0-9]\.[0-9])?$/,
                    loader: "file-loader",
                    options: {
                      name: 'video/[name].[hash:7].[ext]'
                    }
                }
            ]
        },
        resolve: {
            alias: {  //*******全局定义的别名,只建议使用以下别名
                '@common': path.resolve(__dirname,'../../common'),
                '@components': path.resolve(__dirname,'../../components/src/views'),
                '@api': path.resolve(__dirname,'../../common/api'),
                '@utils': path.resolve(__dirname,'../../common/utils'),
                '@gcRoot': path.resolve(__dirname,'../../'),
            },
            extensions: ['.js', '.vue']
        },
    },
    css: { extract: false },
    lintOnSave: false,
    productionSourceMap: false,
}
module.exports = config

```

- app.config.json
```json5
{
  "name": "@gc/demo",
  "title": "测试App",
  "author": "admin",
  "keywords": "demo",
  "company": "久其软件",
  "type": false,
  "version": "v0.1",
  "license": "",
  "description": "",
  "icon":"icon-_ZSYshujuluru",
  "data": {
    "static": [         //**********app个性静态文件
      {"name": "vuex", "url": "static/lib/vuex.min.js"}
    ],
    "app": {
      "component": ["dist/app.bundle.js"] //**********不要修改
    },
    "config": [  //**********app入口参数
      {
        "title":"模版",
        "key":"code",
        "type": "array",
        "dataSource": {
          "api":"/api/define",
          "titleColumn":"title",
          "valueColumn": "code"
        }
      }
    ]
  }
}
```

####**注意事项**
- 模块命名规范 
- 模块互相引用,本模块的依赖应该包含被包含模块的依赖
- 定义了一些全局别名,每个模块强制使用。模块自己的别名建议不要设置,除非确定别人不会通过路径引用你的模块。
- 模块间的代码依赖方式,路径引用到组件的 index.js