0

I am creating a simple react app using webpack as the bundler and nodejs for creating a server. The thing is my webpack is not generating the output files in the destination folder. I am not seeing any error and http://localhost:3000 shows my expected content, but the dist folder is not generated.

Is this something related to hot-module-reloding, and webpack is generating everything from memory for me. I am not sure. I am new to react and any help will be highly appreciated.

Thanks

webpack.config.js

var path = require('path');
var webpack = require('webpack');

module.exports = {
  devtool: 'eval',
  entry: [
    'webpack-dev-server/client?http://localhost:3000',
    'webpack/hot/only-dev-server',
    './src/index'
  ],
  output: {
    path: path.join(__dirname, 'dist'),
    filename: 'bundle.js',
    publicPath: '/static/'
  },
  plugins: [
    new webpack.HotModuleReplacementPlugin()
  ],
  module: {
    loaders: [{
      test: /\.js$/,
      loaders: ['react-hot', 'babel'],
      include: path.join(__dirname, 'src')
    }]
  }
};

package.json

 "scripts": {
    "start": "node server.js",
    "lint": "eslint src"
  },
//remaining dependencies

server.js

var webpack = require('webpack');
var WebpackDevServer = require('webpack-dev-server');
var config = require('./webpack.config');

new WebpackDevServer(webpack(config), {
  publicPath: config.output.publicPath,
  hot: true,
  historyApiFallback: true
}).listen(3000, 'localhost', function (err, result) {
  if (err) {
    return console.log(err);
  }

  console.log('Listening at http://localhost:3000/');
});
4
  • 1
    are you running webpack-dev-server or webpack? Commented May 20, 2016 at 18:50
  • Ohh, got it. I was running webpack-dev-server. Thanks. webpack did the job for me. Commented May 20, 2016 at 18:54
  • Can you please tell me the difference between running webpack-dev-server and webpack. Commented May 20, 2016 at 18:57
  • 3
    webpack-dev-server doesnt write the files to disk .. it serves the file over a port similar to what express does for static files. running webpack actually writes and saves the file to your output path. Commented May 20, 2016 at 18:59

1 Answer 1

1

you should use 'webpack' instead of 'webpack-dev-server', coz 'webpack' do generate your code to the disk while 'webpack-dev-server' just serve your code to your localhost

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.