build headless version
Summary: * Adds `build-headless.js` to bundle the app using metro * the build script replaces the prelude code added by metro with our own to make it work in node. Metro will add an API to add custom prelude code in the next version. * Pins down metro's dependency of `temp` to `v0.9.0` (instead of `0.8.3`) to be compatible with node 10. (This will be fixed in a metro upgrade) Reviewed By: passy Differential Revision: D13786574 fbshipit-source-id: bddb3542c370c068d90a90c4b59337f995e4fa3f
This commit is contained in:
committed by
Facebook Github Bot
parent
dab50ec5c4
commit
7ac6a09af1
48
scripts/build-headless.js
Normal file
48
scripts/build-headless.js
Normal file
@@ -0,0 +1,48 @@
|
||||
/**
|
||||
* Copyright 2018-present Facebook.
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
* @format
|
||||
*/
|
||||
|
||||
const path = require('path');
|
||||
const lineReplace = require('line-replace');
|
||||
const fs = require('fs-extra');
|
||||
const {
|
||||
buildFolder,
|
||||
compile,
|
||||
compileDefaultPlugins,
|
||||
} = require('./build-utils.js');
|
||||
|
||||
function preludeBundle(dir) {
|
||||
return new Promise((resolve, reject) =>
|
||||
lineReplace({
|
||||
file: path.join(dir, 'bundle.js'),
|
||||
line: 1,
|
||||
text:
|
||||
'var __DEV__=false; global.electronRequire = require; global.performance = require("perf_hooks").performance;',
|
||||
addNewLine: true,
|
||||
callback: resolve,
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
function copyFolder(dir) {
|
||||
const buildDir = path.join(__dirname, '..', 'dist');
|
||||
fs.removeSync(buildDir);
|
||||
fs.copySync(dir, buildDir);
|
||||
}
|
||||
|
||||
(async () => {
|
||||
process.env.BUILD_HEADLESS = 'true';
|
||||
const dir = await buildFolder();
|
||||
// eslint-disable-next-line no-console
|
||||
console.log('Created build directory', dir);
|
||||
await compile(dir, path.join(__dirname, '..', 'headless', 'index.js'));
|
||||
await preludeBundle(dir);
|
||||
await compileDefaultPlugins(dir);
|
||||
copyFolder(dir);
|
||||
// eslint-disable-next-line no-console
|
||||
console.log('✨ Done');
|
||||
process.exit();
|
||||
})();
|
||||
Reference in New Issue
Block a user