Showing
12 changed files
with
363 additions
and
342 deletions
.eslintignore
0 → 100644
.stylelintignore
0 → 100644
.stylelintrc
0 → 100644
1 | -/** | ||
2 | - * yohobuy app | ||
3 | - * @author: xuqi<qi.xu@yoho.cn> | ||
4 | - * @date: 2016/4/25 | ||
5 | - */ | ||
6 | - | ||
7 | -var express = require('express'), | ||
8 | - path = require('path'), | ||
9 | - hbs = require('express-handlebars'), | ||
10 | - bodyParser = require('body-parser'), | ||
11 | - favicon = require('serve-favicon'), | ||
12 | - cookieParser = require('cookie-parser'); | ||
13 | - | ||
14 | -var app = express(); | ||
15 | - | ||
16 | -app.set('view engine', '.hbs'); | ||
17 | - | ||
18 | -app.use(bodyParser.json()); | ||
19 | -app.use(bodyParser.urlencoded({extended: false})); | ||
20 | -app.use(cookieParser()); | ||
21 | -app.use(express.static(path.join(__dirname, 'public'))); | ||
22 | - | ||
23 | -// dispatcher | ||
24 | -require('./dispatch')(app); | ||
25 | - | ||
26 | -// listener | ||
27 | -app.listen(3000, function() { | ||
28 | - console.log('yohobuy start'); | ||
29 | -}); | ||
1 | +/** | ||
2 | + * yohobuy app | ||
3 | + * @author: xuqi<qi.xu@yoho.cn> | ||
4 | + * @date: 2016/4/25 | ||
5 | + */ | ||
6 | + | ||
7 | +var express = require('express'), | ||
8 | + path = require('path'), | ||
9 | + hbs = require('express-handlebars'), | ||
10 | + bodyParser = require('body-parser'), | ||
11 | + favicon = require('serve-favicon'), | ||
12 | + cookieParser = require('cookie-parser'); | ||
13 | + | ||
14 | +var app = express(); | ||
15 | + | ||
16 | +app.set('view engine', '.hbs'); | ||
17 | + | ||
18 | +app.use(bodyParser.json()); | ||
19 | +app.use(bodyParser.urlencoded({extended: false})); | ||
20 | +app.use(cookieParser()); | ||
21 | +app.use(express.static(path.join(__dirname, 'public'))); | ||
22 | + | ||
23 | +// dispatcher | ||
24 | +require('./dispatch')(app); | ||
25 | + | ||
26 | +// listener | ||
27 | +app.listen(3000, function() { | ||
28 | + console.log('yohobuy start'); | ||
29 | +}); |
1 | -/** | ||
2 | - * 路由分发 | ||
3 | - * @author: xuqi<qi.xu@yoho.cn> | ||
4 | - * @date: 2016/4/27 | ||
5 | - */ | ||
6 | - | ||
7 | -module.exports = app => { | ||
8 | - //公共服务 | ||
9 | - | ||
10 | - //业务模块 | ||
11 | - app.use('/guang', require('./apps/guang')); | ||
12 | -}; | 1 | +/** |
2 | + * 路由分发 | ||
3 | + * @author: xuqi<qi.xu@yoho.cn> | ||
4 | + * @date: 2016/4/27 | ||
5 | + */ | ||
6 | + | ||
7 | +module.exports = app => { | ||
8 | + // 公共服务 | ||
9 | + | ||
10 | + // 业务模块 | ||
11 | + app.use('/guang', require('./apps/guang')); | ||
12 | +}; |
1 | -/** | ||
2 | - * 登录判断 | ||
3 | - * @author: xuqi<qi.xu@yoho.cn> | ||
4 | - * @date: 2016/4/25 | ||
5 | - */ | ||
6 | - | ||
7 | -'use strict'; | ||
8 | - | ||
9 | -module.exports = (req, res, next) => { | ||
10 | - next(); | ||
11 | -}; | ||
1 | +/** | ||
2 | + * 登录判断 | ||
3 | + * @author: xuqi<qi.xu@yoho.cn> | ||
4 | + * @date: 2016/4/25 | ||
5 | + */ | ||
6 | + | ||
7 | +'use strict'; | ||
8 | + | ||
9 | +module.exports = (req, res, next) => { | ||
10 | + next(); | ||
11 | +}; |
1 | -/** | ||
2 | - * 接口公共方法 | ||
3 | - * @author: xuqiMqi.xu@yoho.cn> | ||
4 | - * @date: 2016/4/25 | ||
5 | - */ | ||
6 | - | ||
7 | -'use strict'; | ||
8 | - | ||
9 | -const rp = require('request-promise'); | ||
10 | -const _ = require('lodash'); | ||
11 | - | ||
12 | -class API { | ||
13 | - | ||
14 | - /** | ||
15 | - * get | ||
16 | - * @param url String | ||
17 | - * @param data Obejct | ||
18 | - */ | ||
19 | - get(url, data) { | ||
20 | - return rp({ | ||
21 | - url: `${this.server}${url}`, | ||
22 | - qs: data | ||
23 | - }); | ||
24 | - } | ||
25 | - | ||
26 | - /** | ||
27 | - * multi get | ||
28 | - * @params: urls => Array[Object[url[string], data[object]]] | ||
29 | - */ | ||
30 | - multiGet(urls) { | ||
31 | - var rps = [], | ||
32 | - self = this; | ||
33 | - | ||
34 | - _.forEach(urls, function(el) { | ||
35 | - rps.push(rp({ | ||
36 | - url: `${self.server}${el.url}`, | ||
37 | - qs: el.data | ||
38 | - })); | ||
39 | - }); | ||
40 | - | ||
41 | - return Promise.all(rps).then((d) => { | ||
42 | - return d; | ||
43 | - }); | ||
44 | - } | ||
45 | - | ||
46 | - /** | ||
47 | - * post | ||
48 | - * @param url String | ||
49 | - * @param data Obejct | ||
50 | - */ | ||
51 | - post(url, data) { | ||
52 | - return rp({ | ||
53 | - url: `${this.server}${url}`, | ||
54 | - method: 'post', | ||
55 | - form: data | ||
56 | - }); | ||
57 | - } | ||
58 | -} | ||
59 | - | ||
60 | -module.exports = API; | ||
1 | +/** | ||
2 | + * 接口公共方法 | ||
3 | + * @author: xuqiMqi.xu@yoho.cn> | ||
4 | + * @date: 2016/4/25 | ||
5 | + */ | ||
6 | + | ||
7 | +'use strict'; | ||
8 | + | ||
9 | +const rp = require('request-promise'); | ||
10 | +const _ = require('lodash'); | ||
11 | + | ||
12 | +class API { | ||
13 | + | ||
14 | + /** | ||
15 | + * get | ||
16 | + * @param url String | ||
17 | + * @param data Obejct | ||
18 | + */ | ||
19 | + get(url, data) { | ||
20 | + return rp({ | ||
21 | + url: `${this.server}${url}`, | ||
22 | + qs: data | ||
23 | + }); | ||
24 | + } | ||
25 | + | ||
26 | + /** | ||
27 | + * multi get | ||
28 | + * @params: urls => Array[Object[url[string], data[object]]] | ||
29 | + */ | ||
30 | + multiGet(urls) { | ||
31 | + var rps = [], | ||
32 | + self = this; | ||
33 | + | ||
34 | + _.forEach(urls, function(el) { | ||
35 | + rps.push(rp({ | ||
36 | + url: `${self.server}${el.url}`, | ||
37 | + qs: el.data | ||
38 | + })); | ||
39 | + }); | ||
40 | + | ||
41 | + return Promise.all(rps).then((d) => { | ||
42 | + return d; | ||
43 | + }); | ||
44 | + } | ||
45 | + | ||
46 | + /** | ||
47 | + * post | ||
48 | + * @param url String | ||
49 | + * @param data Obejct | ||
50 | + */ | ||
51 | + post(url, data) { | ||
52 | + return rp({ | ||
53 | + url: `${this.server}${url}`, | ||
54 | + method: 'post', | ||
55 | + form: data | ||
56 | + }); | ||
57 | + } | ||
58 | +} | ||
59 | + | ||
60 | +module.exports = API; |
1 | { | 1 | { |
2 | "name": "m-yohobuy-node", | 2 | "name": "m-yohobuy-node", |
3 | "version": "0.0.1", | 3 | "version": "0.0.1", |
4 | + "private": true, | ||
4 | "description": "A New Yohobuy Project With Express", | 5 | "description": "A New Yohobuy Project With Express", |
5 | "repository": { | 6 | "repository": { |
6 | "type": "git", | 7 | "type": "git", |
7 | "url": "http://git.dev.yoho.cn/web/yohobuy-node.git" | 8 | "url": "http://git.dev.yoho.cn/web/yohobuy-node.git" |
8 | }, | 9 | }, |
10 | + "scripts": { | ||
11 | + "start": "node app.js", | ||
12 | + "dev": "node_modules/.bin/nodemon -e js,hbs -i public/ app.js", | ||
13 | + "online": "NODE_ENV=\"production\" node app.js", | ||
14 | + "debug": "DEBUG=\"express:*\" node app.js", | ||
15 | + "lint-js": "node_modules/.bin/eslint -c .eslintrc --cache --fix `git diff --cached --name-only --diff-filter=ACM | grep .js$` app.js", | ||
16 | + "lint-css": "node_modules/.bin/stylelint --config .stylelintrc `git diff --cached --name-only --diff-filter=ACM | grep .css$`", | ||
17 | + "precommit": "npm run lint-js && npm run lint-css" | ||
18 | + }, | ||
9 | "license": "MIT", | 19 | "license": "MIT", |
10 | "dependencies": { | 20 | "dependencies": { |
11 | "body-parser": "^1.15.0", | 21 | "body-parser": "^1.15.0", |
@@ -15,17 +25,19 @@ | @@ -15,17 +25,19 @@ | ||
15 | "lodash": "^4.8.2", | 25 | "lodash": "^4.8.2", |
16 | "morgan": "^1.7.0", | 26 | "morgan": "^1.7.0", |
17 | "request-promise": "^2.0.1", | 27 | "request-promise": "^2.0.1", |
18 | - "serve-favicon": "^2.3.0", | ||
19 | - "shelljs": "^0.7.0" | 28 | + "serve-favicon": "^2.3.0" |
20 | }, | 29 | }, |
21 | "devDependencies": { | 30 | "devDependencies": { |
22 | "autoprefixer": "^6.3.6", | 31 | "autoprefixer": "^6.3.6", |
32 | + "eslint": "^2.9.0", | ||
33 | + "eslint-config-yoho": "^1.0.1", | ||
23 | "gulp": "^3.9.1", | 34 | "gulp": "^3.9.1", |
24 | "gulp-cssnano": "^2.1.2", | 35 | "gulp-cssnano": "^2.1.2", |
25 | "gulp-ftp": "^1.1.0", | 36 | "gulp-ftp": "^1.1.0", |
26 | "gulp-postcss": "^6.1.0", | 37 | "gulp-postcss": "^6.1.0", |
27 | "gulp-sourcemaps": "^2.0.0-alpha", | 38 | "gulp-sourcemaps": "^2.0.0-alpha", |
28 | "gulp-util": "^3.0.7", | 39 | "gulp-util": "^3.0.7", |
40 | + "husky": "^0.11.4", | ||
29 | "postcss-assets": "^4.0.1", | 41 | "postcss-assets": "^4.0.1", |
30 | "postcss-cachebuster": "^0.1.2", | 42 | "postcss-cachebuster": "^0.1.2", |
31 | "postcss-calc": "^5.2.1", | 43 | "postcss-calc": "^5.2.1", |
@@ -38,8 +50,11 @@ | @@ -38,8 +50,11 @@ | ||
38 | "postcss-sprites": "^3.1.2", | 50 | "postcss-sprites": "^3.1.2", |
39 | "postcss-use": "^2.0.2", | 51 | "postcss-use": "^2.0.2", |
40 | "precss": "^1.4.0", | 52 | "precss": "^1.4.0", |
53 | + "stylelint": "^6.2.2", | ||
54 | + "stylelint-config-yoho": "^1.2.0", | ||
41 | "webpack": "^1.13.0", | 55 | "webpack": "^1.13.0", |
42 | "webpack-dev-server": "^1.14.1", | 56 | "webpack-dev-server": "^1.14.1", |
43 | - "webpack-stream": "^3.1.0" | 57 | + "webpack-stream": "^3.1.0", |
58 | + "shelljs": "^0.7.0" | ||
44 | } | 59 | } |
45 | } | 60 | } |
1 | -/** | ||
2 | - * Yohobuy 构建脚本 | ||
3 | - * @author: xuqi<qi.xu@yoho.cn> | ||
4 | - * @date: 2016/4/25 | ||
5 | - */ | ||
6 | - | ||
7 | -'use strict'; | ||
8 | - | ||
9 | -const gulp = require('gulp'); | ||
10 | -const gutil = require('gulp-util'); | ||
11 | -const ftp = require('gulp-ftp'); | ||
12 | - | ||
13 | -const postcss = require('gulp-postcss'); | ||
14 | -const sourcemaps = require('gulp-sourcemaps'); | ||
15 | -const cssnano = require('gulp-cssnano'); | ||
16 | - | ||
17 | -const webpack = require('webpack'); | ||
18 | -const webpackDevServer = require('webpack-dev-server'); | ||
19 | -const webpackConfig = require('./webpack.config.js'); | ||
20 | - | ||
21 | -const env = { | ||
22 | - dev: Symbol('development'), | ||
23 | - pro: Symbol('production') | ||
24 | -}; | ||
25 | - | ||
26 | -const config = require('../package.json'); | ||
27 | -const ftpConfig = { | ||
28 | - host: '218.94.75.50', | ||
29 | - user: 'php', | ||
30 | - pass: 'yoho9646' | ||
31 | -}; | ||
32 | -const distRoot = `dist/${config.name}`; | ||
33 | -const dist = { | ||
34 | - js: `${distRoot}/${config.version}`, | ||
35 | - css: `${distRoot}/${config.version}`, | ||
36 | - assets: `${distRoot}/assets`, | ||
37 | - img: `${distRoot}/assets/img`, | ||
38 | - font: `${distRoot}/assets/font` | ||
39 | -}; | ||
40 | - | ||
41 | -/** | ||
42 | - * postcss plugins for both dev and pro | ||
43 | - * @parem et Symbol | ||
44 | - */ | ||
45 | -const postcssPlugin = (et) => { | ||
46 | - var sprites = { | ||
47 | - spritesmith: { | ||
48 | - padding: 2 | ||
49 | - }, | ||
50 | - groupBy(file) { | ||
51 | - var group = file.url.split('/')[1]; | ||
52 | - | ||
53 | - group = group === '' ? 'yo' : group; | ||
54 | - | ||
55 | - return group ? Promise.resolve(group) : Promise.reject(group); | ||
56 | - } | ||
57 | - }, | ||
58 | - assets, | ||
59 | - plugins; | ||
60 | - | ||
61 | - // assets & sprites config in both dev and pro | ||
62 | - if (et === env.pro) { | ||
63 | - assets = { | ||
64 | - loadPaths: [dist.img, dist.font], | ||
65 | - }; | ||
66 | - | ||
67 | - Object.assign(sprites, { | ||
68 | - basePath: dist.img, | ||
69 | - stylesheetPath: dist.css, | ||
70 | - spritePath: dist.img | ||
71 | - }); | ||
72 | - } else if (et === env.dev) { | ||
73 | - assets = { | ||
74 | - loadPaths: ['img/', 'font/'], | ||
75 | - relativeTo: 'css/' | ||
76 | - }; | ||
77 | - | ||
78 | - Object.assign(sprites, { | ||
79 | - basePath: 'img/', | ||
80 | - stylesheetPath: 'css/', | ||
81 | - spritePath: 'img/' | ||
82 | - }); | ||
83 | - }; | ||
84 | - | ||
85 | - plugins = [ | ||
86 | - require('autoprefixer')({ | ||
87 | - browsers: ['> 1%'] | ||
88 | - }), | ||
89 | - require('precss'), | ||
90 | - require('postcss-sprites').default(sprites), | ||
91 | - require('postcss-assets')(assets), | ||
92 | - require('postcss-calc'), | ||
93 | - require('postcss-opacity'), | ||
94 | - | ||
95 | - //可选 | ||
96 | - require('postcss-use')({ | ||
97 | - modules: ['postcss-clearfix', 'postcss-crip', 'postcss-short', 'postcss-center', 'postcss-position'] | ||
98 | - }) | ||
99 | - ]; | ||
100 | - | ||
101 | - if (et === env.pro) { | ||
102 | - plugins.push(require('postcss-cachebuster')({ | ||
103 | - imagesPath: `/${dist.img}`, | ||
104 | - cssPath: `/${dist.css}` | ||
105 | - })); | ||
106 | - } | ||
107 | - return plugins; | ||
108 | -}; | ||
109 | - | ||
110 | -// default | ||
111 | -gulp.task('default', ['postcss-dev', 'postcss-watch', 'webpack-dev-server']); | ||
112 | - | ||
113 | -// ge | ||
114 | -gulp.task('ge', ['postcss', 'webpack']); | ||
115 | - | ||
116 | -// dist | ||
117 | -gulp.task('dist', ['ge'], () => { | ||
118 | - var ftpstream = ftp(ftpConfig); | ||
119 | - | ||
120 | - return gulp.src('dist/**/') | ||
121 | - .pipe(ftpstream) | ||
122 | - .pipe(gutil.noop()); | ||
123 | -}); | ||
124 | - | ||
125 | -// postcss compile in dev | ||
126 | -gulp.task('postcss-dev', () => { | ||
127 | - return gulp.src('scss/index.css') | ||
128 | - .pipe(sourcemaps.init()) | ||
129 | - .pipe(postcss(postcssPlugin(env.dev))) | ||
130 | - .pipe(sourcemaps.write('.')) | ||
131 | - .pipe(gulp.dest('css/')); | ||
132 | -}); | ||
133 | - | ||
134 | -// postcss file watch | ||
135 | -gulp.task('postcss-watch', () => { | ||
136 | - gulp.watch('scss/**/*.css', ['postcss-dev']); | ||
137 | -}); | ||
138 | - | ||
139 | -// copy assets | ||
140 | -gulp.task('assets', ['img', 'font']); | ||
141 | - | ||
142 | -// copy img | ||
143 | -gulp.task('img', () => { | ||
144 | - return gulp.src('img/**/*') | ||
145 | - .pipe(gulp.dest(dist.img)); | ||
146 | -}); | ||
147 | - | ||
148 | -//copy font | ||
149 | -gulp.task('font', () => { | ||
150 | - return gulp.src('font/*') | ||
151 | - .pipe(gulp.dest(dist.font)); | ||
152 | -}); | ||
153 | - | ||
154 | -// postcss compile in pro | ||
155 | -gulp.task('postcss', ['assets'], () => { | ||
156 | - return gulp.src('scss/index.css') | ||
157 | - .pipe(postcss(postcssPlugin(env.pro))) | ||
158 | - .pipe(cssnano()) | ||
159 | - .pipe(gulp.dest(dist.css)); | ||
160 | -}); | ||
161 | - | ||
162 | -// webpack dev server | ||
163 | -gulp.task('webpack-dev-server', () => { | ||
164 | - var devConfig = Object.assign({}, webpackConfig, { | ||
165 | - debug: true | ||
166 | - }); | ||
167 | - | ||
168 | - new webpackDevServer(webpack(devConfig), { | ||
169 | - contentBase: '.', | ||
170 | - publicPath: '//localhost:8000/', | ||
171 | - hot: true, | ||
172 | - stats: { | ||
173 | - colors: true | ||
174 | - } | ||
175 | - }).listen(8000, 'localhost', (err) => { | ||
176 | - if (err) { | ||
177 | - throw new gutil.PluginError('webpack-dev-server', err); | ||
178 | - } | ||
179 | - gutil.log('[webpack-serve]', 'http://localhost:8000/'); | ||
180 | - }); | ||
181 | -}); | ||
182 | - | ||
183 | -// webpack compile in pro | ||
184 | -gulp.task('webpack', () => { | ||
185 | - var proConfig = Object.assign({}, webpackConfig); | ||
186 | - | ||
187 | - proConfig.output.path = dist.js; | ||
188 | - webpack(proConfig, (err, stats) => { | ||
189 | - if (err) { | ||
190 | - throw new gutil.PluginError('webpack', err); | ||
191 | - } | ||
192 | - }); | ||
193 | -}); | ||
1 | +/** | ||
2 | + * Yohobuy 构建脚本 | ||
3 | + * @author: xuqi<qi.xu@yoho.cn> | ||
4 | + * @date: 2016/4/25 | ||
5 | + */ | ||
6 | + | ||
7 | +'use strict'; | ||
8 | + | ||
9 | +const gulp = require('gulp'); | ||
10 | +const gutil = require('gulp-util'); | ||
11 | +const ftp = require('gulp-ftp'); | ||
12 | + | ||
13 | +const postcss = require('gulp-postcss'); | ||
14 | +const sourcemaps = require('gulp-sourcemaps'); | ||
15 | +const cssnano = require('gulp-cssnano'); | ||
16 | + | ||
17 | +const webpack = require('webpack'); | ||
18 | +const webpackDevServer = require('webpack-dev-server'); | ||
19 | +const webpackConfig = require('./webpack.config.js'); | ||
20 | + | ||
21 | +const env = { | ||
22 | + dev: Symbol('development'), | ||
23 | + pro: Symbol('production') | ||
24 | +}; | ||
25 | + | ||
26 | +const config = require('../package.json'); | ||
27 | +const ftpConfig = { | ||
28 | + host: '218.94.75.50', | ||
29 | + user: 'php', | ||
30 | + pass: 'yoho9646' | ||
31 | +}; | ||
32 | +const distRoot = `dist/${config.name}`; | ||
33 | +const dist = { | ||
34 | + js: `${distRoot}/${config.version}`, | ||
35 | + css: `${distRoot}/${config.version}`, | ||
36 | + assets: `${distRoot}/assets`, | ||
37 | + img: `${distRoot}/assets/img`, | ||
38 | + font: `${distRoot}/assets/font` | ||
39 | +}; | ||
40 | + | ||
41 | +/** | ||
42 | + * postcss plugins for both dev and pro | ||
43 | + * @parem et Symbol | ||
44 | + */ | ||
45 | +const postcssPlugin = (et) => { | ||
46 | + var sprites = { | ||
47 | + spritesmith: { | ||
48 | + padding: 2 | ||
49 | + }, | ||
50 | + groupBy(file) { | ||
51 | + var group = file.url.split('/')[1]; | ||
52 | + | ||
53 | + group = group === '' ? 'yo' : group; | ||
54 | + | ||
55 | + return group ? Promise.resolve(group) : Promise.reject(group); | ||
56 | + } | ||
57 | + }, | ||
58 | + assets, | ||
59 | + plugins; | ||
60 | + | ||
61 | + // assets & sprites config in both dev and pro | ||
62 | + if (et === env.pro) { | ||
63 | + assets = { | ||
64 | + loadPaths: [dist.img, dist.font] | ||
65 | + }; | ||
66 | + | ||
67 | + Object.assign(sprites, { | ||
68 | + basePath: dist.img, | ||
69 | + stylesheetPath: dist.css, | ||
70 | + spritePath: dist.img | ||
71 | + }); | ||
72 | + } else if (et === env.dev) { | ||
73 | + assets = { | ||
74 | + loadPaths: ['img/', 'font/'], | ||
75 | + relativeTo: 'css/' | ||
76 | + }; | ||
77 | + | ||
78 | + Object.assign(sprites, { | ||
79 | + basePath: 'img/', | ||
80 | + stylesheetPath: 'css/', | ||
81 | + spritePath: 'img/' | ||
82 | + }); | ||
83 | + } | ||
84 | + | ||
85 | + plugins = [ | ||
86 | + require('autoprefixer')({ | ||
87 | + browsers: ['> 1%'] | ||
88 | + }), | ||
89 | + require('precss'), | ||
90 | + require('postcss-sprites').default(sprites), | ||
91 | + require('postcss-assets')(assets), | ||
92 | + require('postcss-calc'), | ||
93 | + require('postcss-opacity'), | ||
94 | + | ||
95 | + // 可选 | ||
96 | + require('postcss-use')({ | ||
97 | + modules: ['postcss-clearfix', 'postcss-crip', 'postcss-short', 'postcss-center', 'postcss-position'] | ||
98 | + }) | ||
99 | + ]; | ||
100 | + | ||
101 | + if (et === env.pro) { | ||
102 | + plugins.push(require('postcss-cachebuster')({ | ||
103 | + imagesPath: `/${dist.img}`, | ||
104 | + cssPath: `/${dist.css}` | ||
105 | + })); | ||
106 | + } | ||
107 | + return plugins; | ||
108 | +}; | ||
109 | + | ||
110 | +// default | ||
111 | +gulp.task('default', ['postcss-dev', 'postcss-watch', 'webpack-dev-server']); | ||
112 | + | ||
113 | +// ge | ||
114 | +gulp.task('ge', ['postcss', 'webpack']); | ||
115 | + | ||
116 | +// dist | ||
117 | +gulp.task('dist', ['ge'], () => { | ||
118 | + var ftpstream = ftp(ftpConfig); | ||
119 | + | ||
120 | + return gulp.src('dist/**/') | ||
121 | + .pipe(ftpstream) | ||
122 | + .pipe(gutil.noop()); | ||
123 | +}); | ||
124 | + | ||
125 | +// postcss compile in dev | ||
126 | +gulp.task('postcss-dev', () => { | ||
127 | + return gulp.src('scss/index.css') | ||
128 | + .pipe(sourcemaps.init()) | ||
129 | + .pipe(postcss(postcssPlugin(env.dev))) | ||
130 | + .pipe(sourcemaps.write('.')) | ||
131 | + .pipe(gulp.dest('css/')); | ||
132 | +}); | ||
133 | + | ||
134 | +// postcss file watch | ||
135 | +gulp.task('postcss-watch', () => { | ||
136 | + gulp.watch('scss/**/*.css', ['postcss-dev']); | ||
137 | +}); | ||
138 | + | ||
139 | +// copy assets | ||
140 | +gulp.task('assets', ['img', 'font']); | ||
141 | + | ||
142 | +// copy img | ||
143 | +gulp.task('img', () => { | ||
144 | + return gulp.src('img/**/*') | ||
145 | + .pipe(gulp.dest(dist.img)); | ||
146 | +}); | ||
147 | + | ||
148 | +// copy font | ||
149 | +gulp.task('font', () => { | ||
150 | + return gulp.src('font/*') | ||
151 | + .pipe(gulp.dest(dist.font)); | ||
152 | +}); | ||
153 | + | ||
154 | +// postcss compile in pro | ||
155 | +gulp.task('postcss', ['assets'], () => { | ||
156 | + return gulp.src('scss/index.css') | ||
157 | + .pipe(postcss(postcssPlugin(env.pro))) | ||
158 | + .pipe(cssnano()) | ||
159 | + .pipe(gulp.dest(dist.css)); | ||
160 | +}); | ||
161 | + | ||
162 | +// webpack dev server | ||
163 | +gulp.task('webpack-dev-server', () => { | ||
164 | + var devConfig = Object.assign({}, webpackConfig, { | ||
165 | + debug: true | ||
166 | + }); | ||
167 | + | ||
168 | + new webpackDevServer(webpack(devConfig), { | ||
169 | + contentBase: '.', | ||
170 | + publicPath: '//localhost:8000/', | ||
171 | + hot: true, | ||
172 | + stats: { | ||
173 | + colors: true | ||
174 | + } | ||
175 | + }).listen(8000, 'localhost', (err) => { | ||
176 | + if (err) { | ||
177 | + throw new gutil.PluginError('webpack-dev-server', err); | ||
178 | + } | ||
179 | + gutil.log('[webpack-serve]', 'http://localhost:8000/'); | ||
180 | + }); | ||
181 | +}); | ||
182 | + | ||
183 | +// webpack compile in pro | ||
184 | +gulp.task('webpack', () => { | ||
185 | + var proConfig = Object.assign({}, webpackConfig); | ||
186 | + | ||
187 | + proConfig.output.path = dist.js; | ||
188 | + webpack(proConfig, (err, stats) => { | ||
189 | + if (err) { | ||
190 | + throw new gutil.PluginError('webpack', err); | ||
191 | + } | ||
192 | + }); | ||
193 | +}); |
1 | -/** | ||
2 | - * webpack config | ||
3 | - * @author: xuqi<qi.xu@yoho.cn> | ||
4 | - * @date: 2016/4/25 | ||
5 | - */ | ||
6 | - | ||
7 | -'use strict'; | ||
8 | - | ||
9 | -const webpack = require('webpack'); | ||
10 | -const fs = require('fs'); | ||
11 | -const path = require('path'); | ||
12 | -const _ = require('lodash'); | ||
13 | - | ||
14 | -require('shelljs/global'); | ||
15 | - | ||
16 | -var entries = {}; | ||
17 | - | ||
18 | -//构建各模块子页面JS。生成规则module.page.js | ||
19 | -ls(__dirname + '/js/**/*.page.js').forEach((f) => { | ||
20 | - var dir = _.slice(f.split('/'), -2); //[modulename, xx.page.js] | ||
21 | - | ||
22 | - // Important | ||
23 | - // 生成规则:module.page: './js/module/xx.page.js' | ||
24 | - entries[`${dir[0]}.${dir[1].match(/(.*).page.js/)[1]}`] = `./js/${dir.join('/')}`; | ||
25 | -}); | ||
26 | - | ||
27 | -module.exports = { | ||
28 | - entry: entries, | ||
29 | - output: { | ||
30 | - path: path.join(__dirname, 'bundle'), //absolute path | ||
31 | - filename: '[name].js' | ||
32 | - } | ||
33 | -}; | ||
1 | +/** | ||
2 | + * webpack config | ||
3 | + * @author: xuqi<qi.xu@yoho.cn> | ||
4 | + * @date: 2016/4/25 | ||
5 | + */ | ||
6 | + | ||
7 | +'use strict'; | ||
8 | + | ||
9 | +const webpack = require('webpack'); | ||
10 | +const fs = require('fs'); | ||
11 | +const path = require('path'); | ||
12 | +const _ = require('lodash'); | ||
13 | + | ||
14 | +require('shelljs/global'); | ||
15 | + | ||
16 | +var entries = {}; | ||
17 | + | ||
18 | +// 构建各模块子页面JS。生成规则module.page.js | ||
19 | +ls(__dirname + '/js/**/*.page.js').forEach((f) => { | ||
20 | + var dir = _.slice(f.split('/'), -2); // [modulename, xx.page.js] | ||
21 | + | ||
22 | + // Important | ||
23 | + // 生成规则:module.page: './js/module/xx.page.js' | ||
24 | + entries[`${dir[0]}.${dir[1].match(/(.*).page.js/)[1]}`] = `./js/${dir.join('/')}`; | ||
25 | +}); | ||
26 | + | ||
27 | +module.exports = { | ||
28 | + entry: entries, | ||
29 | + output: { | ||
30 | + path: path.join(__dirname, 'bundle'), // absolute path | ||
31 | + filename: '[name].js' | ||
32 | + } | ||
33 | +}; |
-
Please register or login to post a comment