change server build process to respect babel transforms
Summary: The build process for the server was a simple ts-node that compiled all deps. However, that didn't do any source transformations we need, like replacing `fb-stubs` with `fb` in facebook builds. This diff works out the dev build process to align more with how other parts of the code base is build, by starting metro to build and bundle the server (only the sources of flipper-server, flipper-server-core and other flipper packages are bundled, node-deps are left as is). To achieve this, since metro doesn't have support for 'external' packages like any arbitrarily other bundler, we recycle the electronRequire work around that is used in the desktop app as well Reviewed By: aigoncharov Differential Revision: D32949677 fbshipit-source-id: 00d326bb17b68aece6fb43af98d0def13b335e74
This commit is contained in:
committed by
Facebook GitHub Bot
parent
1ffd845fb2
commit
ae56f2b62f
@@ -28,6 +28,8 @@ import {
|
||||
staticDir,
|
||||
defaultPluginsDir,
|
||||
babelTransformationsDir,
|
||||
serverDir,
|
||||
rootDir,
|
||||
} from './paths';
|
||||
|
||||
const {version} = require('../package.json');
|
||||
@@ -343,3 +345,39 @@ export function genMercurialRevision(): Promise<string | null> {
|
||||
)
|
||||
.catch(() => null);
|
||||
}
|
||||
|
||||
export async function compileServerMain() {
|
||||
await fs.promises.mkdir(path.join(serverDir, 'dist'), {recursive: true});
|
||||
const out = path.join(serverDir, 'dist', 'index.js');
|
||||
console.log('⚙️ Compiling server bundle...');
|
||||
const config = Object.assign({}, await Metro.loadConfig(), {
|
||||
reporter: {update: () => {}},
|
||||
projectRoot: rootDir,
|
||||
transformer: {
|
||||
babelTransformerPath: path.join(
|
||||
babelTransformationsDir,
|
||||
'transform-server',
|
||||
),
|
||||
...minifierConfig,
|
||||
},
|
||||
resolver: {
|
||||
sourceExts: ['tsx', 'ts', 'js', 'json'],
|
||||
resolverMainFields: ['flipperBundlerEntry', 'module', 'main'],
|
||||
},
|
||||
});
|
||||
await Metro.runBuild(config, {
|
||||
platform: 'node',
|
||||
entry: path.join(serverDir, 'src', 'index.tsx'),
|
||||
out,
|
||||
dev,
|
||||
minify: !dev,
|
||||
sourceMap: true,
|
||||
sourceMapUrl: dev ? 'index.map' : undefined,
|
||||
inlineSourceMap: false,
|
||||
resetCache: !dev,
|
||||
});
|
||||
console.log('✅ Compiled server bundle.');
|
||||
if (!dev) {
|
||||
stripSourceMapComment(out);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user