gulp+webpack+experss

var gulp = require('gulp');

var gls = require('gulp-live-server');

var less = require('gulp-less');

var cssmin = require('gulp-minify-css');

var livereload = require('gulp-livereload');

//var uglifyjs = require('gulp-uglify');

var webpack = require('gulp-webpack');

gulp.task('watch', function () {

    livereload.listen();

    gulp.watch('source/less/*.less', ['less']);

    gulp.watch('views/**/*.ejs', ['html']);

    //gulp.watch('source/js/*.js', ['jsmin']);

});

gulp.task('less', function () {

    gulp.src('source/less/*.less')

        .pipe(less())

        .pipe(cssmin())

        .pipe(gulp.dest('public/css/'))

        .pipe(livereload())

});

// 压缩js

// gulp.task('jsmin', function () {

//    gulp.src('source/js/*.js')

//        .pipe(uglifyjs())

//        .pipe(gulp.dest('public/js/'))

// });

gulp.task('html', function () {

    gulp.src('views/**/*.ejs')

        .pipe(livereload())

});

gulp.task('server', function () {

    var server = gls('app.js', {}, false);

    server.start();

});

gulp.task('scripts', function () {

    return gulp.src('source/entry.js')

        .pipe(webpack(require('./webpack.config.js')))

        .pipe(gulp.dest('public/js/'));

});

gulp.task('default', ['less', 'watch', 'scripts', 'server']);

//webpack

module.exports = {

    watch: true,

    entry: {

        'standard': './source/js/standard.js',

        'standard_red': './source/js/standard_red.js',

        'info': './source/js/info.js',

        'join': './source/js/join.js',

        'join_red': './source/js/join_red.js',

        'share': './source/js/share.js',

        'share_browser': './source/js/share_browser.js',

        'actlist': './source/js/actlist.js',

        'reach': './source/js/reach.js',

        'team': './source/js/team.js',

        'info_red': './source/js/info_red.js',

    },

    output: {

        path: __dirname + '/public/js/',

        filename: "[name].js",

        sourceMapFilename: "debugging/[file].map"

    },

    externals: {

        "jquery": "jQuery",

        '$': 'jQuery',

    },

    devtool: "source-map",

};

//app.js

var express = require('express');

var path = require('path');

var favicon = require('serve-favicon');

var logger = require('morgan');

var cookieParser = require('cookie-parser');

var bodyParser = require('body-parser');

var app = express();

// view engine setup

app.set('views', path.join(__dirname, 'views'));

app.set('view engine', 'ejs');

// uncomment after placing your favicon in /public

//app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')));

app.use(logger('dev'));

app.use(bodyParser.json());

app.use(bodyParser.urlencoded({extended: false}));

app.use(cookieParser());

app.use(express.static(path.join(__dirname, 'public')));

app.use('/', require('./routes/routes.js'));

// app.use('/', require('./routes/index'));

app.use('/more_act', require('./routes/r_more_act'));

app.use('/standard_act', require('./routes/r_standard_act'));

app.use('/join_act', require('./routes/r_join_act'));

app.use('/join_act_red', require('./routes/r_join_act_red'));

app.use('/share_act', require('./routes/r_share_act'));

app.use('/team', require('./routes/r_team'));

//test

app.use('/test', require('./routes/test'));

// catch 404 and forward to error handler

app.use(function (req, res, next) {

    var err = new Error('Not Found');

    err.status = 404;

    next(err);

});

// error handler

app.use(function (err, req, res, next) {

    // set locals, only providing error in development

    res.locals.message = err.message;

    res.locals.error = req.app.get('env') === 'development' ? err : {};

    // render the error page

    res.status(err.status || 500);

    res.render('error');

});

app.set('ip', process.env.HTTP_IP || 'localhost');

app.set('port', process.env.HTTP_PORT || 3000);

var server = app.listen(app.get('port'), app.get('ip'), function () {

    console.log('server running at ' + app.get('ip') + ':' + app.get('port'));

});

module.exports = app;

你可能感兴趣的:(gulp+webpack+experss)