我想在 Visual Studio 2017 中与我的 .NET 应用程序一起开发一个 React 应用程序(在同一个解决方案中).
我正在使用 TypeScript,所以我想要一个可以自定义构建的项目类型(我想对项目进行 webpack 等,所以标准的 Visual Studio TypeScript 构建是不够的).
我已经安装了 node.js 开发工具,但它们只允许我创建 node.js 特定项目(启动时运行 node.js 实例)并且不要让我自定义构建过程.
哪种项目类型最适合这个?
我最近做了这个,建议如下:
create-react-appject
命令.请注意,这是一个单向"操作,因为您无法将文件放回 create-react-app
.您需要安装 node 和 纱线,如果不明显的话.既然你也想使用 TypeScript,你应该使用 react-scripts-ts 脚本如下:
create-react-app my-app --scripts-version=react-scripts-ts
微软在这里有很好的了解..p>
棘手的部分是将生成的 React 项目导入 Visual Studio.我通过从随 Visual Studio 一起安装的Visual Studio 安装程序"安装Node.js 开发"模块来做到这一点.不幸的是,微软似乎已经删除了空白或空的 TypeScript 项目模板(请参阅此处).
安装 Node.js 工具后,您可以在解决方案中创建基于节点的项目.在 File -> New -> Project... -> Templates -> Other Languages -> TypeScript 左侧菜单导航下有几个可供选择.我选择了空白 Node.js Web 应用程序".
之后,您需要将 create-react-app
创建的 React 项目文件复制到您的 Visual Studio 项目中.我发现在 Visual Studio 中创建目录更容易,因此将它们添加到项目文件中,然后将文件复制到生成的文件夹中,最后将它们添加到 Visual Studio 中的项目文件夹中.
此时,您可以运行 create-react-app
添加的 package.json
文件中的脚本.我更喜欢在命令行中运行它们,但您也可以在 Visual Studio 中运行它们,也可以使用 Mads Kristensen 的Task Runner Explorer".
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:
create-react-app eject
command. Be advised that this is a "one-way" operation as you can't put the files back in to create-react-app
. You will need to install node and yarn separately, if that wasn't obvious.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 中的反应项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!