Skip to content
This repository was archived by the owner on Feb 6, 2023. It is now read-only.

Commit 0a1f981

Browse files
altanofacebook-github-bot
authored andcommitted
Bundle size stats + Misc changes
Summary: **Summary** Misc changes that: 1. Make the dev environment work on Windows and Node v9. 1. Upgrade Webpack and UglifyJS. 1. Build now outputs build stats to the `meta/bundle-size-stats directory/` dir. 1. The build stats are named the current package version, e.g. the current one is `version-0.10.5.json`. 1. An example of this file can be seen here: https://files.terriblefish.com/version-0.10.5.json 1. This json file can be visualized in any of the various tools online, e.g. [the official tool](https://webpack.github.io/analyse) which is great for visualizing module dependencies and [this one from Chris Bateman](http://chrisbateman.github.io/webpack-visualizer/) that makes visualizing file sizes really nice. **Test Plan** `npm test`, `npm run lint`, and `npm run flow` all pass **Misc** * I don't think any of these changes need tests * No API changes Closes #1644 Reviewed By: flarnie Differential Revision: D6950926 Pulled By: flarnie fbshipit-source-id: 47de3b030087af010a19694caeca3de13d16a099
1 parent 3a3d34b commit 0a1f981

File tree

5 files changed

+600
-240
lines changed

5 files changed

+600
-240
lines changed

examples/draft-0-10-0/playground/src/App.js

-1
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,6 @@ class DraftJsPlaygroundContainer extends Component {
153153

154154
render() {
155155
const {editorState, mode, codeMirrorValue} = this.state;
156-
const lang = mode === 'html' ? mode : 'json';
157156

158157
return (
159158
<PanelGroup borderColor="grey">

gulpfile.js

+74-63
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,15 @@ var concatCSS = require('gulp-concat-css');
1616
var derequire = require('gulp-derequire');
1717
var flatten = require('gulp-flatten');
1818
var gulp = require('gulp');
19+
var gulpif = require('gulp-if');
1920
var gulpUtil = require('gulp-util');
2021
var header = require('gulp-header');
2122
var packageData = require('./package.json');
2223
var rename = require('gulp-rename');
2324
var runSequence = require('run-sequence');
25+
var StatsPlugin = require('stats-webpack-plugin');
2426
var through = require('through2');
27+
var UglifyJsPlugin = require('uglifyjs-webpack-plugin');
2528
var webpackStream = require('webpack-stream');
2629

2730
var fbjsConfigurePreset = require('babel-preset-fbjs/configure');
@@ -37,9 +40,7 @@ var paths = {
3740
'!src/**/__tests__/**/*.js',
3841
'!src/**/__mocks__/**/*.js',
3942
],
40-
css: [
41-
'src/**/*.css',
42-
],
43+
css: ['src/**/*.css'],
4344
};
4445

4546
var babelOptsJS = {
@@ -74,7 +75,6 @@ var COPYRIGHT_HEADER = `/**
7475

7576
var buildDist = function(opts) {
7677
var webpackOpts = {
77-
debug: opts.debug,
7878
externals: {
7979
immutable: {
8080
root: 'Immutable',
@@ -103,23 +103,22 @@ var buildDist = function(opts) {
103103
plugins: [
104104
new webpackStream.webpack.DefinePlugin({
105105
'process.env.NODE_ENV': JSON.stringify(
106-
opts.debug ? 'development' : 'production'
106+
opts.debug ? 'development' : 'production',
107107
),
108108
}),
109-
new webpackStream.webpack.optimize.OccurenceOrderPlugin(),
110-
new webpackStream.webpack.optimize.DedupePlugin(),
109+
new webpackStream.webpack.LoaderOptionsPlugin({
110+
debug: true,
111+
}),
112+
new StatsPlugin(
113+
'../meta/bundle-size-stats/version-' + packageData.version + '.json',
114+
{
115+
chunkModules: true,
116+
},
117+
),
111118
],
112119
};
113120
if (!opts.debug) {
114-
webpackOpts.plugins.push(
115-
new webpackStream.webpack.optimize.UglifyJsPlugin({
116-
compress: {
117-
hoist_vars: true,
118-
screw_ie8: true,
119-
warnings: false,
120-
},
121-
})
122-
);
121+
webpackOpts.plugins.push(new UglifyJsPlugin());
123122
}
124123
return webpackStream(webpackOpts, null, function(err, stats) {
125124
if (err) {
@@ -153,56 +152,61 @@ gulp.task('flow', function() {
153152
});
154153

155154
gulp.task('css', function() {
156-
return gulp
157-
.src(paths.css)
158-
.pipe(through.obj(function(file, encoding, callback) {
159-
var contents = file.contents.toString();
160-
var replaced = contents.replace(
161-
// Regex based on MakeHasteCssModuleTransform: ignores comments,
162-
// strings, and URLs
163-
/\/\*.*?\*\/|'(?:\\.|[^'])*'|"(?:\\.|[^"])*"|url\([^)]*\)|(\.(?:public\/)?[\w-]*\/{1,2}[\w-]+)/g,
164-
function(match, cls) {
165-
if (cls) {
166-
return cls.replace(/\//g, '-');
167-
} else {
168-
return match;
169-
}
170-
}
171-
);
172-
replaced = replaced.replace(
173-
// MakeHasteCssVariablesTransform
174-
/\bvar\(([\w-]+)\)/g,
175-
function(match, name) {
176-
var vars = {
177-
'fig-secondary-text': '#9197a3',
178-
'fig-light-20': '#bdc1c9',
179-
};
180-
if (vars[name]) {
181-
return vars[name];
182-
} else {
183-
throw new Error('Unknown CSS variable ' + name);
184-
}
185-
}
186-
);
187-
file.contents = new Buffer(replaced);
188-
callback(null, file);
189-
}))
190-
.pipe(concatCSS('Draft.css'))
191-
// Avoid rewriting rules *just in case*, just compress
192-
.pipe(cleanCSS({advanced: false}))
193-
.pipe(header(COPYRIGHT_HEADER, {version: packageData.version}))
194-
.pipe(gulp.dest(paths.dist));
155+
return (gulp
156+
.src(paths.css)
157+
.pipe(
158+
through.obj(function(file, encoding, callback) {
159+
var contents = file.contents.toString();
160+
var replaced = contents.replace(
161+
// Regex based on MakeHasteCssModuleTransform: ignores comments,
162+
// strings, and URLs
163+
/\/\*.*?\*\/|'(?:\\.|[^'])*'|"(?:\\.|[^"])*"|url\([^)]*\)|(\.(?:public\/)?[\w-]*\/{1,2}[\w-]+)/g,
164+
function(match, cls) {
165+
if (cls) {
166+
return cls.replace(/\//g, '-');
167+
} else {
168+
return match;
169+
}
170+
},
171+
);
172+
replaced = replaced.replace(
173+
// MakeHasteCssVariablesTransform
174+
/\bvar\(([\w-]+)\)/g,
175+
function(match, name) {
176+
var vars = {
177+
'fig-secondary-text': '#9197a3',
178+
'fig-light-20': '#bdc1c9',
179+
};
180+
if (vars[name]) {
181+
return vars[name];
182+
} else {
183+
throw new Error('Unknown CSS variable ' + name);
184+
}
185+
},
186+
);
187+
file.contents = new Buffer(replaced);
188+
callback(null, file);
189+
}),
190+
)
191+
.pipe(concatCSS('Draft.css'))
192+
// Avoid rewriting rules *just in case*, just compress
193+
.pipe(cleanCSS({advanced: false}))
194+
.pipe(header(COPYRIGHT_HEADER, {version: packageData.version}))
195+
.pipe(gulp.dest(paths.dist)) );
195196
});
196197

197198
gulp.task('dist', ['modules', 'css'], function() {
198199
var opts = {
199200
debug: true,
200201
output: 'Draft.js',
201202
};
202-
return gulp.src('./lib/Draft.js')
203+
return gulp
204+
.src('./lib/Draft.js')
203205
.pipe(buildDist(opts))
204206
.pipe(derequire())
205-
.pipe(header(COPYRIGHT_HEADER, {version: packageData.version}))
207+
.pipe(
208+
gulpif('*.js', header(COPYRIGHT_HEADER, {version: packageData.version})),
209+
)
206210
.pipe(gulp.dest(paths.dist));
207211
});
208212

@@ -211,16 +215,17 @@ gulp.task('dist:min', ['modules'], function() {
211215
debug: false,
212216
output: 'Draft.min.js',
213217
};
214-
return gulp.src('./lib/Draft.js')
218+
return gulp
219+
.src('./lib/Draft.js')
215220
.pipe(buildDist(opts))
216-
.pipe(header(COPYRIGHT_HEADER, {version: packageData.version}))
221+
.pipe(
222+
gulpif('*.js', header(COPYRIGHT_HEADER, {version: packageData.version})),
223+
)
217224
.pipe(gulp.dest(paths.dist));
218225
});
219226

220227
gulp.task('check-dependencies', function() {
221-
return gulp
222-
.src('package.json')
223-
.pipe(gulpCheckDependencies());
228+
return gulp.src('package.json').pipe(gulpCheckDependencies());
224229
});
225230

226231
gulp.task('watch', function() {
@@ -232,5 +237,11 @@ gulp.task('dev', function() {
232237
});
233238

234239
gulp.task('default', function(cb) {
235-
runSequence('check-dependencies', 'clean', ['modules', 'flow'], ['dist', 'dist:min'], cb);
240+
runSequence(
241+
'check-dependencies',
242+
'clean',
243+
['modules', 'flow'],
244+
['dist', 'dist:min'],
245+
cb,
246+
);
236247
});

meta/bundle-size-stats/version-0.10.5.json

+1
Large diffs are not rendered by default.

package.json

+9-5
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,14 @@
2929
"lint": "eslint .",
3030
"format": "eslint . --fix",
3131
"flow": "flow src",
32-
"test": "NODE_ENV=test jest",
33-
"test-ci": "NODE_ENV=test npm run lint && npm run flow && npm run test"
32+
"test": "cross-env NODE_ENV=test jest",
33+
"test-ci": "cross-env NODE_ENV=test npm run lint && npm run flow && npm run test"
3434
},
3535
"dependencies": {
3636
"fbjs": "^0.8.15",
3737
"immutable": "~3.7.4",
38-
"object-assign": "^4.1.0"
38+
"object-assign": "^4.1.0",
39+
"uglifyjs-webpack-plugin": "^1.1.6"
3940
},
4041
"peerDependencies": {
4142
"react": "^0.14.0 || ^15.0.0-rc || ^16.0.0-rc || ^16.0.0",
@@ -45,6 +46,7 @@
4546
"babel-core": "^6.8.0",
4647
"babel-eslint": "^7.2.3",
4748
"babel-preset-fbjs": "^2.1.0",
49+
"cross-env": "^5.1.3",
4850
"del": "^2.2.0",
4951
"envify": "^3.4.0",
5052
"es6-shim": "^0.34.4",
@@ -67,6 +69,7 @@
6769
"gulp-derequire": "^2.1.0",
6870
"gulp-flatten": "^0.2.0",
6971
"gulp-header": "1.8.2",
72+
"gulp-if": "^2.0.2",
7073
"gulp-rename": "^1.2.2",
7174
"gulp-uglify": "^1.2.0",
7275
"gulp-util": "^3.0.6",
@@ -76,12 +79,13 @@
7679
"react-dom": "^16.0.0",
7780
"react-test-renderer": "^16.0.0",
7881
"run-sequence": "^1.1.2",
82+
"stats-webpack-plugin": "^0.6.2",
7983
"through2": "^2.0.1",
8084
"vinyl-buffer": "^1.0.0",
81-
"webpack-stream": "^3.0.0"
85+
"webpack-stream": "^4.0.0"
8286
},
8387
"devEngines": {
84-
"node": "6.x || 8.x",
88+
"node": "6.x || 8.x || 9.x",
8589
"npm": "2.x || 3.x || 5.x"
8690
},
8791
"jest": {

0 commit comments

Comments
 (0)