简体   繁体   中英

Minimum server.js required to run react/redux application?

I've built my project with webpack using babel for ES6 transpilation with following presets:

{
  "presets": ["react", "es2015", "stage-1"]
}

And webpack production config looking in the following way:

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/
  index.html
  bundle.js

I'm mentioning this, as I need my entry point to be 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.

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.

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.

Node, Python, whatever, can be used, but you dont need them, you only need to serve files.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM