1

How should one do to remove server folder from react-boilerplate? Question is also asked here by another person https://github.com/react-boilerplate/react-boilerplate/issues/2110.

user1665355
  • 3,324
  • 8
  • 44
  • 84

2 Answers2

1

Removing just server folder will not work because the webpack dev configuration is utilising it for hot reload as well as your npm start command starts express server from this folder.

If you want to remove server folder completely and still want the application to be working as it was like hot reloading etc, follow the below steps. We will require webpack dev server in that case:

  • Remove ./server folder manually.
  • Install webpack-dev-server and react-hot-loader as dev dependencies.
  • In your ./internals/webpack/webpack.dev.babel.js, do the following modifications:

    • Change entry to this:

      entry: [
            require.resolve('react-app-polyfill/ie11'),
            'react-hot-loader/patch',
            `webpack-dev-server/client?http://localhost:3000/`,
            'webpack/hot/only-dev-server',
            path.join(process.cwd(), 'app/app.js'), // Start with js/app.js
      ],
      
    • Add publicPath in output:

      output: {
          filename: '[name].js',
          chunkFilename: '[name].chunk.js',
          publicPath: `http://localhost:3000/`,
      },
      
    • Add webpack dev server config property in the same file:

      devServer: {
         port: 3000,
         publicPath: `http://localhost:3000/`,
         compress: true,
         noInfo: false,
         stats: 'errors-only',
         inline: true,
         lazy: false,
         hot: true,
         open: true,
         overlay: true,
         headers: { 'Access-Control-Allow-Origin': '*' },
         contentBase: path.join(__dirname, '..', '..', 'app', 'build'),
         watchOptions: {
             aggregateTimeout: 300,
             ignored: /node_modules/,
             poll: 100,
         },
         historyApiFallback: {
             verbose: true,
             disableDotRule: false,
         },
      },
      
    • In ./internals/webpack/webpack.base.babel.js, add the line:

      devServer: options.devServer,
      

And finally, modify your start script in package.json as below:

"start": "cross-env NODE_ENV=development node --trace-warnings ./node_modules/webpack-dev-server/bin/webpack-dev-server --color --config internals/webpack/webpack.dev.babel.js",

And you are good to go!!

Manish Jangir
  • 5,329
  • 4
  • 42
  • 75
0

Just remove with rm -rf ./server if you feel harassed :)

Mosè Raguzzini
  • 15,399
  • 1
  • 31
  • 43