Good day, My task is to create two different bundle one for CMS and another one for Product team and there are few function's which i want to be in bundle of CMS but not in the Product team.
I have a Class XYZ
Class XYZ {
constructor() {}
forCms() {}
forProduct() {}
}
and I want two different bundle:
For CMS(i need forCms function):
Class XYZ {
constructor() {}
forCms() {} //<--- notice methods
}
For Product(I need forProduct function):
Class XYZ {
constructor() {}
forProduct() {} //<--- notice methods
}
I searched a lot and I found Env. variable and i use them for some logic like:
function abc() {
const env = process.env.NODE_ENV;
switch (env) {
case "cms":
//some logic
break;
default:
//some logic
});
}
}
I have no idea, how can I achieve this? or Is there any different way beside's ENV. to accomplish this inside bundler like Webpack or Rollup?
Any suggestion would be helpful!
If you're looking to how to attach methods to prototype according to env variable, you could do something like:
export interface LayerManager {
forCms: Function;
forProduct: Function;
}
export class LayerManager {
firstName: string = '';
constructor(name: string) {}
}
// @ts-ignore
if (process.env.NODE_ENV === "cms") {
LayerManager.prototype.forCms = function() {}
} else {
LayerManager.prototype.forProduct = function() {}
}