Skip to content

Instantly share code, notes, and snippets.

@tx-tim
Last active February 8, 2016 02:41
Show Gist options
  • Save tx-tim/7fcf92db414c94ce8bf7 to your computer and use it in GitHub Desktop.
Save tx-tim/7fcf92db414c94ce8bf7 to your computer and use it in GitHub Desktop.
Gulp + Webpack Configs

gulpfile.js

gulp --v 3.9.0

var gulp = require('gulp');
var webpackStream = require('webpack-stream');
var webpack = require('webpack');
var browserSync = require('browser-sync').create();
var sass        = require('gulp-sass');
var commonsPlugin =
    new webpack.optimize.CommonsChunkPlugin('./js/common.js');

gulp.task('webpack', function() {
    return gulp.src('./src/script/entry.js')
        .pipe(webpackStream( require('./webpack.config.js') ))
        .pipe(gulp.dest('./dist'))
        .pipe(browserSync.stream());
});


// Static Server + watching scss/html files
gulp.task('serve', ['sass'], function() {

    browserSync.init({
        server: "./dist"
    });

    gulp.watch("./src/stylesheets/**/*.scss", ['sass']);
    gulp.watch("./src/script/**/*.js", ['webpack']);
    gulp.watch("./dist/*.html").on('change', browserSync.reload);
});

// Compile sass into CSS & auto-inject into browsers
gulp.task('sass', function() {
    return gulp.src("./src/stylesheets/**/*.scss")
        .pipe(sass())
        .pipe(gulp.dest("./dist/css"))
        .pipe(browserSync.stream());
});

gulp.task('default', ['serve']);

webpack.config.js

webpack --v 1.12.13

var webpack = require('webpack');
var commonsPlugin =
    new webpack.optimize.CommonsChunkPlugin('./js/common.js');

module.exports = {
    entry: {
        registration: "./src/script/registration.js",
        application: "./src/script/app.js"
    },
    output: {
        path: __dirname,
        filename: "./js/[name].js"
    },
    plugins: [commonsPlugin]
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment