Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

webpack convention for conditional files for node vs web build

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...