packager: optimize assets' JS

Reviewed By: davidaurelio

Differential Revision: D5010186

fbshipit-source-id: 3c26d8b8792df1dbc24e5200f28f63e017cb0173
This commit is contained in:
Jean Lauliac 2017-05-08 07:44:04 -07:00 committed by Facebook Github Bot
parent 2a5959ae6e
commit 7d6fec0a39
3 changed files with 23 additions and 4 deletions

View File

@ -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};

View File

@ -13,15 +13,14 @@
const uglify = require('uglify-js'); const uglify = require('uglify-js');
const {UGLIFY_JS_OUTPUT_OPTIONS} = require('./JsMinification');
function minify(filename: string, code: string, sourceMap: ?string) { function minify(filename: string, code: string, sourceMap: ?string) {
const minifyResult = uglify.minify(code, { const minifyResult = uglify.minify(code, {
fromString: true, fromString: true,
inSourceMap: sourceMap, inSourceMap: sourceMap,
outSourceMap: true, outSourceMap: true,
output: { output: UGLIFY_JS_OUTPUT_OPTIONS,
ascii_only: true,
screw_ie8: true,
},
}); });
minifyResult.map = JSON.parse(minifyResult.map); minifyResult.map = JSON.parse(minifyResult.map);

View File

@ -152,6 +152,7 @@ export type TransformedSourceFile =
export type LibraryOptions = {| export type LibraryOptions = {|
dependencies?: Array<string>, dependencies?: Array<string>,
optimize: boolean,
platform?: string, platform?: string,
rebasePath: string => string, rebasePath: string => string,
|}; |};