Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export default function withEntry(
webpackConfig: AnyConfiguration,
env: InputEnvironment = {},
options: { entryPath: string; strict?: boolean }
): AnyConfiguration {
env.projectRoot = env.projectRoot || getPossibleProjectRoot();
const extraAppEntry = projectHasModule(
options.entryPath,
env.projectRoot,
// @ts-ignore
env.config || 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;
}: {
useCustom?: boolean;
mode?: Mode;
babelProjectRoot?: string;
include?: string[];
verbose?: boolean;
[key: string]: any;
} = {}): Rule {
const ensuredProjectRoot = ensureRoot(babelProjectRoot);
const modules = [...includeModulesThatContainPaths, ...include];
const customUse = options.use || {};
const customUseOptions = customUse.options || {};
const isProduction = mode === 'production';
const projectRoot = getPossibleProjectRoot();
let presetOptions: any = {
// Explicitly use babel.config.js instead of .babelrc
babelrc: false,
// Attempt to use local babel.config.js file for compiling project.
configFile: true,
};
if (
!fs.existsSync(path.join(projectRoot, 'babel.config.js')) &&
!fs.existsSync(path.join(projectRoot, '.babelrc'))
) {
presetOptions = {
babelrc: false,
configFile: false,
presets: [require.resolve('babel-preset-expo')],
};
}
function ensureRoot(possibleProjectRoot?: string): string {
if (typeof possibleProjectRoot === 'string') {
return path.resolve(possibleProjectRoot);
}
return getPossibleProjectRoot();
}