@expo/webpack-config
Version:
The default Webpack configuration used to build Expo apps targeting the web.
56 lines • 2.6 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const config_1 = require("@expo/config");
const paths_1 = require("@expo/config/paths");
const env_1 = require("../env");
const utils_1 = require("../utils");
/**
* Inject a new entry path into an existing Webpack config.
*
* @param webpackConfig Existing Webpack config to modify.
* @param env Environment props used to get the Expo config.
* @param options new entry path to inject.
* @category addons
*/
function withEntry(webpackConfig, env = {}, options) {
env.projectRoot = env.projectRoot || paths_1.getPossibleProjectRoot();
const extraAppEntry = config_1.projectHasModule(options.entryPath, env.projectRoot,
// @ts-ignore
env.config || env_1.getConfig(env));
if (!extraAppEntry) {
if (options.strict) {
throw new Error(`[WEBPACK]: The required app entry module: "${options.entryPath}" couldn't be found.`);
}
// Couldn't resolve the app entry so return the config without modifying it.
return webpackConfig;
}
const expoEntry = webpackConfig.entry;
webpackConfig.entry = () => __awaiter(this, void 0, void 0, function* () {
const entries = yield utils_1.resolveEntryAsync(expoEntry);
if (entries.app) {
if (!entries.app.includes(extraAppEntry)) {
if (!Array.isArray(entries.app)) {
entries.app = [entries.app];
}
entries.app.unshift(extraAppEntry);
}
}
else if (options.strict) {
// Better to be safe...
throw new Error(`[WEBPACK]: Failed to include required app entry module: "${options.entryPath}" because the webpack entry object doesn't contain an \`app\` field.`);
}
return entries;
});
return webpackConfig;
}
exports.default = withEntry;
//# sourceMappingURL=withEntry.js.map