mirror of https://github.com/status-im/metro.git
Reduce source map in 44.5 MiB for Nuclide
Reviewed By: pakoito, davidaurelio Differential Revision: D5611240 fbshipit-source-id: b0090f6d07d3e08408fc27e91e462a2019130880
This commit is contained in:
parent
08947acde3
commit
e9d815c1fa
|
@ -269,7 +269,7 @@ class Bundle extends BundleBase {
|
|||
|
||||
return this._sourceMapFormat === 'indexed'
|
||||
? this._getCombinedSourceMaps(options)
|
||||
: fromRawMappings(this.getModules()).toMap();
|
||||
: fromRawMappings(this.getModules()).toMap(undefined, options);
|
||||
}
|
||||
|
||||
getSourceMapString(options: {excludeSource?: boolean}): string {
|
||||
|
@ -284,7 +284,10 @@ class Bundle extends BundleBase {
|
|||
let map = this._sourceMap;
|
||||
if (map == null) {
|
||||
debug('Start building flat source map');
|
||||
map = this._sourceMap = fromRawMappings(this.getModules()).toString();
|
||||
map = this._sourceMap = fromRawMappings(this.getModules()).toString(
|
||||
undefined,
|
||||
options,
|
||||
);
|
||||
debug('End building flat source map');
|
||||
} else {
|
||||
debug('Returning cached source map');
|
||||
|
|
|
@ -149,12 +149,20 @@ class Generator {
|
|||
/**
|
||||
* Return the source map as object.
|
||||
*/
|
||||
toMap(file?: string): MappingsMap {
|
||||
toMap(file?: string, options: {excludeSource?: boolean}): MappingsMap {
|
||||
let content;
|
||||
|
||||
if (options && options.excludeSource) {
|
||||
content = {};
|
||||
} else {
|
||||
content = {sourcesContent: this.sourcesContent.slice()};
|
||||
}
|
||||
|
||||
return {
|
||||
version: 3,
|
||||
file,
|
||||
sources: this.sources.slice(),
|
||||
sourcesContent: this.sourcesContent.slice(),
|
||||
...content,
|
||||
names: this.names.items(),
|
||||
mappings: this.builder.toString(),
|
||||
};
|
||||
|
@ -165,13 +173,21 @@ class Generator {
|
|||
*
|
||||
* This is ~2.5x faster than calling `JSON.stringify(generator.toMap())`
|
||||
*/
|
||||
toString(file?: string): string {
|
||||
toString(file?: string, options: {excludeSource?: boolean}): string {
|
||||
let content;
|
||||
|
||||
if (options && options.excludeSource) {
|
||||
content = '';
|
||||
} else {
|
||||
content = `"sourcesContent":${JSON.stringify(this.sourcesContent)},`;
|
||||
}
|
||||
|
||||
return (
|
||||
'{' +
|
||||
'"version":3,' +
|
||||
(file ? `"file":${JSON.stringify(file)},` : '') +
|
||||
`"sources":${JSON.stringify(this.sources)},` +
|
||||
`"sourcesContent":${JSON.stringify(this.sourcesContent)},` +
|
||||
content +
|
||||
`"names":${JSON.stringify(this.names.items())},` +
|
||||
`"mappings":"${this.builder.toString()}"` +
|
||||
'}'
|
||||
|
|
|
@ -5,6 +5,8 @@
|
|||
* 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.
|
||||
*
|
||||
* @emails oncall+javascript_tools
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
@ -156,6 +158,7 @@ describe('processRequest', () => {
|
|||
dev: true,
|
||||
entryFile: 'index.ios.js',
|
||||
entryModuleOnly: false,
|
||||
excludeSource: false,
|
||||
generateSourceMaps: false,
|
||||
hot: false,
|
||||
inlineSourceMap: false,
|
||||
|
@ -183,6 +186,7 @@ describe('processRequest', () => {
|
|||
dev: true,
|
||||
entryFile: 'index.js',
|
||||
entryModuleOnly: false,
|
||||
excludeSource: false,
|
||||
generateSourceMaps: false,
|
||||
hot: false,
|
||||
inlineSourceMap: false,
|
||||
|
@ -210,6 +214,7 @@ describe('processRequest', () => {
|
|||
dev: true,
|
||||
entryFile: 'index.js',
|
||||
entryModuleOnly: false,
|
||||
excludeSource: false,
|
||||
generateSourceMaps: false,
|
||||
hot: false,
|
||||
inlineSourceMap: false,
|
||||
|
@ -447,6 +452,7 @@ describe('processRequest', () => {
|
|||
dev: true,
|
||||
entryFile: 'foo file',
|
||||
entryModuleOnly: false,
|
||||
excludeSource: false,
|
||||
generateSourceMaps: false,
|
||||
hot: false,
|
||||
inlineSourceMap: false,
|
||||
|
@ -466,13 +472,14 @@ describe('processRequest', () => {
|
|||
|
||||
describe('buildBundleFromUrl(options)', () => {
|
||||
it('Calls the bundler with the correct args', () => {
|
||||
return server.buildBundleFromUrl('/path/to/foo.bundle?dev=false&runModule=false')
|
||||
return server.buildBundleFromUrl('/path/to/foo.bundle?dev=false&runModule=false&excludeSource=true')
|
||||
.then(() =>
|
||||
expect(Bundler.prototype.bundle).toBeCalledWith({
|
||||
assetPlugins: [],
|
||||
dev: false,
|
||||
entryFile: 'path/to/foo.js',
|
||||
entryModuleOnly: false,
|
||||
excludeSource: true,
|
||||
generateSourceMaps: true,
|
||||
hot: false,
|
||||
inlineSourceMap: false,
|
||||
|
@ -483,7 +490,7 @@ describe('processRequest', () => {
|
|||
resolutionResponse: null,
|
||||
runBeforeMainModule: ['InitializeCore'],
|
||||
runModule: false,
|
||||
sourceMapUrl: '/path/to/foo.map?dev=false&runModule=false',
|
||||
sourceMapUrl: '/path/to/foo.map?dev=false&runModule=false&excludeSource=true',
|
||||
unbundle: false,
|
||||
})
|
||||
);
|
||||
|
|
|
@ -102,6 +102,7 @@ export type BundleOptions = {
|
|||
dev: boolean,
|
||||
entryFile: string,
|
||||
+entryModuleOnly: boolean,
|
||||
+excludeSource: boolean,
|
||||
+generateSourceMaps: boolean,
|
||||
+hot: boolean,
|
||||
+inlineSourceMap: boolean,
|
||||
|
@ -790,6 +791,7 @@ class Server {
|
|||
log(createActionEndEntry(requestingBundleLogEntry));
|
||||
} else if (requestType === 'map') {
|
||||
const sourceMap = p.getSourceMapString({
|
||||
excludeSource: options.excludeSource,
|
||||
minify: options.minify,
|
||||
dev: options.dev,
|
||||
});
|
||||
|
@ -879,6 +881,7 @@ class Server {
|
|||
);
|
||||
return building.then(p =>
|
||||
p.getSourceMap({
|
||||
excludeSource: options.excludeSource,
|
||||
minify: options.minify,
|
||||
dev: options.dev,
|
||||
}),
|
||||
|
@ -994,6 +997,12 @@ class Server {
|
|||
|
||||
const dev = this._getBoolOptionFromQuery(urlObj.query, 'dev', true);
|
||||
const minify = this._getBoolOptionFromQuery(urlObj.query, 'minify', false);
|
||||
const excludeSource = this._getBoolOptionFromQuery(
|
||||
urlObj.query,
|
||||
'excludeSource',
|
||||
false,
|
||||
);
|
||||
|
||||
return {
|
||||
sourceMapUrl: url.format({
|
||||
hash: urlObj.hash,
|
||||
|
@ -1004,6 +1013,7 @@ class Server {
|
|||
entryFile,
|
||||
dev,
|
||||
minify,
|
||||
excludeSource,
|
||||
hot: this._getBoolOptionFromQuery(urlObj.query, 'hot', false),
|
||||
runBeforeMainModule: defaults.runBeforeMainModule,
|
||||
runModule: this._getBoolOptionFromQuery(urlObj.query, 'runModule', true),
|
||||
|
@ -1054,6 +1064,7 @@ Server.DEFAULT_BUNDLE_OPTIONS = {
|
|||
assetPlugins: [],
|
||||
dev: true,
|
||||
entryModuleOnly: false,
|
||||
excludeSource: false,
|
||||
generateSourceMaps: false,
|
||||
hot: false,
|
||||
inlineSourceMap: false,
|
||||
|
|
Loading…
Reference in New Issue