With Webpack:
const WebpackConfig = {
// ...
plugins: [
new Webpack.DefinePlugin({
__IS_DEVELOPMENT_BUILDING_MODE__: isDevelopmentBuildingMode,
__IS_TESTING_BUILDING_MODE__: isTestingBuildingMode,
__IS_PRODUCTION_BUILDING_MODE__: !isDevelopmentBuildingMode && !isTestingBuildingMode
})
]
}
Now I'm going to use TS-Node instead of Webpack. TS-Node does not see these constants:
ErrorsReportingService.ts:35:9 - error TS2304: Cannot find name '__IS_DEVELOPMENT_BUILDING_MODE__'.
How to initialize these globals for TS-Node?
Off course, typings for these constants are being provided:
declare const __IS_DEVELOPMENT_BUILDING_MODE__: boolean;
declare const __IS_TESTING_BUILDING_MODE__: boolean;
declare const __IS_PRODUCTION_BUILDING_MODE__: boolean;
Please note that I need both Webpack and TSNode.
Solution on conceptual level
- Create file and initialize global variables (like
globalThis.__IS_DEVELOPMENT_BUILDING_MODE__ = false?) - Tell TSNode to execute this file first.
Now the question is TSNode allows such things or not.
Update
My TypeScript lost the declared globals after I placed them inside declare global {}:
typings.d.ts
declare global {
let __IS_DEVELOPMENT_BUILDING_MODE__: boolean;
let __IS_TESTING_BUILDING_MODE__: boolean;
let __IS_PRODUCTION_BUILDING_MODE__: boolean;
}
Now compiler does not see them:
TS2304: Cannot find name '__IS_DEVELOPMENT_BUILDING_MODE__'.
