A
A
angelzzz2018-08-26 12:08:59
Node.js
angelzzz, 2018-08-26 12:08:59

How to run auto update in MERN + webpack stack?

I'm doing a MERN project.
Collected from the tutorial
File webpack.config.js
const path = require('path');
const entryFile = path.resolve(__dirname, 'src', 'client', 'app.js');
const outputDir = path.resolve(__dirname, 'public');

module.exports = {
  entry: ['babel-polyfill', entryFile],
  output: {
    filename: 'bundle.js',
    path: outputDir
  },
  module: {
    rules: [
      {
        test: /\.(js|jsx)$/,
        loader: 'babel-loader',
        exclude: /node_modules/
      },
      {
        test: /\.(scss|css)$/,
        use: [
          {
            loader: 'style-loader'
          }, 
          { 
            loader: 'css-loader',
          }, 
          { 
            loader: 'sass-loader'
          }
        ]
      }
    ]
  }
};

package.json:
{
  ...
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "babel-node src/server/app.js",
    "prestart": "webpack --mode development"
  },
  "repository": {
    "type": "git",
    "url": "git+https://github.com/2u4u/share-book.git"
  },
  ...
  "dependencies": {
    "express": "^4.16.3",
    "webpack": "^4.17.1",
    "webpack-dev-server": "^3.1.5"
  },
  "devDependencies": {
    "babel-cli": "^6.26.0",
    "babel-core": "^6.26.3",
    "babel-loader": "^7.1.5",
    "babel-polyfill": "^6.26.0",
    "babel-preset-env": "^1.7.0",
    "babel-preset-react": "^6.24.1",
    "babel-preset-stage-0": "^6.24.1",
    "css-loader": "^1.0.0",
    "node-sass": "^4.9.3",
    "react": "^16.4.2",
    "react-dom": "^16.4.2",
    "sass-loader": "^7.1.0",
    "style-loader": "^0.22.1",
    "webpack-cli": "^3.1.0",
    "webpack-command": "^0.4.1"
  }
}

server/app.js:
import express from 'express';
import path from 'path';
const app = express();
const publicPath = path.resolve(__dirname, '..', '..', 'public');
app.use(express.static(publicPath));
app.listen(3000, () => {   
    console.log(`NEW one MERN Boilerplate listening on port 3000 and looking in folder ${publicPath}`);
});

Reboot does not work when updating files. What could be the problem?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Spirin, 2018-08-26
@rockon404

Read:
webpack dev server
webpack hot module replacement React hot module replacement
library: react-hot-loader
There are a bunch of examples in the examples folder.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question