Created
January 23, 2017 06:01
-
-
Save anonymous/09232b42fd14e6db54afc8e2231cfed5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * @file grunt 的一些配置 | |
| * @author ji.yang@joudou.com | |
| * | |
| * 根目录public | |
| */ | |
| var pages = ['stock/js/main', | |
| 'wx/js/mmsg', | |
| 'wx/js/private', | |
| 'wx/js/internal', | |
| 'wx/js/strategies', | |
| 'wx/js/strategy' | |
| ]; | |
| module.exports = { | |
| css: [ | |
| 'css/style.css', | |
| 'chart/css/style.css', | |
| // 'chunxunying/css/style.css', | |
| // 'ganhuo/css/style.css', | |
| // 'admin/css/style.css', | |
| 'msg/css/index.css', | |
| 'msg/css/second.css', | |
| 'msg/css/hot.css', | |
| 'msg/css/search.css', | |
| 'msg/css/macro.css', | |
| 'annual/css/style.css', | |
| 'stock/css/search.css', | |
| 'stock/css/main.css', | |
| 'stock/css/charts.css', | |
| 'tally/css/rank.css', | |
| 'tally/css/yieldCurve.css', | |
| 'wx/css/articles.css', | |
| 'wx/css/seculist.css', | |
| 'wx/css/secuinfo.css', | |
| 'wx/css/mmsg.css', | |
| 'wx/css/private.css', | |
| 'wx/css/internal.css', | |
| 'wx/css/merger.css', | |
| 'wx/css/home.css', | |
| 'wx/css/strategies.css', | |
| 'wx/css/strategy.css' | |
| ], | |
| js: [ | |
| 'chart/js/main', | |
| // 'ganhuo/js/main', | |
| // 'chunxunying/js/main', | |
| 'msg/js/index', | |
| 'msg/js/second', | |
| 'msg/js/hot', | |
| 'msg/js/search', | |
| 'msg/js/macro', | |
| 'annual/js/main', | |
| 'stock/js/search', | |
| 'stock/js/main', | |
| 'stock/js/charts', | |
| 'tally/js/rank', | |
| 'tally/js/yieldCurve', | |
| 'wx/js/articles2', | |
| 'wx/js/seculist', | |
| 'wx/js/secuinfo', | |
| 'wx/js/mmsg', | |
| 'wx/js/private', | |
| 'wx/js/internal', | |
| 'wx/js/merger', | |
| 'wx/js/strategies', | |
| 'wx/js/strategy' | |
| ], | |
| components: [ | |
| { | |
| file: 'component/stockSearch/main2', | |
| dependBy: pages | |
| }, | |
| { | |
| file: 'component/bottomNav/main', | |
| dependBy: pages | |
| } | |
| ] | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * @file 获取copy配置 | |
| * @author ji.yang@joudou.com | |
| * | |
| */ | |
| module.exports = function() { | |
| var options = { | |
| icomoon: { | |
| files: [ | |
| { | |
| expand: true, | |
| cwd: 'public/css/icomoon/', | |
| dest: 'public/asset/css/icomoon/', | |
| src: [ | |
| '**/*.*' | |
| ] | |
| } | |
| ] | |
| }, | |
| view: { | |
| files: [ | |
| { | |
| expand: true, | |
| cwd: 'app/viewSrc', | |
| dest: 'app/views', | |
| src: [ | |
| '**/*.*' | |
| ] | |
| } | |
| ] | |
| } | |
| }; | |
| return options; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * @file grunt rev 的配置 | |
| * @author ji.yang@joudou.com | |
| */ | |
| var config = require('./config'); | |
| var path = require('path'); | |
| var _ = require('lodash'); | |
| var css = _.union(config.css, [ | |
| 'css/icomoon/style.css' | |
| ]); | |
| module.exports = function () { | |
| var options = { | |
| options: { | |
| algorithm: 'md5', | |
| length: 8, | |
| } | |
| }; | |
| // 打包到各自的目录 | |
| var number = 0; | |
| function getName(file) { | |
| number++; | |
| return 'filerev' + number + file; | |
| } | |
| function setOption(location, file) { | |
| options[getName(file)] = { | |
| src: [location], | |
| dest: path.dirname(location) | |
| } | |
| } | |
| css.forEach(function (file) { | |
| var location = path.join(__dirname + '/../public/asset/' + file); | |
| setOption(location, file); | |
| }); | |
| config.js.forEach(function (file) { | |
| var location = path.join(__dirname + '/../public/asset/' + file + '.js'); | |
| setOption(location, file); | |
| }); | |
| // 全部打包到一个目录 | |
| // var src = []; | |
| // config.css.forEach(function (file) { | |
| // src.push(path.join(__dirname + '/../' + file)); | |
| // }); | |
| // config.js.forEach(function (file) { | |
| // src.push(path.join(__dirname + '/../public/asset/' + file + '.js')); | |
| // }); | |
| // options.asset = { | |
| // src: src, | |
| // dest: 'public/asset/md5' | |
| // } | |
| return options; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * @file 获取需要通过less 打包的配置 | |
| * @author ji.yang@joudou.com | |
| * | |
| * 根目录public | |
| */ | |
| var files = require('./config').css; | |
| module.exports = function() { | |
| var options = { | |
| dist: { | |
| options: { | |
| compress: process.env.NODE_ENV == 'local' ? false : true | |
| } | |
| } | |
| }; | |
| var result = {}; | |
| files.forEach(function(file) { | |
| result['public/asset/' + file] = 'public/' + file.substr(0, file.length - 4) + '.less'; | |
| // 这个文件是给本地调试用的 | |
| if (process.env.NODE_ENV == 'local') { | |
| result['public/' + file] = 'public/' + file.substr(0, file.length - 4) + '.less'; | |
| } | |
| }); | |
| options.dist.files = result; | |
| return options; | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * @file 根据config生成grunt-newer-explicit的配置 | |
| * @author yu.zhao@joudou.com | |
| * | |
| * 根目录public | |
| */ | |
| var path = require('path'); | |
| var fs = require('fs'); | |
| var files = require('./config').js; | |
| var components = require('./config').components; | |
| module.exports = function () { | |
| var options = {}; | |
| files.forEach(function (file) { | |
| options[file] = { | |
| src: [path.join(__dirname, '../public', file +'.js')], | |
| dest: path.join(__dirname, '../public/asset/', file + '.js'), | |
| options: { tasks: ["requirejs:" + file] } | |
| } | |
| }); | |
| components.forEach(function (file) { | |
| options[file.file] = { | |
| src: [path.join(__dirname, '../public', file.file +'.js')], | |
| dest: path.join(__dirname, '../public/asset/', file.file + '.js'), | |
| options: { | |
| tasks: file.dependBy.reduce(function (prev, f) { | |
| prev.push("touch:" + f, "requirejs:" + f); | |
| return prev; | |
| }, ["requirejs:" + file.file]) | |
| } | |
| } | |
| }); | |
| return options; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * @file replace 打包的配置 | |
| * @author ji.yang@joudou.com | |
| * | |
| * 根目录public | |
| */ | |
| var path = require('path'); | |
| var traverse = require('../app/utils/traverse'); | |
| var config = require('./config'); | |
| module.exports = function(grunt) { | |
| var obj = {}; | |
| var options = {}; | |
| var number = 0; | |
| traverse(path.join(__dirname, '../app/viewSrc'), function (dir, fullPath) { | |
| obj[dir] = obj[dir] || []; | |
| obj[dir].push(fullPath); | |
| }); | |
| for (var k in obj) { | |
| number++; | |
| options['replace' + number + path.relative(path.join(__dirname, '../'), k)] = { | |
| options: { | |
| patterns: [ | |
| { | |
| match: /[\.\/\w]+\.css/gm, | |
| replacement: (function () { | |
| var relativePath = path.relative(path.join(__dirname, '../app/viewSrc/'), k); | |
| return function (file) { | |
| var summary = grunt.filerev.summary; | |
| var abs = path.join(__dirname, '../public/asset/', relativePath, file); | |
| if (summary[abs]) { | |
| return '/' + path.relative(path.join(__dirname, '../public/'), summary[abs]); | |
| } | |
| return file; | |
| } | |
| })() | |
| }, | |
| { | |
| match: /[\'\"][\.\/\w]+\/js\/[\.\/\w]+[\'\"]/gm, | |
| replacement: (function () { | |
| return function (file) { | |
| var fileName = file.replace(/\'/gm, '').replace(/\"/gm, ''); | |
| var summary = grunt.filerev.summary; | |
| var abs = path.join(__dirname, '../public/asset/', fileName + '.js'); | |
| if (summary[abs]) { | |
| var temp = path.relative(path.join(__dirname, '../public/asset/'), summary[abs]); | |
| return '\'' + temp.substr(0, temp.length - 3) + '\''; | |
| } | |
| return file; | |
| } | |
| })() | |
| } | |
| ] | |
| }, | |
| files: [ | |
| { | |
| expand: true, | |
| flatten: true, | |
| src: obj[k], | |
| dest: (function () { | |
| var relativePath = path.relative(path.join(__dirname, '../app/viewSrc/'), k); | |
| return path.join(__dirname, '../app/views', relativePath + '/'); | |
| })() | |
| } | |
| ] | |
| } | |
| } | |
| var jsPath = {}; | |
| config.js.forEach(function (file) { | |
| var location = path.join(__dirname + '/../public/asset/' + file + '.js'); | |
| jsPath[path.dirname(location)] = 1; | |
| }); | |
| for (var k in jsPath) { | |
| number++; | |
| options['replace' + number + path.relative(path.join(__dirname, '../'), k)] = { | |
| options: { | |
| patterns: [ | |
| { | |
| match: /[\'\"][\.\/\w]+\/js\/[\.\/\w]+[\'\"]/gm, | |
| replacement: (function () { | |
| return function (file) { | |
| var fileName = file.replace(/\'/gm, '').replace(/\"/gm, ''); | |
| var summary = grunt.filerev.summary; | |
| var abs = path.join(__dirname, '../public/asset/', fileName + '.js'); | |
| if (summary[abs]) { | |
| var temp = path.relative(path.join(__dirname, '../public/asset/'), summary[abs]); | |
| return '\'' + temp.substr(0, temp.length - 3) + '\''; | |
| } | |
| return file; | |
| } | |
| })() | |
| } | |
| ] | |
| }, | |
| files: [ | |
| { | |
| expand: true, | |
| flatten: true, | |
| src: [k + '/*.js'], | |
| dest: k | |
| } | |
| ] | |
| } | |
| } | |
| return options; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * @file 获取需要通过requirejs 打包的配置 | |
| * @author ji.yang@joudou.com | |
| * | |
| * 根目录public | |
| */ | |
| var path = require('path'); | |
| var files = require('./config').js; | |
| var components = require('./config').components; | |
| module.exports = function () { | |
| var options = {}; | |
| components.forEach(function(c) { | |
| files.push(c.file); | |
| }); | |
| files.forEach(function (file) { | |
| options[file] = { | |
| options: { | |
| baseUrl: path.join(__dirname, '../public'), | |
| include: file, | |
| create: true, | |
| out: path.join(__dirname, '../public/asset/', file + '.js'), | |
| optimize: process.env.NODE_ENV == 'local' ? 'none' : 'uglify', | |
| preserveLicenseComments: !false, | |
| packages: [ | |
| { | |
| main: 'echarts', | |
| location: 'lib/echarts/src', | |
| name: 'echarts' | |
| }, | |
| { | |
| main: 'zrender', | |
| location: 'lib/zrender/src', | |
| name: 'zrender' | |
| }, | |
| { | |
| main: 'main', | |
| location: 'lib/etpl/src', | |
| name: 'etpl' | |
| }, | |
| { | |
| main: 'moment', | |
| location: 'lib/moment', | |
| name: 'moment' | |
| } | |
| ] | |
| } | |
| } | |
| }); | |
| return options; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * @file 根据config生成grunt-touch的配置,用于自动touch文件 | |
| * @author yu.zhao@joudou.com | |
| * | |
| * 根目录public | |
| */ | |
| var path = require('path'); | |
| var files = require('./config').js; | |
| module.exports = function () { | |
| var options = {}; | |
| files.forEach(function (file) { | |
| options[file] = { | |
| src: [path.join(__dirname, '../public', file +'.js')], | |
| target: [path.join(__dirname, '../public', file +'.js')] | |
| } | |
| }); | |
| return options; | |
| } | |
| // Usage of grunt-touch: | |
| // grunt.loadNpmTasks('grunt-touch'); | |
| // grunt.initConfig({ | |
| // touch: ['file.js'], | |
| // }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * @file 获取需要通过uglify 打包的配置 | |
| * @author ji.yang@joudou.com | |
| * | |
| * 打包不需要经过requirejs合并的文件 | |
| */ | |
| var path = require('path'); | |
| var files = [ | |
| 'lib/requirejs/require.js' | |
| ]; | |
| module.exports = function () { | |
| var temp = {}; | |
| files.forEach(function (file) { | |
| temp[path.join(__dirname, '../public/asset', file)] = [path.join(__dirname, '../public', file)]; | |
| }); | |
| return { | |
| base: { | |
| files: process.env.NODE_ENV == 'local' ? {} : temp | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment