From c4b6474defe9084c5090936f7fa14ca6009e170e Mon Sep 17 00:00:00 2001 From: Vvv Date: Mon, 25 Jul 2016 07:47:52 +0000 Subject: [PATCH] added production build task --- README.md | 14 ++++++------ config/env/development.js | 7 ++++++ config/env/production.js | 7 ++++++ package.json | 3 ++- tasks/config/webpack.js | 45 +++++++++++++++++++++++++++++---------- 5 files changed, 57 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index f8496e1..16495e8 100644 --- a/README.md +++ b/README.md @@ -1,23 +1,23 @@ # Sails-React-Webpack Starter Kit -Apart from [this Sails-React starter kit](https://github.com/mixxen/sails-react-example) this one fully uses [Webpack](http://webpack.github.io) as a separate grunt build task. Also I have stepped out from using [Bower](https://bower.io) as front-end package manager and left all to `npm` so if you need any additional package that you want to `import` to your React app, use `npm`. +Apart from [this Sails-React starter kit](https://github.com/mixxen/sails-react-example) this one fully uses [Webpack](http://webpack.github.io) as a separate grunt build task. Also I have stepped out from using [Bower](https://bower.io) as front-end package manager and left all to `npm` so if you need any additional package that you want to `import` to your **React** app, use `npm`. -Upon navigating to `/` an `index.jade` view will be shown that starts React application. All React application code is located at `assets/app`. +Upon navigating to `/` an `index.jade` view will be shown that starts **React** application. All **React** application code is located at `assets/app`. -In order to modify grunt task that bundles React code look at `tasks/config/webpack.js`. +In order to modify grunt task that bundles **React** code look at `tasks/config/webpack.js`. ### Installation -- Clone this repo. -- run `npm install` -- run `npm run dev` to start sails server. +- run `npm install` to scaffold up dependencies +- run `npm run dev` to start Sails server in `development` mode +- run `npm run prod` to start Sails server in `production` mode ### Licence -MIT +MIT \ No newline at end of file diff --git a/config/env/development.js b/config/env/development.js index 3716916..9b30dda 100644 --- a/config/env/development.js +++ b/config/env/development.js @@ -20,5 +20,12 @@ module.exports = { // models: { // connection: 'someMongodbServer' // } + + /** + * Here we increase hoot timeout for grunt so that it won't cry on slow machines + */ + grunt: { + _hookTimeout: 80000 + } }; diff --git a/config/env/production.js b/config/env/production.js index 60dd602..5293f34 100644 --- a/config/env/production.js +++ b/config/env/production.js @@ -34,5 +34,12 @@ module.exports = { // log: { // level: "silent" // } + + /** + * Here we increase hoot timeout for grunt so that it won't cry on slow machines + */ + grunt: { + _hookTimeout: 80000 + } }; diff --git a/package.json b/package.json index af95ed2..d2764fb 100644 --- a/package.json +++ b/package.json @@ -35,7 +35,8 @@ "webpack-dev-server": "^1.14.1" }, "scripts": { - "dev": "clear && sails lift --verbose" + "dev": "clear && sails lift --verbose", + "prod": "clear && sails lift --prod" }, "main": "app.js", "repository": { diff --git a/tasks/config/webpack.js b/tasks/config/webpack.js index 84603d0..6ebd96d 100644 --- a/tasks/config/webpack.js +++ b/tasks/config/webpack.js @@ -2,6 +2,20 @@ var path = require("path"); var project_dir = __dirname + '/../../'; var webpack = require("webpack"); +var prod = process.env.NODE_ENV && process.env.NODE_ENV === 'production'; + +var pluggins = [ + new webpack.optimize.DedupePlugin(), + new webpack.optimize.OccurenceOrderPlugin() +]; + +if (prod) + pluggins.push(new webpack.optimize.UglifyJsPlugin({ + mangle: true, + sourcemap: false, + minimize: true, + })); + module.exports = function(grunt) { grunt.config.set('webpack', { dev: { @@ -25,23 +39,32 @@ module.exports = function(grunt) { }, output: { path: ".tmp/public/js", - filename: "app.min.js" + filename: prod ? "app.min.js" : "app.js" }, - plugins: [ - new webpack.optimize.DedupePlugin(), - new webpack.optimize.OccurenceOrderPlugin(), - // new webpack.optimize.UglifyJsPlugin({ - // mangle: true, - // sourcemap: false - // }), - ], - + plugins: pluggins, + hot: false, inline: false, keepalive: false, - stats: false, watch: false, + progress: false, + stats: { + colors: true, + hash: false, + version: false, + timings: true, + assets: true, + chunks: true, + modules: true, + reasons: false, + children: false, + source: false, + errors: false, + errorDetails: false, + warnings: false, + publicPath: false + } } });