Authored by xuqi

webpack build

{
"name": "yohobuy-node",
"version": "0.0.1",
"description": "A New Yohobuy Project With Express",
"repository": {
"type": "git",
"url": "http://git.dev.yoho.cn/web/yohobuy-node.git"
},
"license": "MIT",
"dependencies": {
"express": "^4.13.1",
"body-parser": "^1.15.0",
"cookie-parser": "^1.4.1",
"express-handlebars": "^3.0.0",
"lodash": "^4.8.2",
"morgan": "^1.7.0",
"request-promise": "^2.0.1",
"serve-favicon": "^2.3.0"
},
"devDependencies": {
"gulp": "^3.9.1",
"autoprefixer": "^6.3.6",
"gulp-cssnano": "^2.1.2",
"gulp-postcss": "^6.1.0",
"gulp-sourcemaps": "^2.0.0-alpha",
"postcss-assets": "^4.0.1",
"postcss-cachebuster": "^0.1.2",
"postcss-calc": "^5.2.1",
"postcss-center": "^1.0.0",
"postcss-clearfix": "^1.0.0",
"postcss-crip": "^2.0.0",
"postcss-opacity": "^3.0.0",
"postcss-position": "^0.4.0",
"postcss-short": "^1.4.0",
"postcss-sprites": "^3.1.2",
"postcss-use": "^2.0.2",
"precss": "^1.4.0",
"webpack": "^1.13.0",
"webpack-dev-server": "^1.14.1",
"webpack-stream": "^3.1.0"
}
}
\ No newline at end of file
{
"name": "yohobuy-node",
"version": "0.0.1",
"description": "A New Yohobuy Project With Express",
"repository": {
"type": "git",
"url": "http://git.dev.yoho.cn/web/yohobuy-node.git"
},
"license": "MIT",
"dependencies": {
"body-parser": "^1.15.0",
"cookie-parser": "^1.4.1",
"express": "^4.13.1",
"express-handlebars": "^3.0.0",
"lodash": "^4.8.2",
"morgan": "^1.7.0",
"request-promise": "^2.0.1",
"serve-favicon": "^2.3.0",
"shelljs": "^0.7.0"
},
"devDependencies": {
"autoprefixer": "^6.3.6",
"gulp": "^3.9.1",
"gulp-cssnano": "^2.1.2",
"gulp-postcss": "^6.1.0",
"gulp-sourcemaps": "^2.0.0-alpha",
"gulp-util": "^3.0.7",
"postcss-assets": "^4.0.1",
"postcss-cachebuster": "^0.1.2",
"postcss-calc": "^5.2.1",
"postcss-center": "^1.0.0",
"postcss-clearfix": "^1.0.0",
"postcss-crip": "^2.0.0",
"postcss-opacity": "^3.0.0",
"postcss-position": "^0.4.0",
"postcss-short": "^1.4.0",
"postcss-sprites": "^3.1.2",
"postcss-use": "^2.0.2",
"precss": "^1.4.0",
"webpack": "^1.13.0",
"webpack-dev-server": "^1.14.1",
"webpack-stream": "^3.1.0"
}
}
... ...
... ... @@ -7,10 +7,15 @@
'use strict';
const gulp = require('gulp');
const gutil = require('gulp-util');
const postcss = require('gulp-postcss');
const sourcemaps = require('gulp-sourcemaps');
const cssnano = require('gulp-cssnano');
const webpack = require('webpack');
const webpackDevServer = require('webpack-dev-server');
const webpackConfig = require('./webpack.config.js');
const env = {
dev: Symbol('development'),
pro: Symbol('production')
... ... @@ -135,4 +140,34 @@ gulp.task('postcss', ['assets'], () => {
.pipe(postcssPlugin(env.pro))
.pipe(cssnano())
.pipe(gulp.dest(dist.css));
});
// webpack dev server
// gulp.task('webpack-dev-server', () => {
// var devConfig = Object.assign({}, webpackConfig, {
// devtool: 'eval',
// debug: true
// });
// new webpackDevServer(webpack(devConfig), {
// contentBase: '.',
// publicPath: '/',
// stats: {
// colors: true
// }
// }).listen(8000, 'localhost', (err) => {
// if (err) {
// throw new gutil.PluginError('webpack-dev-server', err);
// }
// gutil.log('[webpack-serve]', 'http://localhost:8000/');
// });
// });
// webpack compile in pro
gulp.task('webpack', () => {
webpack(webpackConfig, (err, stats) => {
if (err) {
throw new gutil.PluginError('webpack', err);
}
});
});
\ No newline at end of file
... ...
/**
* webpack config
* @author: xuqi<qi.xu@yoho.cn>
* @date: 2016/4/25
*/
'use strict';
const webpack = require('webpack');
const fs = require('fs');
const path = require('path');
const _ = require('lodash');
require('shelljs/global');
var entries = {};
//构建各模块子页面JS。生成规则module.page.js
ls(__dirname + '/js/**/*.page.js').forEach((f) => {
var dir = _.slice(f.split('/'), -2); //[modulename, xx.page.js]
// Important
// 生成规则:module.page: './js/module/xx.page.js'
entries[`${dir[0]}.${dir[1].match(/(.*).page.js/)[1]}`] = `./js/${dir.join('/')}`;
});
module.exports = {
entry: entries,
output: {
path: './bundle',
filename: '[name].js'
}
};
\ No newline at end of file
... ...