[英]Shared react front end components -> Separate project with TypeScript -> Visual Studio 2017
We have the following project structure in Visual Studio. 在Visual Studio中,我们具有以下项目结构。 The reason we have a SharedComponents project is because a lot of components are shared between our client and admin interface.
之所以拥有SharedComponents项目,是因为客户端和管理界面之间共享了许多组件。 We use the feature pattern and would like to have this project structure.
我们使用特征模式,并希望具有此项目结构。
/src(.sln)
--/PublicClient
--/Admin
--/SharedComponents
Our SharedComponents project is not a Visual Studio Shared Project
but a Class Library
because we use TypeLite NuGet to generate TypeScript
interfaces from .NET classes. 我们的SharedComponents项目不是
Visual Studio Shared Project
而是Class Library
因为我们使用TypeLite NuGet从.NET类生成TypeScript
接口。
We are facing a lot of problems due to the fact that the SharedComponents project has its own package.json
, tsconfig.json
and tslint.json
. 由于SharedComponents项目具有自己的
package.json
, tsconfig.json
和tslint.json
, tsconfig.json
我们面临许多问题。
Module agumentation is one of the problems described here: 模块参数化是此处描述的问题之一:
Typescript 2.6 -> Extend type definition for external library with module augmentation -> TS2339: Property '' does not exist on type '' Typescript 2.6->使用模块扩展来扩展外部库的类型定义-> TS2339:类型”上不存在属性”
One feature that we do not wan't to loose is hot reloading with webpack-dev-server
if we change anything in either of the projects, including SharedComponents. 我们不希望失去的一项功能是,如果我们更改了两个项目(包括SharedComponents)中的任何内容,则将使用
webpack-dev-server
热重载。
I have read a lot of threads about this but not found any good solution. 我已经阅读了很多有关此内容的主题,但没有找到任何好的解决方案。
npm link
causes build errors due to dependencies in node_modules
being moved. npm link
由于移动的node_modules
中的依赖性而导致生成错误。
https://github.com/npm/npm/issues/10343 https://github.com/npm/npm/issues/10343
https://github.com/facebookincubator/create-react-app/issues/1492 https://github.com/facebookincubator/create-react-app/issues/1492
We do not want to skip the shared project and copy the files to both our projects. 我们不想跳过共享项目并将文件复制到两个项目中。 It would be to time consuming to maintain the same components in two different projects.
在两个不同项目中维护相同组件将非常耗时。
If we open source our shared project to NPM
or use another service like NPM private modules , linklocal , Bit or sinopia we will loose hot reloading and/or have to maintain the package separately. 如果我们将共享项目开源到
NPM
或使用其他服务(例如NPM专用模块 , linklocal , Bit或sinopia),我们将失去热重载和/或必须单独维护软件包。
Has anyone else been in the same situation and found a good solution? 其他人也遇到过同样的情况并找到了一个好的解决方案吗?
We decided to put all our front end code in one project and then use separate folders there. 我们决定将所有前端代码放在一个项目中,然后在其中使用单独的文件夹。 This means we only have one
package.json
, node_modules
, tsconfig.json
and tslint.json
. 这意味着我们只有一个
package.json
, node_modules
, tsconfig.json
和tslint.json
。 We can't have the API:s in the same project but since we can use hot reloading with webpack-dev-server
it was still a good trade off in the end. 我们不能在同一项目中使用API :,但是由于我们可以在
webpack-dev-server
使用热重载,因此最终还是个不错的选择。
We then used two separate webpack.config.js
files called webpack.publicclient.config.js
and webpack.admin.config.js
for different configurations. 然后,我们将两个单独的
webpack.config.js
文件称为webpack.publicclient.config.js
和webpack.admin.config.js
用于不同的配置。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.