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,
|
+globalTransformCache: ?GlobalTransformCache,
|
||||||
+hasteImplModulePath?: string,
|
+hasteImplModulePath?: string,
|
||||||
+maxWorkers: number,
|
+maxWorkers: number,
|
||||||
|
+minifierPath: string,
|
||||||
+platforms: Array<string>,
|
+platforms: Array<string>,
|
||||||
+polyfillModuleNames: Array<string>,
|
+polyfillModuleNames: Array<string>,
|
||||||
+postMinifyProcess: PostMinifyProcess,
|
+postMinifyProcess: PostMinifyProcess,
|
||||||
|
@ -120,8 +121,7 @@ class Bundler {
|
||||||
this._transformer = new Transformer({
|
this._transformer = new Transformer({
|
||||||
asyncRequireModulePath: opts.asyncRequireModulePath,
|
asyncRequireModulePath: opts.asyncRequireModulePath,
|
||||||
maxWorkers: opts.maxWorkers,
|
maxWorkers: opts.maxWorkers,
|
||||||
// TODO t26063242 make this an option
|
minifierPath: opts.minifierPath,
|
||||||
minifierPath: defaults.DEFAULT_METRO_MINIFIER_PATH,
|
|
||||||
reporters: {
|
reporters: {
|
||||||
stdoutChunk: chunk =>
|
stdoutChunk: chunk =>
|
||||||
opts.reporter.update({type: 'worker_stdout_chunk', chunk}),
|
opts.reporter.update({type: 'worker_stdout_chunk', chunk}),
|
||||||
|
|
|
@ -33,6 +33,7 @@ const bundlerOptions = {
|
||||||
cacheVersion: 'smth',
|
cacheVersion: 'smth',
|
||||||
enableBabelRCLookup: true,
|
enableBabelRCLookup: true,
|
||||||
extraNodeModules: {},
|
extraNodeModules: {},
|
||||||
|
minifierPath: defaults.DEFAULT_METRO_MINIFIER_PATH,
|
||||||
platforms: defaults.platforms,
|
platforms: defaults.platforms,
|
||||||
resetCache: false,
|
resetCache: false,
|
||||||
sourceExts: defaults.sourceExts,
|
sourceExts: defaults.sourceExts,
|
||||||
|
|
|
@ -28,6 +28,7 @@ const symbolicate = require('./symbolicate');
|
||||||
const url = require('url');
|
const url = require('url');
|
||||||
|
|
||||||
const {getAsset} = require('../Assets');
|
const {getAsset} = require('../Assets');
|
||||||
|
const resolveSync: ResolveSync = require('resolve').sync;
|
||||||
|
|
||||||
import type {CustomError} from '../lib/formatBundlingError';
|
import type {CustomError} from '../lib/formatBundlingError';
|
||||||
import type {IncomingMessage, ServerResponse} from 'http';
|
import type {IncomingMessage, ServerResponse} from 'http';
|
||||||
|
@ -49,6 +50,8 @@ const {
|
||||||
Logger: {createActionStartEntry, createActionEndEntry, log},
|
Logger: {createActionStartEntry, createActionEndEntry, log},
|
||||||
} = require('metro-core');
|
} = require('metro-core');
|
||||||
|
|
||||||
|
type ResolveSync = (path: string, opts: ?{baseDir?: string}) => string;
|
||||||
|
|
||||||
function debounceAndBatch(fn, delay) {
|
function debounceAndBatch(fn, delay) {
|
||||||
let timeout;
|
let timeout;
|
||||||
return () => {
|
return () => {
|
||||||
|
@ -71,6 +74,7 @@ class Server {
|
||||||
getTransformOptions?: GetTransformOptions,
|
getTransformOptions?: GetTransformOptions,
|
||||||
hasteImplModulePath?: string,
|
hasteImplModulePath?: string,
|
||||||
maxWorkers: number,
|
maxWorkers: number,
|
||||||
|
minifierPath: string,
|
||||||
moduleFormat: string,
|
moduleFormat: string,
|
||||||
platforms: Array<string>,
|
platforms: Array<string>,
|
||||||
polyfillModuleNames: Array<string>,
|
polyfillModuleNames: Array<string>,
|
||||||
|
@ -127,6 +131,10 @@ class Server {
|
||||||
globalTransformCache: options.globalTransformCache,
|
globalTransformCache: options.globalTransformCache,
|
||||||
hasteImplModulePath: options.hasteImplModulePath,
|
hasteImplModulePath: options.hasteImplModulePath,
|
||||||
maxWorkers,
|
maxWorkers,
|
||||||
|
minifierPath:
|
||||||
|
options.minifierPath == null
|
||||||
|
? defaults.DEFAULT_METRO_MINIFIER_PATH
|
||||||
|
: resolveSync(options.minifierPath, {basedir: process.cwd()}),
|
||||||
moduleFormat:
|
moduleFormat:
|
||||||
options.moduleFormat != null ? options.moduleFormat : 'haste',
|
options.moduleFormat != null ? options.moduleFormat : 'haste',
|
||||||
platforms: options.platforms || defaults.platforms,
|
platforms: options.platforms || defaults.platforms,
|
||||||
|
|
|
@ -49,6 +49,7 @@ type PublicMetroOptions = {|
|
||||||
config?: ConfigT,
|
config?: ConfigT,
|
||||||
globalTransformCache?: ?GlobalTransformCache,
|
globalTransformCache?: ?GlobalTransformCache,
|
||||||
maxWorkers?: number,
|
maxWorkers?: number,
|
||||||
|
minifierPath?: string,
|
||||||
port?: ?number,
|
port?: ?number,
|
||||||
reporter?: Reporter,
|
reporter?: Reporter,
|
||||||
transformCache?: TransformCache,
|
transformCache?: TransformCache,
|
||||||
|
@ -86,6 +87,7 @@ async function runMetro({
|
||||||
globalTransformCache,
|
globalTransformCache,
|
||||||
resetCache = false,
|
resetCache = false,
|
||||||
maxWorkers = getMaxWorkers(),
|
maxWorkers = getMaxWorkers(),
|
||||||
|
minifierPath,
|
||||||
// $FlowFixMe TODO t0 https://github.com/facebook/flow/issues/183
|
// $FlowFixMe TODO t0 https://github.com/facebook/flow/issues/183
|
||||||
port = null,
|
port = null,
|
||||||
reporter = new TerminalReporter(new Terminal(process.stdout)),
|
reporter = new TerminalReporter(new Terminal(process.stdout)),
|
||||||
|
@ -133,6 +135,7 @@ async function runMetro({
|
||||||
globalTransformCache,
|
globalTransformCache,
|
||||||
hasteImplModulePath: normalizedConfig.hasteImplModulePath,
|
hasteImplModulePath: normalizedConfig.hasteImplModulePath,
|
||||||
maxWorkers,
|
maxWorkers,
|
||||||
|
minifierPath,
|
||||||
platforms: defaults.platforms.concat(platforms),
|
platforms: defaults.platforms.concat(platforms),
|
||||||
postMinifyProcess: normalizedConfig.postMinifyProcess,
|
postMinifyProcess: normalizedConfig.postMinifyProcess,
|
||||||
postProcessModules: normalizedConfig.postProcessModules,
|
postProcessModules: normalizedConfig.postProcessModules,
|
||||||
|
@ -208,6 +211,7 @@ type RunServerOptions = {|
|
||||||
exports.runServer = async ({
|
exports.runServer = async ({
|
||||||
host,
|
host,
|
||||||
onReady,
|
onReady,
|
||||||
|
minifierPath,
|
||||||
// $FlowFixMe Flow messes up when using "destructuring"+"default value"+"spread typing"+"stricter field typing" together
|
// $FlowFixMe Flow messes up when using "destructuring"+"default value"+"spread typing"+"stricter field typing" together
|
||||||
port = 8080,
|
port = 8080,
|
||||||
reporter = new TerminalReporter(new Terminal(process.stdout)),
|
reporter = new TerminalReporter(new Terminal(process.stdout)),
|
||||||
|
@ -231,6 +235,7 @@ exports.runServer = async ({
|
||||||
...rest,
|
...rest,
|
||||||
port,
|
port,
|
||||||
reporter,
|
reporter,
|
||||||
|
minifierPath,
|
||||||
});
|
});
|
||||||
|
|
||||||
serverApp.use(middleware);
|
serverApp.use(middleware);
|
||||||
|
|
|
@ -183,6 +183,7 @@ function toServerOptions(options: Options): ServerOptions {
|
||||||
globalTransformCache: options.globalTransformCache,
|
globalTransformCache: options.globalTransformCache,
|
||||||
hasteImplModulePath: options.hasteImplModulePath,
|
hasteImplModulePath: options.hasteImplModulePath,
|
||||||
maxWorkers: options.maxWorkers,
|
maxWorkers: options.maxWorkers,
|
||||||
|
minifierPath: options.minifierPath,
|
||||||
moduleFormat: options.moduleFormat,
|
moduleFormat: options.moduleFormat,
|
||||||
platforms: options.platforms,
|
platforms: options.platforms,
|
||||||
polyfillModuleNames: options.polyfillModuleNames,
|
polyfillModuleNames: options.polyfillModuleNames,
|
||||||
|
|
|
@ -83,6 +83,7 @@ export type Options = {|
|
||||||
globalTransformCache: ?GlobalTransformCache,
|
globalTransformCache: ?GlobalTransformCache,
|
||||||
hasteImplModulePath?: string,
|
hasteImplModulePath?: string,
|
||||||
maxWorkers?: number,
|
maxWorkers?: number,
|
||||||
|
minifierPath?: string,
|
||||||
moduleFormat?: string,
|
moduleFormat?: string,
|
||||||
platforms?: Array<string>,
|
platforms?: Array<string>,
|
||||||
polyfillModuleNames?: Array<string>,
|
polyfillModuleNames?: Array<string>,
|
||||||
|
|
Loading…
Reference in New Issue