[英]Minimum server.js required to run react/redux application?
I've built my project with webpack using babel for ES6 transpilation with following presets: 我已经使用babel进行webpack构建了项目,并使用babel对ES6进行了以下预置:
{
"presets": ["react", "es2015", "stage-1"]
}
And webpack production config looking in the following way: 和webpack生产配置以下列方式查看:
var path = require('path');
var node_modules_dir = path.resolve(__dirname, 'node_modules');
module.exports = {
entry: [ path.resolve(__dirname, 'src/index.js') ],
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'bundle.js'
},
module: {
loaders: [{
test: /\.(js|jsx)$/,
exclude: [node_modules_dir],
loader: 'babel'
},
{
test: /\.(png|jpg)$/,
exclude: [node_modules_dir],
loader: 'url?limit=100000'
},
{
test: /\.svg$/,
exclude: [node_modules_dir],
loader: 'svg-url-loader'
},
{
test: /\.scss$/,
exclude: [node_modules_dir],
loader: 'style!css!sass'
}]
},
resolve: { extensions: ['', '.js', '.jsx'] }
};
And I would like to now deploy it to the server. 我现在想将其部署到服务器上。 Production ready files are located in the
dist
folder, so: 生产就绪文件位于
dist
文件夹中,因此:
dist/
index.html
bundle.js
I'm mentioning this, as I need my entry point to be dist/index.html
. 我要提到这一点,因为我的入口必须是
dist/index.html
。
As I have never deployed previously I'm not sure how my server.js file should look, after some research it seems that I need to use http server or express server, with some babel transpiration as well for es6 syntax. 由于我以前从未部署过,所以我不确定server.js文件的外观,经过研究后,看来我需要使用http服务器或express服务器,并且还要对es6语法进行一些翻译。
What would be a minimum setup that can be used? 可以使用的最低设置是多少?
React/redux is client-side, ie the browser executes your code, the server only needs to get it there. React / redux是客户端的,即浏览器执行您的代码,服务器只需要将其获取即可。
Your server does not need to do anything clever, like transpiling, as your build process has already done that and created a 'bundle' ready to be executed in a browser. 您的服务器不需要做任何聪明的事情,例如编译,因为您的构建过程已经做到了这一点,并创建了一个“束”,准备在浏览器中执行。 As such, a quick static server, such as one using Nginx, Apache or Varnish, needs only to serve the contents of your
dist
folder. 这样,一个快速的静态服务器(例如使用Nginx,Apache或Varnish的服务器)仅需要提供
dist
文件夹的内容。
Node, Python, whatever, can be used, but you dont need them, you only need to serve files. 可以使用Node,Python等任何工具,但是您不需要它们,只需要提供文件即可。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.