From 46d4eee57fad380e852b1f45b67ec28127b2d342 Mon Sep 17 00:00:00 2001 From: Simon Egersand Date: Fri, 16 Sep 2016 03:21:55 +0200 Subject: [PATCH] Change build configuration By changing the build config a source map file was added, which is useful for debugging. The non-minified file size was decreased by 3.5kB. The source map file should be included in production so people can use it for debugging. --- gulpfile.js | 16 +++++++++++----- package.json | 1 + webpack.config.js | 4 +++- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/gulpfile.js b/gulpfile.js index 5176a4948..91b8a0c93 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -1,7 +1,8 @@ var gulp = require('gulp'), uglify = require('gulp-uglify'), insert = require('gulp-insert'), - webpack = require('gulp-webpack') + webpack = require('gulp-webpack'), + sourcemaps = require('gulp-sourcemaps') ; var packageName = 'react-datetime'; @@ -34,22 +35,27 @@ var handleError = function( err ){ }; function wp( config, minify ){ - var stream = gulp.src('./Datetime.js') + var inputSrc = './Datetime.js'; + var destSrc = 'dist/'; + + var stream = gulp.src( inputSrc ) .pipe( webpack( config ) ) + .pipe( sourcemaps.init() ) ; if( minify ){ stream = stream.pipe( uglify() ).on( 'error', handleError ); } - return stream.pipe( insert.prepend( cr ) ) - .pipe( gulp.dest('dist/') ) + return stream.pipe( sourcemaps.write() ) + .pipe( insert.prepend( cr ) ) + .pipe( gulp.dest( destSrc ) ) ; } gulp.task( 'build', function( callback ) { var config = getWPConfig( 'react-datetime' ); - config.devtool = '#eval'; + config.devtool = 'cheap-module-source-map'; wp( config ); config = getWPConfig( 'react-datetime.min' ); diff --git a/package.json b/package.json index 53ab6ed8d..ae6bcce01 100644 --- a/package.json +++ b/package.json @@ -37,6 +37,7 @@ "gulp-insert": "^0.4.0", "gulp-uglify": "^1.2.0", "gulp-webpack": "^1.5.0", + "gulp-sourcemaps": "^1.6.0", "jsdom": "^7.0.2", "mocha": "^2.2.5", "moment": "2.14.1", diff --git a/webpack.config.js b/webpack.config.js index c0f00979a..4d12059f9 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -2,7 +2,9 @@ var webpack = require('webpack'); var plugins = [ new webpack.DefinePlugin({ - 'process.env': { NODE_ENV: '"production"'} + 'process.env': { + 'NODE_ENV': JSON.stringify('production') + } }) ];