"flipper-pkg" option for creating production bundle
Summary: Development bundle: NODE_ENV=development, disabled minification, enabled source maps. Production bundle: NODE_ENV=production, enabled minification, disabled source maps. Changelog: Added "--production" option for "flipper-pkg bundle" command to produce minified plugin packages without source maps. Reviewed By: mweststrate Differential Revision: D22158791 fbshipit-source-id: 0f9ac84ca39ac3fb86f0c0b0a3c1be866445a305
This commit is contained in:
committed by
Facebook GitHub Bot
parent
163f3982f7
commit
21ab8dc25c
@@ -59,8 +59,8 @@ export default async function runBuild(
|
|||||||
inputDirectory: string,
|
inputDirectory: string,
|
||||||
entry: string,
|
entry: string,
|
||||||
out: string,
|
out: string,
|
||||||
|
dev: boolean,
|
||||||
) {
|
) {
|
||||||
const dev = process.env.NODE_ENV !== 'production';
|
|
||||||
const baseConfig = await Metro.loadConfig();
|
const baseConfig = await Metro.loadConfig();
|
||||||
const config = Object.assign({}, baseConfig, {
|
const config = Object.assign({}, baseConfig, {
|
||||||
reporter: {update: () => {}},
|
reporter: {update: () => {}},
|
||||||
@@ -96,7 +96,7 @@ export default async function runBuild(
|
|||||||
dev,
|
dev,
|
||||||
minify: !dev,
|
minify: !dev,
|
||||||
resetCache: !dev,
|
resetCache: !dev,
|
||||||
sourceMap: true,
|
sourceMap: dev,
|
||||||
entry,
|
entry,
|
||||||
out,
|
out,
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -30,7 +30,16 @@ export default class Bundle extends Command {
|
|||||||
];
|
];
|
||||||
|
|
||||||
public static flags = {
|
public static flags = {
|
||||||
watch: flags.boolean(),
|
watch: flags.boolean({
|
||||||
|
description:
|
||||||
|
'Watch for plugin source code and bundle it after every change.',
|
||||||
|
default: false,
|
||||||
|
}),
|
||||||
|
production: flags.boolean({
|
||||||
|
description:
|
||||||
|
'Force env.NODE_ENV=production, enable minification and disable producing source maps.',
|
||||||
|
default: false,
|
||||||
|
}),
|
||||||
};
|
};
|
||||||
|
|
||||||
public async run() {
|
public async run() {
|
||||||
@@ -50,11 +59,16 @@ export default class Bundle extends Command {
|
|||||||
const out = path.resolve(inputDirectory, plugin.main);
|
const out = path.resolve(inputDirectory, plugin.main);
|
||||||
await fs.ensureDir(path.dirname(out));
|
await fs.ensureDir(path.dirname(out));
|
||||||
|
|
||||||
const success = await runBuildOnce(inputDirectory, plugin.source, out);
|
const success = await runBuildOnce(
|
||||||
|
inputDirectory,
|
||||||
|
plugin.source,
|
||||||
|
out,
|
||||||
|
!flags.production,
|
||||||
|
);
|
||||||
if (!flags.watch) {
|
if (!flags.watch) {
|
||||||
process.exit(success ? 0 : 1);
|
process.exit(success ? 0 : 1);
|
||||||
} else {
|
} else {
|
||||||
enterWatchMode(inputDirectory, plugin.source, out);
|
enterWatchMode(inputDirectory, plugin.source, out, !flags.production);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -63,9 +77,10 @@ async function runBuildOnce(
|
|||||||
inputDirectory: string,
|
inputDirectory: string,
|
||||||
source: string,
|
source: string,
|
||||||
out: string,
|
out: string,
|
||||||
|
dev: boolean,
|
||||||
) {
|
) {
|
||||||
try {
|
try {
|
||||||
await runBuild(inputDirectory, source, out);
|
await runBuild(inputDirectory, source, out, dev);
|
||||||
console.log('✅ Build succeeded');
|
console.log('✅ Build succeeded');
|
||||||
return true;
|
return true;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@@ -75,7 +90,12 @@ async function runBuildOnce(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function enterWatchMode(inputDirectory: string, source: string, out: string) {
|
function enterWatchMode(
|
||||||
|
inputDirectory: string,
|
||||||
|
source: string,
|
||||||
|
out: string,
|
||||||
|
dev: boolean,
|
||||||
|
) {
|
||||||
console.log(`⏳ Waiting for changes...`);
|
console.log(`⏳ Waiting for changes...`);
|
||||||
let isBuilding = false;
|
let isBuilding = false;
|
||||||
let pendingChanges = false;
|
let pendingChanges = false;
|
||||||
@@ -92,7 +112,7 @@ function enterWatchMode(inputDirectory: string, source: string, out: string) {
|
|||||||
isBuilding = true;
|
isBuilding = true;
|
||||||
while (pendingChanges) {
|
while (pendingChanges) {
|
||||||
pendingChanges = false;
|
pendingChanges = false;
|
||||||
await runBuildOnce(inputDirectory, source, out);
|
await runBuildOnce(inputDirectory, source, out, dev);
|
||||||
}
|
}
|
||||||
isBuilding = false;
|
isBuilding = false;
|
||||||
console.log(`⏳ Waiting for changes...`);
|
console.log(`⏳ Waiting for changes...`);
|
||||||
|
|||||||
@@ -36,6 +36,11 @@ export default class Pack extends Command {
|
|||||||
description:
|
description:
|
||||||
'Where to output the package, file or directory. Defaults to the current working directory.',
|
'Where to output the package, file or directory. Defaults to the current working directory.',
|
||||||
}),
|
}),
|
||||||
|
production: flags.boolean({
|
||||||
|
description:
|
||||||
|
'Force env.NODE_ENV=production, enable minification and disable producing source maps.',
|
||||||
|
default: false,
|
||||||
|
}),
|
||||||
};
|
};
|
||||||
|
|
||||||
public static args: args.IArg[] = [
|
public static args: args.IArg[] = [
|
||||||
@@ -117,7 +122,7 @@ export default class Pack extends Command {
|
|||||||
|
|
||||||
cli.action.start(`Compiling`);
|
cli.action.start(`Compiling`);
|
||||||
await ensureDir(path.dirname(out));
|
await ensureDir(path.dirname(out));
|
||||||
await runBuild(inputDirectory, plugin.source, out);
|
await runBuild(inputDirectory, plugin.source, out, parsedFlags.production);
|
||||||
cli.action.stop();
|
cli.action.stop();
|
||||||
|
|
||||||
cli.action.start(`Packing to ${outputFile}`);
|
cli.action.start(`Packing to ${outputFile}`);
|
||||||
|
|||||||
@@ -135,7 +135,7 @@ async function compilePlugin(
|
|||||||
// eslint-disable-line no-console
|
// eslint-disable-line no-console
|
||||||
console.log(`⚙️ Compiling ${name}...`);
|
console.log(`⚙️ Compiling ${name}...`);
|
||||||
try {
|
try {
|
||||||
await runBuild(dir, source, entry);
|
await runBuild(dir, source, entry, false);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (failSilently) {
|
if (failSilently) {
|
||||||
console.error(
|
console.error(
|
||||||
|
|||||||
Reference in New Issue
Block a user