]> git.wincent.com - hextrapolate.git/commitdiff
Replace boilerplate server.js with gulp-based runner
authorGreg Hurrell <greg@hurrell.net>
Fri, 31 Jul 2015 17:11:33 +0000 (10:11 -0700)
committerGreg Hurrell <greg@hurrell.net>
Fri, 31 Jul 2015 17:11:33 +0000 (10:11 -0700)
I want to use gulp as a uniform interface for building, running,
watching etc. This is a start.

gulpfile.babel.js [new file with mode: 0644]
package.json
server.js [deleted file]

diff --git a/gulpfile.babel.js b/gulpfile.babel.js
new file mode 100644 (file)
index 0000000..563f878
--- /dev/null
@@ -0,0 +1,55 @@
+import WebpackDevServer from 'webpack-dev-server';
+import config from './webpack.config.js';
+import gulp from 'gulp';
+import gutil from 'gulp-util';
+import webpack from 'webpack';
+
+gulp.task('default', ['webpack-dev-server']);
+
+gulp.task('build', ['webpack:build']);
+
+gulp.task('webpack:build', callback => {
+  const myConfig = {
+    ...config,
+    plugins: config.plugins.concat(
+      new webpack.DefinePlugin({
+        'process.env': {
+          NODE_ENV: JSON.stringify('production'),
+        },
+      }),
+      new webpack.optimize.DedupePlugin(),
+      new webpack.optimize.UglifyJsPlugin()
+    ),
+  };
+
+  webpack(myConfig, (err, stats) => {
+    if (err) {
+      throw new gutil.PluginError('webpack:build', err);
+    }
+    gutil.log('[webpack:build]', stats.toString({
+      colors: true
+    }));
+    callback();
+  });
+});
+
+gulp.task('webpack-dev-server', callback => {
+  var myConfig = {
+    ...config,
+    debug: true,
+  };
+
+  new WebpackDevServer(webpack(myConfig), {
+    publicPath: config.output.publicPath,
+    hot: true,
+    historyApiFallback: true,
+    stats: {
+      colors: true,
+    },
+  }).listen(8080, 'localhost', err => {
+    if (err) {
+      throw new gutil.PluginError('webpack-dev-server', err);
+    }
+    gutil.log('[webpack-dev-server]', 'http://localhost:3000');
+  });
+});
index 4944187dfed58a8bff92adc5e63456e5cf7b6afb..5188b3df1e318027cb4702f4fc47ca219d140676 100644 (file)
@@ -4,7 +4,7 @@
   "description": "Number base conversion tool",
   "scripts": {
     "lint": "eslint src",
-    "start": "node server.js",
+    "start": "gulp webpack-dev-server",
     "test": "mocha --opts mocha/mocha.opts 'src/**/__mocks__/*.js' 'src/**/__tests__/*-test.js'"
   },
   "repository": {
@@ -27,6 +27,8 @@
     "babel-loader": "^5.1.2",
     "eslint-plugin-react": "^2.3.0",
     "expect": "^1.8.0",
+    "gulp": "^3.9.0",
+    "gulp-util": "^3.0.6",
     "mocha": "^2.2.5",
     "react-hot-loader": "^1.2.7",
     "sinon": "^1.15.4",
diff --git a/server.js b/server.js
deleted file mode 100644 (file)
index 5ac2b33..0000000
--- a/server.js
+++ /dev/null
@@ -1,15 +0,0 @@
-var webpack = require('webpack');
-var WebpackDevServer = require('webpack-dev-server');
-var config = require('./webpack.config');
-
-new WebpackDevServer(webpack(config), {
-  publicPath: config.output.publicPath,
-  hot: true,
-  historyApiFallback: true
-}).listen(3000, 'localhost', function (err, result) {
-  if (err) {
-    console.log(err);
-  }
-
-  console.log('Listening at localhost:3000');
-});