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:
parent
e135bacb48
commit
976a181a1c
|
@ -15,7 +15,7 @@ const Config = require('../util/Config');
|
|||
const defaultConfig = require('./default.config');
|
||||
const minimist = require('minimist');
|
||||
|
||||
import type {GetTransformOptions, PostProcessModules} from '../../packager/src/Bundler';
|
||||
import type {GetTransformOptions, PostProcessModules, PostMinifyProcess} from '../../packager/src/Bundler';
|
||||
import type {HasteImpl} from '../../packager/src/node-haste/Module';
|
||||
import type {CommandT} from '../commands';
|
||||
|
||||
|
@ -74,6 +74,12 @@ export type ConfigT = {
|
|||
*/
|
||||
postProcessModules?: PostProcessModules,
|
||||
|
||||
/**
|
||||
* An optional function that can modify the code and source map of bundle
|
||||
* after the minifaction took place.
|
||||
*/
|
||||
postMinifyProcess?: PostMinifyProcess,
|
||||
|
||||
/**
|
||||
* A module that exports:
|
||||
* - a `getHasteName(filePath)` method that returns `hasteName` for module at
|
||||
|
|
|
@ -111,6 +111,7 @@ function getPackagerServer(args, config) {
|
|||
hasteImpl: config.hasteImpl,
|
||||
platforms: defaultPlatforms.concat(args.platforms),
|
||||
postProcessModules: config.postProcessModules,
|
||||
postMinifyProcess: config.postMinifyProcess,
|
||||
projectRoots: args.projectRoots,
|
||||
providesModuleNodeModules: providesModuleNodeModules,
|
||||
reporter: new LogReporter(),
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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});
|
||||
}
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue