import { config } from '@erect/core/config'; import { BuildEnvHookParams, buildEnvHook, } from '../hooks/buildEnv'; buildEnvHook.addFilter('default', (env, { buildOptions: { development, target } }) => { const isDev = development; const isProd = !isDev; const isClient = target === 'client'; const isServer = target === 'server'; const isNode = !isClient; return { ...env, // It is really important to use NODE_ENV=production in order to use // optimised versions of some node_modules, such as React. NODE_ENV: development ? 'development' : 'production', // Is this the "client" bundle? BUILD_FLAG_IS_CLIENT: JSON.stringify(isClient), // Is this the "server" bundle? BUILD_FLAG_IS_SERVER: JSON.stringify(isServer), // Is this a node bundle? BUILD_FLAG_IS_NODE: JSON.stringify(isNode), // Is this a development build? BUILD_FLAG_IS_DEV: JSON.stringify(development), // If onfline service worker is enabled, if false will remove from bundle OFFLINE_SERVICE_WORKER_ENABLED: JSON.stringify(config.offlineServiceWorker.enabled), // If onfline service worker is enabled, if false will remove from bundle SOURCE_MAP_ENABLED: JSON.stringify(config.includeSourceMapsForOptimisedClientBundle), // Set environment for fix trailling slash FIX_TRAILING_SLASH: JSON.stringify(config.fixTrailingSlash), }; }, { priority: 50 }); export const createBuildEnv = (config: BuildEnvHookParams) => { return buildEnvHook.filter({}, config); };