"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
@@ -30,7 +30,16 @@ export default class Bundle extends Command {
|
||||
];
|
||||
|
||||
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() {
|
||||
@@ -50,11 +59,16 @@ export default class Bundle extends Command {
|
||||
const out = path.resolve(inputDirectory, plugin.main);
|
||||
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) {
|
||||
process.exit(success ? 0 : 1);
|
||||
} else {
|
||||
enterWatchMode(inputDirectory, plugin.source, out);
|
||||
enterWatchMode(inputDirectory, plugin.source, out, !flags.production);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -63,9 +77,10 @@ async function runBuildOnce(
|
||||
inputDirectory: string,
|
||||
source: string,
|
||||
out: string,
|
||||
dev: boolean,
|
||||
) {
|
||||
try {
|
||||
await runBuild(inputDirectory, source, out);
|
||||
await runBuild(inputDirectory, source, out, dev);
|
||||
console.log('✅ Build succeeded');
|
||||
return true;
|
||||
} 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...`);
|
||||
let isBuilding = false;
|
||||
let pendingChanges = false;
|
||||
@@ -92,7 +112,7 @@ function enterWatchMode(inputDirectory: string, source: string, out: string) {
|
||||
isBuilding = true;
|
||||
while (pendingChanges) {
|
||||
pendingChanges = false;
|
||||
await runBuildOnce(inputDirectory, source, out);
|
||||
await runBuildOnce(inputDirectory, source, out, dev);
|
||||
}
|
||||
isBuilding = false;
|
||||
console.log(`⏳ Waiting for changes...`);
|
||||
|
||||
@@ -36,6 +36,11 @@ export default class Pack extends Command {
|
||||
description:
|
||||
'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[] = [
|
||||
@@ -117,7 +122,7 @@ export default class Pack extends Command {
|
||||
|
||||
cli.action.start(`Compiling`);
|
||||
await ensureDir(path.dirname(out));
|
||||
await runBuild(inputDirectory, plugin.source, out);
|
||||
await runBuild(inputDirectory, plugin.source, out, parsedFlags.production);
|
||||
cli.action.stop();
|
||||
|
||||
cli.action.start(`Packing to ${outputFile}`);
|
||||
|
||||
Reference in New Issue
Block a user