Quellcode durchsuchen

优化配置文件

daxiongYang vor 7 Jahren
Ursprung
Commit
1903dc7627

+ 3 - 3
README.md

@ -5,11 +5,11 @@
5 5
- 发布时,支持动态配置CDN静态资源/切换新旧版本
6 6
- 演示地址:[fast.demo.renren.io](http://fast.demo.renren.io) (账号密码:admin/admin)
7 7
8
![demo-screenshot_01](https://github.com/daxiongYang/renren-fast-vue/blob/master/screenshot_01.png)
8
![demo-screenshot_01](https://github.com/daxiongYang/renren-fast-vue/blob/master/demo-screenshot/01.png)
9 9
10
![demo-screenshot_02](https://github.com/daxiongYang/renren-fast-vue/blob/master/screenshot_02.png)
10
![demo-screenshot_02](https://github.com/daxiongYang/renren-fast-vue/blob/master/demo-screenshot/02.png)
11 11
12
![demo-screenshot_03](https://github.com/daxiongYang/renren-fast-vue/blob/master/screenshot_03.png)
12
![demo-screenshot_03](https://github.com/daxiongYang/renren-fast-vue/blob/master/demo-screenshot/03.png)
13 13
14 14
## 更新日志
15 15
每个版本的详细更改都记录在[release notes](https://github.com/daxiongYang/renren-fast-vue/releases)中。

screenshot_01.png → demo-screenshot/01.png


screenshot_02.png → demo-screenshot/02.png


screenshot_03.png → demo-screenshot/03.png


+ 17 - 14
gulpfile.js

@ -4,16 +4,19 @@ var path = require('path');
4 4
var del  = require('del');
5 5
6 6
var distPath    = path.resolve('./dist');
7
var version     = ''; // 版本号(静态资源文件夹名称)
8
var versionPath = ''; // 版本号路径(静态资源文件夹路径)
9
var env         = ''; // 环境
7
var version     = ''; // 版本号
8
var versionPath = ''; // 版本号路径
9
var env         = ''; // 运行环境
10 10
11
// 创建版本号 / 版本号路径
11
// 创建版本号(年月日时分)
12 12
(function () {
13 13
  var d = new Date();
14
  version = (d.getFullYear().toString().slice(2))
15
    + ((d.getMonth() + 1) >= 10 ? (d.getMonth() + 1) : '0' + (d.getMonth() + 1))
16
    + (d.getDate() >= 10 ? d.getDate() : '0' + d.getDate());
14
  var yy = d.getFullYear().toString().slice(2);
15
  var MM = d.getMonth() + 1 >= 10 ? (d.getMonth() + 1) : '0' + (d.getMonth() + 1)
16
  var dd = d.getDate() >= 10 ? d.getDate() : '0' + d.getDate()
17
  var HH = d.getHours() >= 10 ? d.getHours() : '0' + d.getHours()
18
  var MM = d.getMinutes() >= 10 ? d.getMinutes() : '0' + d.getMinutes()
19
  version = yy + MM + dd + HH + MM;
17 20
  versionPath = distPath + '/' + version;
18 21
})();
19 22
@ -21,27 +24,27 @@ var env         = ''; // 环境
21 24
gulp.task('build', $.shell.task([ 'node build/build.js' ]));
22 25
23 26
// 创建版本号目录
24
gulp.task('create:versionPath', ['build'], function () {
27
gulp.task('create:versionCatalog', ['build'], function () {
25 28
  return gulp.src(`${distPath}/static/**/*`)
26 29
    .pipe(gulp.dest(`${versionPath}/static/`))
27 30
});
28 31
29 32
// 替换${versionPath}/static/js/manifest.js window.SITE_CONFIG.cdnUrl占位变量
30
gulp.task('replace:cdnUrl', ['create:versionPath'], function () {
33
gulp.task('replace:cdnUrl', ['create:versionCatalog'], function () {
31 34
  return gulp.src(`${versionPath}/static/js/manifest.js`)
32 35
    .pipe($.replace(new RegExp(`"${require('./config').build.assetsPublicPath}"`, 'g'), 'window.SITE_CONFIG.cdnUrl + "/"'))
33 36
    .pipe(gulp.dest(`${versionPath}/static/js/`))
34 37
});
35 38
36
// 替换${versionPath}/static/config/index-${env}.js window.SITE_CONFIG.staticFileName配置变量
37
gulp.task('replace:staticFileName', ['create:versionPath'], function () {
39
// 替换${versionPath}/static/config/index-${env}.js window.SITE_CONFIG['version']配置变量
40
gulp.task('replace:version', ['create:versionCatalog'], function () {
38 41
  return gulp.src(`${versionPath}/static/config/index-${env}.js`)
39
    .pipe($.replace(/window.SITE_CONFIG\['staticFileName'\] = '.*'/g, `window.SITE_CONFIG['staticFileName'] = '${version}'`))
42
    .pipe($.replace(/window.SITE_CONFIG\['version'\] = '.*'/g, `window.SITE_CONFIG['version'] = '${version}'`))
40 43
    .pipe(gulp.dest(`${versionPath}/static/config/`))
41 44
});
42 45
43 46
// 合并${versionPath}/static/config/[index-${env}, init].js 至 ${distPath}/config/index.js
44
gulp.task('concat:config', ['replace:staticFileName'], function () {
47
gulp.task('concat:config', ['replace:version'], function () {
45 48
  return gulp.src([`${versionPath}/static/config/index-${env}.js`, `${versionPath}/static/config/init.js`])
46 49
    .pipe($.concat('index.js'))
47 50
    .pipe(gulp.dest(`${distPath}/config/`))
@ -56,7 +59,7 @@ gulp.task('default', ['clean'], function () {
56 59
  // 获取环境配置
57 60
  env = process.env.npm_config_qa ? 'qa' : process.env.npm_config_uat ? 'uat' : 'prod'
58 61
  // 开始打包编译
59
  gulp.start(['build', 'create:versionPath', 'replace:cdnUrl', 'replace:staticFileName', 'concat:config'], function () {
62
  gulp.start(['build', 'create:versionCatalog', 'replace:cdnUrl', 'replace:version', 'concat:config'], function () {
60 63
    // 清除, 编译 / 处理项目中产生的文件
61 64
    del([`${distPath}/static`, `${versionPath}/static/config`])
62 65
  })

+ 0 - 0
src/filters/index.js


+ 2 - 2
src/mock/create.js

@ -1,5 +1,5 @@
1 1
import Mock from 'mockjs'
2
import requestUrl from '@/api/requestUrl'
2
import http from '@/utils/http'
3 3
import merge from 'lodash/merge'
4 4
5 5
/**
@ -23,7 +23,7 @@ export default function (mods, isOpen = true) {
23 23
        console.log('\n')
24 24
25 25
        // 2种url拦截方式
26
        Mock.mock(requestUrl(mod.url), mod.type, mod.data)
26
        Mock.mock(http.adronUrl(mod.url), mod.type, mod.data)
27 27
        Mock.mock(new RegExp(mod.url, 'g'), mod.type, mod.data)
28 28
      }
29 29
    }

+ 4 - 4
src/router/index.js

@ -12,8 +12,8 @@ Vue.use(Router)
12 12
export default new Router({
13 13
  mode: 'hash',
14 14
  routes: [
15
    { path: '/404', component: _import('common/404'), name: '404', desc: '404未找到' },
16
    { path: '/login', component: _import('common/login'), name: 'login', desc: '登录' },
15
    { path: '/404', component: _import('error/404'), name: '404', desc: '404未找到' },
16
    { path: '/login', component: _import('login/index'), name: 'login', desc: '登录' },
17 17
    {
18 18
      path: '/',
19 19
      component: _import('main'),
@ -22,8 +22,8 @@ export default new Router({
22 22
      desc: '主入口整体布局',
23 23
      children: [
24 24
        // 通过isTab属性, 设定是否通过tab标签页展示内容
25
        { path: '/home', component: _import('common/home'), name: 'home', desc: '首页' },
26
        { path: '/theme', component: _import('common/theme'), name: 'theme', desc: '主题' },
25
        { path: '/home', component: _import('home/index'), name: 'home', desc: '首页' },
26
        { path: '/theme', component: _import('theme/index'), name: 'theme', desc: '主题' },
27 27
        { path: '/job/schedule', component: _import('modules/job/schedule'), name: 'schedule', desc: '定时任务', meta: { isTab: true } },
28 28
        { path: '/oss', component: _import('modules/oss/index'), name: 'oss', desc: '文件上传', meta: { isTab: true } },
29 29
        { path: '/sys/config', component: _import('modules/sys/config'), name: 'config', desc: '参数管理', meta: { isTab: true } },

src/views/common/404.vue → src/views/error/404.vue


src/views/common/home.vue → src/views/home/index.vue


src/views/common/login.vue → src/views/login/index.vue


src/views/common/theme.vue → src/views/theme/index.vue


+ 0 - 0
static/.gitkeep


+ 4 - 9
static/config/index-prod.js

@ -7,13 +7,8 @@
7 7
  // api接口请求地址
8 8
  window.SITE_CONFIG['baseUrl'] = 'http://demo.renren.io/renren-fast';
9 9
10
  // 嵌套iframe地址
11
  window.SITE_CONFIG['nestIframeUrl'] = 'http://demo.renren.io/renren-fast';
12
  // 嵌套iframe路由名称列表
13
  window.SITE_CONFIG['nestIframeRouteNameList'] = ['sql'];
14
15
  // 静态资源文件夹名称
16
  window.SITE_CONFIG['staticFileName'] = '';
17
  // cdn地址
18
  window.SITE_CONFIG['cdnUrl'] = './' + window.SITE_CONFIG.staticFileName;
10
  // cdn地址 = 域名 + 版本号
11
  window.SITE_CONFIG['domain']  = './'; // 域名
12
  window.SITE_CONFIG['version'] = '';   // 版本号(年月日时分)
13
  window.SITE_CONFIG['cdnUrl']  = window.SITE_CONFIG.domain + window.SITE_CONFIG.version
19 14
})();

+ 4 - 9
static/config/index-qa.js

@ -7,13 +7,8 @@
7 7
  // api接口请求地址
8 8
  window.SITE_CONFIG['baseUrl'] = 'http://demo.renren.io/renren-fast';
9 9
10
  // 嵌套iframe地址
11
  window.SITE_CONFIG['nestIframeUrl'] = 'http://demo.renren.io/renren-fast';
12
  // 嵌套iframe路由名称列表
13
  window.SITE_CONFIG['nestIframeRouteNameList'] = ['sql'];
14
15
  // 静态资源文件夹名称
16
  window.SITE_CONFIG['staticFileName'] = '';
17
  // cdn地址
18
  window.SITE_CONFIG['cdnUrl'] = './' + window.SITE_CONFIG.staticFileName;
10
  // cdn地址 = 域名 + 版本号
11
  window.SITE_CONFIG['domain']  = './'; // 域名
12
  window.SITE_CONFIG['version'] = '';   // 版本号(年月日时分)
13
  window.SITE_CONFIG['cdnUrl']  = window.SITE_CONFIG.domain + window.SITE_CONFIG.version
19 14
})();

+ 4 - 9
static/config/index-uat.js

@ -7,13 +7,8 @@
7 7
  // api接口请求地址
8 8
  window.SITE_CONFIG['baseUrl'] = 'http://demo.renren.io/renren-fast';
9 9
10
  // 嵌套iframe地址
11
  window.SITE_CONFIG['nestIframeUrl'] = 'http://demo.renren.io/renren-fast';
12
  // 嵌套iframe路由名称列表
13
  window.SITE_CONFIG['nestIframeRouteNameList'] = ['sql'];
14
15
  // 静态资源文件夹名称
16
  window.SITE_CONFIG['staticFileName'] = '';
17
  // cdn地址
18
  window.SITE_CONFIG['cdnUrl'] = './' + window.SITE_CONFIG.staticFileName;
10
  // cdn地址 = 域名 + 版本号
11
  window.SITE_CONFIG['domain']  = './'; // 域名
12
  window.SITE_CONFIG['version'] = '';   // 版本号(年月日时分)
13
  window.SITE_CONFIG['cdnUrl']  = window.SITE_CONFIG.domain + window.SITE_CONFIG.version
19 14
})();

+ 4 - 9
static/config/index.js

@ -7,13 +7,8 @@
7 7
  // api接口请求地址
8 8
  window.SITE_CONFIG['baseUrl'] = 'http://dev.demo.renren.io/renren-fast';
9 9
10
  // 嵌套iframe地址
11
  window.SITE_CONFIG['nestIframeUrl'] = 'http://dev.demo.renren.io/renren-fast';
12
  // 嵌套iframe路由名称列表
13
  window.SITE_CONFIG['nestIframeRouteNameList'] = ['sql'];
14
15
  // 静态资源文件夹名称
16
  window.SITE_CONFIG['staticFileName'] = '';
17
  // cdn地址
18
  window.SITE_CONFIG['cdnUrl'] = './' + window.SITE_CONFIG.staticFileName;
10
  // cdn地址 = 域名 + 版本号
11
  window.SITE_CONFIG['domain']  = './'; // 域名
12
  window.SITE_CONFIG['version'] = '';   // 版本号(年月日时分)
13
  window.SITE_CONFIG['cdnUrl']  = window.SITE_CONFIG.domain + window.SITE_CONFIG.version
19 14
})();

+ 8 - 30
static/config/init.js

@ -1,11 +1,11 @@
1 1
/**
2 2
 * 动态加载初始资源
3 3
 */
4
;(function(window, document) {
4
;(function() {
5 5
  var resList = {
6 6
    icon: window.SITE_CONFIG.cdnUrl + '/static/img/favicon.ico',
7 7
    css: [
8
      window.SITE_CONFIG.cdnUrl + '/static/css/app.css'
8
      window.SITE_CONFIG.cdnUrl + '/static/css/app.css',
9 9
    ],
10 10
    js: [
11 11
      window.SITE_CONFIG.cdnUrl + '/static/js/manifest.js',
@ -17,7 +17,6 @@
17 17
18 18
  // 图标
19 19
  (function () {
20
    document.getElementsByTagName('html')[0].style.opacity = 0;
21 20
    var _icon = document.createElement('link');
22 21
    _icon.setAttribute('rel', 'shortcut icon');
23 22
    _icon.setAttribute('type', 'image/x-icon');
@ -27,46 +26,25 @@
27 26
28 27
  // 样式
29 28
  (function () {
30
    document.getElementsByTagName('html')[0].style.opacity = 0;
31
    var i = 0;
32
    var _style = null;
33
    var createStyles = function () {
34
      if (i >= resList.css.length) {
35
        document.getElementsByTagName('html')[0].style.opacity = 1;
36
        return;
37
      }
29
    var _script = null;
30
    for (var i = 0; i < resList.css.length; i++) {
38 31
      _style = document.createElement('link');
39 32
      _style.href = resList.css[i];
40 33
      _style.setAttribute('rel', 'stylesheet');
41
      _style.onload = function () {
42
        i++;
43
        createStyles();
44
      }
45 34
      document.getElementsByTagName('head')[0].appendChild(_style);
46 35
    }
47
    createStyles();
48 36
  })();
49 37
50 38
  // 脚本
51
  var isLoad = false;
52 39
  document.onreadystatechange = function () {
53
    if (!isLoad && (document.readyState === 'interactive' || document.readyState === 'complete')) {
54
      isLoad = true;
55
      var i = 0;
40
    if (document.readyState === 'complete') {
56 41
      var _script = null;
57
      var createScripts = function () {
58
        if (i >= resList.js.length) {
59
          return;
60
        }
42
      for (var i = 0; i < resList.js.length; i++) {
61 43
        _script = document.createElement('script');
62 44
        _script.src = resList.js[i];
63
        _script.onload = function () {
64
          i++;
65
          createScripts();
66
        }
45
        _script.async = false
67 46
        document.getElementsByTagName('body')[0].appendChild(_script);
68 47
      }
69
      createScripts();
70 48
    }
71 49
  };
72
})(window, document);
50
})();