2
我想用C#Web Api后端在TypeScript中开发我的React应用程序时使用热重新加载。我使用.Net框架,而不是核心,所以我需要使用IIS或IIS Express。我可以使用webpack dev server
没有问题的前端热重新加载,但是我无法访问API资源。我可以做到这一点吗?反应与Typescript热重新加载IIS网络服务器
我想用C#Web Api后端在TypeScript中开发我的React应用程序时使用热重新加载。我使用.Net框架,而不是核心,所以我需要使用IIS或IIS Express。我可以使用webpack dev server
没有问题的前端热重新加载,但是我无法访问API资源。我可以做到这一点吗?反应与Typescript热重新加载IIS网络服务器
找到一个解决方案,使用webpack dev server
作为reverse proxy到IIS。
NPM:
npm install --save [email protected]
npm install webpack-dev-server --save-dev
webpack.config.js,代理在IIS运行:
var webpack = require('webpack');
var path = require("path");
var proxy = 'localhost:61299';
module.exports = {
entry: [
// activate HMR for React
'react-hot-loader/patch',
// the entry point of our app
'./Scripts/src/index.tsx',
],
//entry: "./Scripts/src/index.tsx",
output: {
filename: "./Scripts/dist/bundle.js",
},
// Enable sourcemaps for debugging webpack's output.
devtool: "source-map",
resolve: {
// Add '.ts' and '.tsx' as resolvable extensions.
extensions: [".webpack.js", ".web.js", ".ts", ".tsx", ".js"]
},
module: {
loaders: [
// All files with a '.ts' or '.tsx' extension will be handled by 'ts-loader'.
//{ test: /\.tsx?$/, loader: "ts-loader" }
{ test: /\.tsx?$/, loader: ['react-hot-loader/webpack', 'ts-loader'] }
]
},
plugins: [
new webpack.HotModuleReplacementPlugin(),
// enable HMR globally
new webpack.NamedModulesPlugin(),
// prints more readable module names in the browser console on HMR updates
],
devServer: {
proxy: {
'*': {
target: 'http://' + proxy,
}
},
port: 8080,
host: '0.0.0.0',
hot: true,
},
}
然后我就可以使用此命令从项目根文件夹中启动Web服务器:node_modules\.bin\webpack-dev-server
。如果我然后访问我有热重新加载,我仍然可以使用C#web API,因为它将代理IIS Express在“http://localhost:61299/”