Skip to content
Browse files

Make some dist build changes

Summary:- Inline `process.env.NODE_ENV === 'production'` checks
- Compress CSS
- Add copyright headers to dist files

It's not a *huge* difference on the size front but definitely better. And the copyright thing is something we should do regardless of the rest.
<img width="591" alt="screen shot 2016-03-09 at 4 26 17 pm" src="https://cloud.githubusercontent.com/assets/8445/13655376/bc78d212-e613-11e5-8f39-0268bf4d32f2.png">
Closes #189

Differential Revision: D3034186

fb-gh-sync-id: ede05fcc42f4d3831edcd809adb204f3f6ddf8f2
shipit-source-id: ede05fcc42f4d3831edcd809adb204f3f6ddf8f2
  • Loading branch information...
1 parent ebd782c commit 17559052075ed4cfb08d38d7e128d4ff3d7432aa @zpao zpao committed with Facebook Github Bot 5
Showing with 27 additions and 0 deletions.
  1. +25 −0 gulpfile.js
  2. +2 −0 package.json
View
25 gulpfile.js
@@ -11,11 +11,14 @@
var babel = require('gulp-babel');
var del = require('del');
+var cleanCSS = require('gulp-clean-css');
var concatCSS = require('gulp-concat-css');
var derequire = require('gulp-derequire');
var flatten = require('gulp-flatten');
var gulp = require('gulp');
var gulpUtil = require('gulp-util');
+var header = require('gulp-header');
+var packageData = require('./package.json');
var runSequence = require('run-sequence');
var through = require('through2');
var webpackStream = require('webpack-stream');
@@ -41,6 +44,18 @@ var paths = {
// options, converting __DEV__.
babelOpts.plugins.push(babelPluginDEV);
+var COPYRIGHT_HEADER = `/**
+ * Draft v<%= version %>
+ *
+ * Copyright (c) 2013-present, Facebook, Inc.
+ * All rights reserved.
+ *
+ * This source code is licensed under the BSD-style license found in the
+ * LICENSE file in the root directory of this source tree. An additional grant
+ * of patent rights can be found in the PATENTS file in the same directory.
+ */
+`;
+
var buildDist = function(opts) {
var webpackOpts = {
debug: opts.debug,
@@ -55,6 +70,11 @@ var buildDist = function(opts) {
library: 'Draft',
},
plugins: [
+ new webpackStream.webpack.DefinePlugin({
+ 'process.env.NODE_ENV': JSON.stringify(
+ opts.debug ? 'development' : 'production'
+ ),
+ }),
new webpackStream.webpack.optimize.OccurenceOrderPlugin(),
new webpackStream.webpack.optimize.DedupePlugin(),
],
@@ -128,6 +148,9 @@ gulp.task('css', function() {
callback(null, file);
}))
.pipe(concatCSS('Draft.css'))
+ // Avoid rewriting rules *just in case*, just compress
+ .pipe(cleanCSS({advanced: false}))
+ .pipe(header(COPYRIGHT_HEADER, {version: packageData.version}))
.pipe(gulp.dest(paths.dist));
});
@@ -139,6 +162,7 @@ gulp.task('dist', ['modules', 'css'], function() {
return gulp.src('./lib/Draft.js')
.pipe(buildDist(opts))
.pipe(derequire())
+ .pipe(header(COPYRIGHT_HEADER, {version: packageData.version}))
.pipe(gulp.dest(paths.dist));
});
@@ -149,6 +173,7 @@ gulp.task('dist:min', ['modules'], function() {
};
return gulp.src('./lib/Draft.js')
.pipe(buildDist(opts))
+ .pipe(header(COPYRIGHT_HEADER, {version: packageData.version}))
.pipe(gulp.dest(paths.dist));
});
View
2 package.json
@@ -47,9 +47,11 @@
"gulp": "^3.9.0",
"gulp-babel": "^5.1.0",
"gulp-browserify-thin": "^0.1.5",
+ "gulp-clean-css": "^2.0.3",
"gulp-concat-css": "^2.2.0",
"gulp-derequire": "^2.1.0",
"gulp-flatten": "^0.2.0",
+ "gulp-header": "^1.7.1",
"gulp-uglify": "^1.2.0",
"gulp-util": "^3.0.6",
"jest-cli": "^0.9.0-fb1",

0 comments on commit 1755905

Please sign in to comment.
Something went wrong with that request. Please try again.