Reputation: 373
I use NestJS application in nx project
i use this approach
if (process.env.NODE_ENV === 'production') {
// Code will only appear in production build.
}
if (process.env.NODE_ENV !== 'production') {
// Code will be removed from production build.
console.log("Looks like you're a developer.");
}
i used also any other approach even use chatgpt
i need alll the code in the none prodection block code to be deleted from the prodection code.
this is very important becuse in the none production code i lazy import hard coded mock in the code, and this data is very sensitive and increase the server size which cost as allots off money.
please help me find a sulotion to spear unwanted code base on procces.env.NODE_ENV mode approach.
any third party package or advance Typescript configuration is an option
the app code
import { HttpService } from '@nestjs/axios';
import { Injectable } from '@nestjs/common';
import { firstValueFrom } from 'rxjs';
@Injectable()
export class SomeRandomService {
constructor(private httpService: HttpService) {}
randomRequest(body: any): Promise<any> {
if (process.env.NODE_ENV === 'production') {
return firstValueFrom(
this.httpService.post(`someRandomUrl`, body, {
headers: {
Accept: 'application/json',
},
})
);
} else {
return import('some-random-path-to-mock.mock');
}
}
}
please let me know if any further information is needed like project.json
or package.json
Upvotes: 0
Views: 31
Reputation: 605
According to the comments in this question, it is not possible with TypeScript. Though I do not have experience with it, using Rollup with this package should do what you want.
Upvotes: 0