我想与我的.NET应用程序(在同一解决方案中)一起在Visual Studio 2017中开发一个React应用程序.
我正在使用TypeScript,所以我想要一个可以自定义构建的项目类型(我想对项目进行webpack等,因此标准的Visual Studio TypeScript构建是不够的.)
我已经安装了 node.js开发人员工具,但它们只允许我创建特定于node.js的项目(启动时会运行一个node.js实例),不要让我自定义构建过程.
哪种项目类型最适合?
解决方案我最近做了此操作,并建议以下操作:
由于您还想使用TypeScript,因此应使用 react-scripts- ts 脚本如下:
create-react-app my-app --scripts-version=react-scripts-ts
Microsoft在此处进行了很好的介绍.. p>
棘手的部分是将生成的React项目放入Visual Studio.我是通过从随Visual Studio一起安装的"Visual Studio安装程序"中安装"Node.js开发"模块来完成此操作的.不幸的是,Microsoft似乎已经删除了空白或空的TypeScript项目模板(请参见此处).
一旦安装了Node.js工具,您就可以在解决方案中创建一个基于节点的项目.在文件->新建->项目...->模板->其他语言-> TypeScript左侧菜单导航下,有几种选择.我选择了空白Node.js Web应用程序".
之后,您需要将create-react-app创建的React项目文件复制到Visual Studio项目中.我发现在Visual Studio中创建目录比较容易,因此可以将它们添加到项目文件中,然后将文件复制到生成的文件夹中,最后将它们添加到Visual Studio中的项目文件夹中.
这时,您可以运行create-react-app添加的package.json文件中的脚本.我更喜欢在命令行上运行它们,但是您也可以使用Mads Kristensen的任务运行器资源管理器"在Visual Studio中运行它们.
I want to develop a React application in Visual Studio 2017 alongside my .NET application (in the same solution).
I am using TypeScript, so I want a project type where I can customise the build (I want to webpack the project, etc, so the standard Visual Studio TypeScript build is not enough).
I have installed the node.js developer tools but they only allow me to create node.js specific projects (which run a node.js instance when started) and do not let me customise the build process.
Which project type will be best for this?
解决方案I recently did this and would recommend the following:
Since you also want to use TypeScript you should use the react-scripts-ts script like so:
create-react-app my-app --scripts-version=react-scripts-ts
Microsoft has a good walk through here.
The tricky part is getting the generated React project into Visual Studio. I did this by installing the "Node.js development" module from the "Visual Studio Installer" that gets installed with Visual Studio. Unfortunately, Microsoft seems to have removed the blank or empty TypeScript project template (see here).
Once the Node.js tools are installed you can create a node based project in your solution. There are several to choose from under the File -> New -> Project... -> Templates -> Other Languages -> TypeScript left menu navigation. I chose "Blank Node.js Web Application".
After that you will need to copy over the React project files created by create-react-app into your Visual Studio project. I find it easier to create the directories in Visual Studio so they are added to the project file, then copy the files the generated folders, and finally add them to the project folder in Visual Studio.
At this point you can run the scripts in the package.json file that were added by create-react-app. I prefer to run these at the command line, but you can run them in Visual Studio as well using the "Task Runner Explorer" by Mads Kristensen.
更多推荐
Visual Studio 2017中的React项目
发布评论