mirror of https://github.com/status-im/metro.git
Add minifier-path option to Metro
Summary: This exposes the `minifierPath` externally and allows it to be adjusted through the `--minifier-path` argument. This works for both the server (when starting the server) and running a single build through the CLI. In server mode, this can not be used per file request yet, though that should also be doable if need be. Reviewed By: rafeca Differential Revision: D6998562 fbshipit-source-id: 669b876c24fe117ec88b2200d48aa82658f568b4
This commit is contained in:
parent
c080d70699
commit
5aa19c7626
|
@ -89,6 +89,7 @@ export type Options = {|
|
|||
+globalTransformCache: ?GlobalTransformCache,
|
||||
+hasteImplModulePath?: string,
|
||||
+maxWorkers: number,
|
||||
+minifierPath: string,
|
||||
+platforms: Array<string>,
|
||||
+polyfillModuleNames: Array<string>,
|
||||
+postMinifyProcess: PostMinifyProcess,
|
||||
|
@ -120,8 +121,7 @@ class Bundler {
|
|||
this._transformer = new Transformer({
|
||||
asyncRequireModulePath: opts.asyncRequireModulePath,
|
||||
maxWorkers: opts.maxWorkers,
|
||||
// TODO t26063242 make this an option
|
||||
minifierPath: defaults.DEFAULT_METRO_MINIFIER_PATH,
|
||||
minifierPath: opts.minifierPath,
|
||||
reporters: {
|
||||
stdoutChunk: chunk =>
|
||||
opts.reporter.update({type: 'worker_stdout_chunk', chunk}),
|
||||
|
|
|
@ -33,6 +33,7 @@ const bundlerOptions = {
|
|||
cacheVersion: 'smth',
|
||||
enableBabelRCLookup: true,
|
||||
extraNodeModules: {},
|
||||
minifierPath: defaults.DEFAULT_METRO_MINIFIER_PATH,
|
||||
platforms: defaults.platforms,
|
||||
resetCache: false,
|
||||
sourceExts: defaults.sourceExts,
|
||||
|
|
|
@ -28,6 +28,7 @@ const symbolicate = require('./symbolicate');
|
|||
const url = require('url');
|
||||
|
||||
const {getAsset} = require('../Assets');
|
||||
const resolveSync: ResolveSync = require('resolve').sync;
|
||||
|
||||
import type {CustomError} from '../lib/formatBundlingError';
|
||||
import type {IncomingMessage, ServerResponse} from 'http';
|
||||
|
@ -49,6 +50,8 @@ const {
|
|||
Logger: {createActionStartEntry, createActionEndEntry, log},
|
||||
} = require('metro-core');
|
||||
|
||||
type ResolveSync = (path: string, opts: ?{baseDir?: string}) => string;
|
||||
|
||||
function debounceAndBatch(fn, delay) {
|
||||
let timeout;
|
||||
return () => {
|
||||
|
@ -71,6 +74,7 @@ class Server {
|
|||
getTransformOptions?: GetTransformOptions,
|
||||
hasteImplModulePath?: string,
|
||||
maxWorkers: number,
|
||||
minifierPath: string,
|
||||
moduleFormat: string,
|
||||
platforms: Array<string>,
|
||||
polyfillModuleNames: Array<string>,
|
||||
|
@ -127,6 +131,10 @@ class Server {
|
|||
globalTransformCache: options.globalTransformCache,
|
||||
hasteImplModulePath: options.hasteImplModulePath,
|
||||
maxWorkers,
|
||||
minifierPath:
|
||||
options.minifierPath == null
|
||||
? defaults.DEFAULT_METRO_MINIFIER_PATH
|
||||
: resolveSync(options.minifierPath, {basedir: process.cwd()}),
|
||||
moduleFormat:
|
||||
options.moduleFormat != null ? options.moduleFormat : 'haste',
|
||||
platforms: options.platforms || defaults.platforms,
|
||||
|
|
|
@ -49,6 +49,7 @@ type PublicMetroOptions = {|
|
|||
config?: ConfigT,
|
||||
globalTransformCache?: ?GlobalTransformCache,
|
||||
maxWorkers?: number,
|
||||
minifierPath?: string,
|
||||
port?: ?number,
|
||||
reporter?: Reporter,
|
||||
transformCache?: TransformCache,
|
||||
|
@ -86,6 +87,7 @@ async function runMetro({
|
|||
globalTransformCache,
|
||||
resetCache = false,
|
||||
maxWorkers = getMaxWorkers(),
|
||||
minifierPath,
|
||||
// $FlowFixMe TODO t0 https://github.com/facebook/flow/issues/183
|
||||
port = null,
|
||||
reporter = new TerminalReporter(new Terminal(process.stdout)),
|
||||
|
@ -133,6 +135,7 @@ async function runMetro({
|
|||
globalTransformCache,
|
||||
hasteImplModulePath: normalizedConfig.hasteImplModulePath,
|
||||
maxWorkers,
|
||||
minifierPath,
|
||||
platforms: defaults.platforms.concat(platforms),
|
||||
postMinifyProcess: normalizedConfig.postMinifyProcess,
|
||||
postProcessModules: normalizedConfig.postProcessModules,
|
||||
|
@ -208,6 +211,7 @@ type RunServerOptions = {|
|
|||
exports.runServer = async ({
|
||||
host,
|
||||
onReady,
|
||||
minifierPath,
|
||||
// $FlowFixMe Flow messes up when using "destructuring"+"default value"+"spread typing"+"stricter field typing" together
|
||||
port = 8080,
|
||||
reporter = new TerminalReporter(new Terminal(process.stdout)),
|
||||
|
@ -231,6 +235,7 @@ exports.runServer = async ({
|
|||
...rest,
|
||||
port,
|
||||
reporter,
|
||||
minifierPath,
|
||||
});
|
||||
|
||||
serverApp.use(middleware);
|
||||
|
|
|
@ -183,6 +183,7 @@ function toServerOptions(options: Options): ServerOptions {
|
|||
globalTransformCache: options.globalTransformCache,
|
||||
hasteImplModulePath: options.hasteImplModulePath,
|
||||
maxWorkers: options.maxWorkers,
|
||||
minifierPath: options.minifierPath,
|
||||
moduleFormat: options.moduleFormat,
|
||||
platforms: options.platforms,
|
||||
polyfillModuleNames: options.polyfillModuleNames,
|
||||
|
|
|
@ -83,6 +83,7 @@ export type Options = {|
|
|||
globalTransformCache: ?GlobalTransformCache,
|
||||
hasteImplModulePath?: string,
|
||||
maxWorkers?: number,
|
||||
minifierPath?: string,
|
||||
moduleFormat?: string,
|
||||
platforms?: Array<string>,
|
||||
polyfillModuleNames?: Array<string>,
|
||||
|
|
Loading…
Reference in New Issue