-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwebpack.config.js
More file actions
38 lines (32 loc) · 1.55 KB
/
webpack.config.js
File metadata and controls
38 lines (32 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
const createExpoWebpackConfigAsync = require("@expo/webpack-config");
const { DefinePlugin } = require("webpack");
const get = require("lodash/get");
// Expo CLI will await this method so you can optionally return a promise.
module.exports = async function configureWebpack(
/** @type {import("@expo/webpack-config/webpack/types").InputEnvironment} */ env,
/** @type {import("@expo/webpack-config/webpack/types").Arguments} */ argv,
) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
const config = await createExpoWebpackConfigAsync(env, argv);
// Add in missing process.env.EXPO_PUBLIC_<...> variables to the DefinePlugin
const expoPublicEnvVars = Object.fromEntries(
Object.entries(process.env)
.filter(([key]) => key.startsWith("EXPO_PUBLIC_"))
.map(([key, value]) => [key, JSON.stringify(value)]),
);
const configDefinePlugin = config.plugins.find(
(plugin) => plugin instanceof DefinePlugin
);
// If DefinePlugin is not found, throw an error or handle it appropriately
if (!configDefinePlugin) {
throw new Error("DefinePlugin not found in webpack config plugins array");
}
const configDefinePluginEnv = /** @type {{}} */ (
// NOTE: the last key is actually the string "process.env", so to access without lodash
// (less type-safe) you would need to do configDefinePlugin.definitions["process.env"]
get(configDefinePlugin.definitions, ["process.env"])
);
Object.assign(configDefinePluginEnv, expoPublicEnvVars);
// Finally return the new config for the CLI to use.
return config;
};