Add additional post process of SourceMap after the minification of JS

Reviewed By: davidaurelio

Differential Revision: D4955229

fbshipit-source-id: ac4e5f917839d43d73b80d98b4813d8ccf1d41ef
This commit is contained in:
Lukas Piatkowski 2017-05-03 03:45:04 -07:00 committed by Facebook Github Bot
parent 58f3046450
commit d016b2e9e4
4 changed files with 19 additions and 3 deletions

View File

@ -17,7 +17,7 @@ const debug = require('debug');
const invariant = require('fbjs/lib/invariant');
import type Server from './src/Server';
import type {PostProcessModules} from './src/Bundler';
import type {PostProcessModules, PostMinifyProcess} from './src/Bundler';
import type {GlobalTransformCache} from './src/lib/GlobalTransformCache';
import type {Reporter} from './src/lib/reporting';
import type {HasteImpl} from './src/node-haste/Module';
@ -30,6 +30,7 @@ type Options = {
globalTransformCache: ?GlobalTransformCache,
nonPersistent?: boolean,
postProcessModules?: PostProcessModules,
postMinifyProcess?: PostMinifyProcess,
projectRoots: Array<string>,
reporter?: Reporter,
watch?: boolean,

View File

@ -40,6 +40,7 @@ const VERSION = require('../../package.json').version;
import type AssetServer from '../AssetServer';
import type Module, {HasteImpl} from '../node-haste/Module';
import type ResolutionResponse from '../node-haste/DependencyGraph/ResolutionResponse';
import type {MappingsMap} from '../lib/SourceMap';
import type {Options as JSTransformerOptions} from '../JSTransformer/worker/worker';
import type {Reporter} from '../lib/reporting';
import type {GlobalTransformCache} from '../lib/GlobalTransformCache';
@ -112,6 +113,11 @@ export type PostProcessModules = (
options: PostProcessModulesOptions,
) => Array<ModuleTransport>;
export type PostMinifyProcess = ({
code: string,
map: MappingsMap,
}) => {code: string, map: MappingsMap};
type Options = {|
+allowBundleUpdates: boolean,
+assetExts: Array<string>,
@ -125,6 +131,7 @@ type Options = {|
+platforms: Array<string>,
+polyfillModuleNames: Array<string>,
+postProcessModules?: PostProcessModules,
+postMinifyProcess?: PostMinifyProcess,
+projectRoots: Array<string>,
+providesModuleNodeModules?: Array<string>,
+reporter: Reporter,
@ -206,6 +213,7 @@ class Bundler {
hasteImpl: opts.hasteImpl,
maxWorkerCount,
minifyCode: this._transformer.minify,
postMinifyProcess: this._opts.postMinifyProcess,
platforms: new Set(opts.platforms),
polyfillModuleNames: opts.polyfillModuleNames,
projectRoots: opts.projectRoots,

View File

@ -19,6 +19,7 @@ const pathJoin = require('path').join;
import type ResolutionResponse from '../node-haste/DependencyGraph/ResolutionResponse';
import type Module, {HasteImpl, TransformCode} from '../node-haste/Module';
import type {MappingsMap} from '../lib/SourceMap';
import type {PostMinifyProcess} from '../Bundler';
import type {Options as JSTransformerOptions} from '../JSTransformer/worker/worker';
import type {Reporter} from '../lib/reporting';
import type {GetTransformCacheKey} from '../lib/TransformCache';
@ -38,6 +39,7 @@ type Options = {|
+hasteImpl?: HasteImpl,
+maxWorkerCount: number,
+minifyCode: MinifyCode,
+postMinifyProcess?: PostMinifyProcess,
+platforms: Set<string>,
+polyfillModuleNames?: Array<string>,
+projectRoots: Array<string>,
@ -52,10 +54,12 @@ class Resolver {
_depGraph: DependencyGraph;
_minifyCode: MinifyCode;
_postMinifyProcess: ?PostMinifyProcess;
_polyfillModuleNames: Array<string>;
constructor(opts: Options, depGraph: DependencyGraph) {
this._minifyCode = opts.minifyCode;
this._postMinifyProcess = opts.postMinifyProcess;
this._polyfillModuleNames = opts.polyfillModuleNames || [];
this._depGraph = depGraph;
}
@ -222,7 +226,7 @@ class Resolver {
}
return minify
? this._minifyCode(module.path, code, map)
? this._minifyCode(module.path, code, map).then(this._postMinifyProcess)
: Promise.resolve({code, map});
}

View File

@ -32,7 +32,7 @@ import type ResolutionResponse from '../node-haste/DependencyGraph/ResolutionRes
import type Bundle from '../Bundler/Bundle';
import type HMRBundle from '../Bundler/HMRBundle';
import type {Reporter} from '../lib/reporting';
import type {GetTransformOptions, PostProcessModules} from '../Bundler';
import type {GetTransformOptions, PostProcessModules, PostMinifyProcess} from '../Bundler';
import type {GlobalTransformCache} from '../lib/GlobalTransformCache';
import type {SourceMap, Symbolicate} from './symbolicate';
@ -68,6 +68,7 @@ type Options = {
platforms?: Array<string>,
polyfillModuleNames?: Array<string>,
postProcessModules?: PostProcessModules,
postMinifyProcess?: PostMinifyProcess,
projectRoots: Array<string>,
providesModuleNodeModules?: Array<string>,
reporter: Reporter,
@ -122,6 +123,7 @@ class Server {
platforms: Array<string>,
polyfillModuleNames: Array<string>,
postProcessModules?: PostProcessModules,
postMinifyProcess?: PostMinifyProcess,
projectRoots: Array<string>,
providesModuleNodeModules?: Array<string>,
reporter: Reporter,
@ -158,6 +160,7 @@ class Server {
platforms: options.platforms || defaults.platforms,
polyfillModuleNames: options.polyfillModuleNames || [],
postProcessModules: options.postProcessModules,
postMinifyProcess: options.postMinifyProcess,
projectRoots: options.projectRoots,
providesModuleNodeModules: options.providesModuleNodeModules,
reporter: options.reporter,