UNPKG

@expo/webpack-config

Version:

The default Webpack configuration used to build Expo apps targeting the web.

66 lines 2.81 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const config_1 = require("@expo/config"); const webpack_1 = require("webpack"); const env_1 = require("../env"); function createClientEnvironment(mode, publicPath, nativeAppManifest) { const environment = mode || 'development'; const __DEV__ = environment !== 'production'; const ENV_VAR_REGEX = /^(EXPO_|REACT_NATIVE_|CI$)/i; const processEnv = Object.keys(process.env) .filter(key => ENV_VAR_REGEX.test(key)) .reduce((env, key) => { env[key] = JSON.stringify(process.env[key]); return env; }, { /** * Useful for determining whether we’re running in production mode. * Most importantly, it switches React into the correct mode. */ NODE_ENV: JSON.stringify(environment), /** * Useful for resolving the correct path to static assets in `public`. * For example, <img src={process.env.PUBLIC_URL + '/img/logo.png'} />. * This should only be used as an escape hatch. Normally you would put * images into the root folder and `import` them in code to get their paths. */ PUBLIC_URL: JSON.stringify(publicPath), /** * Surfaces the `app.json` (config) as an environment variable which is then parsed by * `expo-constants` https://docs.expo.io/versions/latest/sdk/constants/ */ APP_MANIFEST: JSON.stringify(nativeAppManifest), }); return { 'process.env': processEnv, __DEV__, }; } exports.createClientEnvironment = createClientEnvironment; /** * Required for `expo-constants` https://docs.expo.io/versions/latest/sdk/constants/ * This surfaces the `app.json` (config) as an environment variable which is then parsed by `expo-constants`. */ class ExpoDefinePlugin extends webpack_1.DefinePlugin { constructor({ mode, publicUrl, productionManifestPath, config, }) { const publicAppManifest = config_1.createEnvironmentConstants(config, productionManifestPath); const environmentVariables = createClientEnvironment(mode, publicUrl, publicAppManifest); super(environmentVariables); } } exports.default = ExpoDefinePlugin; ExpoDefinePlugin.createClientEnvironment = createClientEnvironment; ExpoDefinePlugin.fromEnv = (env) => { const mode = env_1.getMode(env); const { publicUrl } = env_1.getPublicPaths(env); const config = env.config || env_1.getConfig(env); const locations = env.locations || env_1.getPaths(env.projectRoot); const productionManifestPath = locations.production.manifest; return new ExpoDefinePlugin({ mode, publicUrl, config, productionManifestPath, }); }; //# sourceMappingURL=ExpoDefinePlugin.js.map