From 7d6fec0a39a125404d31162546039104b004e1c5 Mon Sep 17 00:00:00 2001 From: Jean Lauliac Date: Mon, 8 May 2017 07:44:04 -0700 Subject: [PATCH] packager: optimize assets' JS Reviewed By: davidaurelio Differential Revision: D5010186 fbshipit-source-id: 3c26d8b8792df1dbc24e5200f28f63e017cb0173 --- .../JSTransformer/worker/JsMinification.js | 19 +++++++++++++++++++ packager/src/JSTransformer/worker/minify.js | 7 +++---- packager/src/ModuleGraph/types.flow.js | 1 + 3 files changed, 23 insertions(+), 4 deletions(-) create mode 100644 packager/src/JSTransformer/worker/JsMinification.js diff --git a/packager/src/JSTransformer/worker/JsMinification.js b/packager/src/JSTransformer/worker/JsMinification.js new file mode 100644 index 00000000000..580212ebb72 --- /dev/null +++ b/packager/src/JSTransformer/worker/JsMinification.js @@ -0,0 +1,19 @@ +/** + * Copyright (c) 2016-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. + * + * @flow + */ + +'use strict'; + +const UGLIFY_JS_OUTPUT_OPTIONS = { + ascii_only: true, + screw_ie8: true, +}; + +module.exports = {UGLIFY_JS_OUTPUT_OPTIONS}; diff --git a/packager/src/JSTransformer/worker/minify.js b/packager/src/JSTransformer/worker/minify.js index e92513a69c9..deceb4cbe13 100644 --- a/packager/src/JSTransformer/worker/minify.js +++ b/packager/src/JSTransformer/worker/minify.js @@ -13,15 +13,14 @@ const uglify = require('uglify-js'); +const {UGLIFY_JS_OUTPUT_OPTIONS} = require('./JsMinification'); + function minify(filename: string, code: string, sourceMap: ?string) { const minifyResult = uglify.minify(code, { fromString: true, inSourceMap: sourceMap, outSourceMap: true, - output: { - ascii_only: true, - screw_ie8: true, - }, + output: UGLIFY_JS_OUTPUT_OPTIONS, }); minifyResult.map = JSON.parse(minifyResult.map); diff --git a/packager/src/ModuleGraph/types.flow.js b/packager/src/ModuleGraph/types.flow.js index 4070f27c338..c1c56074450 100644 --- a/packager/src/ModuleGraph/types.flow.js +++ b/packager/src/ModuleGraph/types.flow.js @@ -152,6 +152,7 @@ export type TransformedSourceFile = export type LibraryOptions = {| dependencies?: Array, + optimize: boolean, platform?: string, rebasePath: string => string, |};