diff --git a/src/commands/base-command.ts b/src/commands/base-command.ts index 32631b4d0de..592f464b755 100644 --- a/src/commands/base-command.ts +++ b/src/commands/base-command.ts @@ -596,7 +596,11 @@ export default class BaseCommand extends Command { token, ...apiUrlOpts, }) - const { buildDir, config, configPath, env, repositoryRoot, siteInfo } = cachedConfig + const { buildDir, config, configPath, repositoryRoot, siteInfo } = cachedConfig + let { env } = cachedConfig + if (flags.offlineEnv) { + env = {} + } env.NETLIFY_CLI_VERSION = { sources: ['internal'], value: version } const normalizedConfig = normalizeConfig(config) @@ -661,7 +665,10 @@ export default class BaseCommand extends Command { // Configuration from netlify.[toml/yml] config: normalizedConfig, // Used to avoid calling @netlify/config again - cachedConfig, + cachedConfig: { + ...cachedConfig, + env, + }, // global cli config globalConfig, // state of current site dir diff --git a/src/commands/dev/dev.ts b/src/commands/dev/dev.ts index 8dba0743eb3..2d79832f92b 100644 --- a/src/commands/dev/dev.ts +++ b/src/commands/dev/dev.ts @@ -118,7 +118,7 @@ export const dev = async (options: OptionValues, command: BaseCommand) => { env[BLOBS_CONTEXT_VARIABLE] = { sources: ['internal'], value: encodeBlobsContext(blobsContext) } - if (!options.offline) { + if (!options.offline && !options.offlineEnv) { env = await getEnvelopeEnv({ api, context: options.context, env, siteInfo }) log(`${NETLIFYDEVLOG} Injecting environment variable values for ${chalk.yellow('all scopes')}`) } @@ -275,6 +275,9 @@ export const createDevCommand = (program: BaseCommand) => { .option('-d ,--dir ', 'dir with static files') .option('-f ,--functions ', 'specify a functions folder to serve') .option('-o ,--offline', 'disables any features that require network access') + .addOption( + new Option('--offline-env', 'disables fetching environment variables from the Netlify API').hideHelp(true), + ) .addOption( new Option( '--internal-disable-edge-functions',