The project I'm part of in a TypeScript monorepo with a large webapp and various server-side daemon processes.
We use webpack to build all build artefacts and it works ok.
We have a range of interfaces that both web and daemon use, and are then implemented with different concrete classes.
For example, a DataFeed
interface might be implemented by a WebSocketDataFeed
in the browser, but a SocketDataFeed
in node.
Our current approach is a bit simplistic, with files like this and using logic like if (isNode)...
to choose which implementation to use - but webpack goes through all files:
DataFeed.ts
WebSocketDataFeed.ts
SocketDataFeed.ts
That's "ok" but I'd really like it if naming would solve the "which should webpack compile" problem, and makes it clearer for us humans too, e.g.:
DataFeed.ts
DataFeed.web.ts
DataFeed.node.ts
Is there an established convention for something like this?
question from:
https://stackoverflow.com/questions/65856781/webpack-convention-for-conditional-files-for-node-vs-web-build 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…