Issue
Can I use IsDebugMode
to switch out import libraries?
Can I do:
if (IsDebugMode) {
import { SQLiteMock, SQLiteObject } from '../mocks/SQLiteMock';
}
else {
import { SQLite, SQLiteDatabaseConfig, SQLiteObject } from '@ionic-native/sqlite';
}
Solution
No, unfortunately you can't conditionally import libraries. What you can do though is import both libraries, inject both in your constructor and then conditionally using isDevMode()
, (there exists no isDebugMode()) you can use whatever you prefer for each case.
This is not a very good solution though, as it means you will load both libs in memory and since you inject them in the constructor the treeshaking that happens at build time will not ommit them.
If this is done sparingly it might even not make a difference though (negatively). I suggest you benchmark Memory size at runtime using dev tools and if there is significant gain to outweigh the manual nature of the cleaner approach, then just replace the Mock class in the import when you are done developing the feature using that Mock.
Answered By - maninak
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.