buildBundle.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = void 0;
  6. function _Server() {
  7. const data = _interopRequireDefault(require("metro/src/Server"));
  8. _Server = function () {
  9. return data;
  10. };
  11. return data;
  12. }
  13. function _bundle() {
  14. const data = _interopRequireDefault(require("metro/src/shared/output/bundle"));
  15. _bundle = function () {
  16. return data;
  17. };
  18. return data;
  19. }
  20. function _path() {
  21. const data = _interopRequireDefault(require("path"));
  22. _path = function () {
  23. return data;
  24. };
  25. return data;
  26. }
  27. function _chalk() {
  28. const data = _interopRequireDefault(require("chalk"));
  29. _chalk = function () {
  30. return data;
  31. };
  32. return data;
  33. }
  34. var _saveAssets = _interopRequireDefault(require("./saveAssets"));
  35. var _loadMetroConfig = _interopRequireDefault(require("../../tools/loadMetroConfig"));
  36. function _cliTools() {
  37. const data = require("@react-native-community/cli-tools");
  38. _cliTools = function () {
  39. return data;
  40. };
  41. return data;
  42. }
  43. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  44. /**
  45. * Copyright (c) Facebook, Inc. and its affiliates.
  46. *
  47. * This source code is licensed under the MIT license found in the
  48. * LICENSE file in the root directory of this source tree.
  49. *
  50. */
  51. // @ts-ignore - no typed definition for the package
  52. // @ts-ignore - no typed definition for the package
  53. async function buildBundle(args, ctx, output = _bundle().default) {
  54. const config = await (0, _loadMetroConfig.default)(ctx, {
  55. maxWorkers: args.maxWorkers,
  56. resetCache: args.resetCache,
  57. config: args.config
  58. });
  59. if (config.resolver.platforms.indexOf(args.platform) === -1) {
  60. _cliTools().logger.error(`Invalid platform ${args.platform ? `"${_chalk().default.bold(args.platform)}" ` : ''}selected.`);
  61. _cliTools().logger.info(`Available platforms are: ${config.resolver.platforms.map(x => `"${_chalk().default.bold(x)}"`).join(', ')}. If you are trying to bundle for an out-of-tree platform, it may not be installed.`);
  62. throw new Error('Bundling failed');
  63. } // This is used by a bazillion of npm modules we don't control so we don't
  64. // have other choice than defining it as an env variable here.
  65. process.env.NODE_ENV = args.dev ? 'development' : 'production';
  66. let sourceMapUrl = args.sourcemapOutput;
  67. if (sourceMapUrl && !args.sourcemapUseAbsolutePath) {
  68. sourceMapUrl = _path().default.basename(sourceMapUrl);
  69. }
  70. const requestOpts = {
  71. entryFile: args.entryFile,
  72. sourceMapUrl,
  73. dev: args.dev,
  74. minify: args.minify !== undefined ? args.minify : !args.dev,
  75. platform: args.platform
  76. };
  77. const server = new (_Server().default)(config);
  78. try {
  79. const bundle = await output.build(server, requestOpts);
  80. await output.save(bundle, args, _cliTools().logger.info); // Save the assets of the bundle
  81. const outputAssets = await server.getAssets({ ..._Server().default.DEFAULT_BUNDLE_OPTIONS,
  82. ...requestOpts,
  83. bundleType: 'todo'
  84. }); // When we're done saving bundle output and the assets, we're done.
  85. return await (0, _saveAssets.default)(outputAssets, args.platform, args.assetsDest);
  86. } finally {
  87. server.end();
  88. }
  89. }
  90. var _default = buildBundle;
  91. exports.default = _default;
  92. //# sourceMappingURL=buildBundle.js.map