webpack / webpack-dev-server

Serves a webpack app. Updates the browser on changes. Documentation https://webpack.js.org/configuration/dev-server/.
MIT License
7.8k stars 1.44k forks source link

Running the server does not compile files or reload page in windows. #155

Closed quantuminformation closed 8 years ago

quantuminformation commented 9 years ago

From the docs it says:

It binds a small express server on localhost:8080 which serves your static assets as well as the bundle (compiled automatically). It automatically updates the browser page when a bundle is recompiled (socket.io). Open http://localhost:8080/webpack-dev-server/bundle in your browser.

However if I run it this doesn't happen: I just get the following, but when I go to the serving URL I still have my old code.

C:\Users\Laptop\WebstormProjects\wirejs-client>npm run start

> wirejs-client@0.1.0 start C:\Users\Laptop\WebstormProjects\wirejs-client
> webpack-dev-server

http://localhost:8080/webpack-dev-server/
webpack result is served from /
content is served from C:\Users\Laptop\WebstormProjects\wirejs-client
webpack: wait until bundle finished: /webpack-dev-server/
Hash: 25bf81a3ab16cfec1760
Version: webpack 1.8.4
Time: 8688ms
        Asset     Size  Chunks             Chunk Names
    bundle.js  4.37 kB       0  [emitted]  main
bundle.js.map     4 kB       0  [emitted]  main
chunk    {0} bundle.js, bundle.js.map (main) 2.69 kB [rendered]
    [0] ./app/main.js 295 bytes {0} [built]
    [1] ./app/wirejs-client.js 2.39 kB {0} [built]
webpack: bundle is now VALID.
ghost commented 8 years ago

Thanks @nathanborror for your hint about the Dropbox for Business's path convention, that solved it for me.

eromoe commented 8 years ago

A project I used has below code

const path = require('path');
const express = require('express');
const webpack = require('webpack');
const config = require('./webpack.config.dev');

const app = express();
const compiler = webpack(config);

app.use(require('webpack-dev-middleware')(compiler, {
  noInfo: true,
  publicPath: config.output.publicPath
}));

app.use(require('webpack-hot-middleware')(compiler));

app.get('*', (req, res) => {
  res.sendFile(path.join(__dirname, 'index.html'));
});

It use npm run dev to start, hot reload work on windows 8.1 but windows 7 What's the problem? I don't know much about webpack, ..

rajyavardhanp commented 8 years ago

webpack-dev-server --content-base ** --inline --hot * >> should be your output folder ./dist or wherever you are building the output

If you don't want to reload the page every time, for most platforms localhost:8080 is enough, else check in localhost:8080/webpack-dev-server/index.html

Ajaybhardwaj7 commented 8 years ago

Here is the sample working app which I have created after two days of struggle. I have used the webpack dev server API method. https://github.com/Ajaybhardwaj7/webpack-react-sample

blackhawk389 commented 8 years ago

@QuantumInformation I have successfully launched recompiled file(not manually refresh), how? seting path to dist folder and devServer: { contentBase: "./dist", }, doing this

jshbrntt commented 8 years ago

Moved from OS X to Windows 10 and now webpack-dev-server is not detecting changes and rebuilding the bundle. I'm using Atom so there's no safe write, so that shouldn't be the problem.

I've attempted most solutions in this issue to no avail.

Here's my config see devServer.

Kekesed commented 8 years ago

same here, i have the exact same problem with @synthecypher

lostpebble commented 8 years ago

Depending on what editor you're using, that could be causing the issue. Just found out that WebStorm was giving me this problem from Windows but not on Ubuntu (the settings must have been different on each).

The setting I had to disable which made all the difference was use "safe write" (found in Appearance & Behaviour > System Settings), which saves changes first to a temporary file. Saving like that doesn't get picked up by webpack of course, was the cause of much frustration.

amcdnl commented 8 years ago

I can't get it to work either, everything loads fine but upon refresh auto or even manual it does not reflect updates. My config is: https://github.com/swimlane/angular2-data-table/blob/master/webpack.config.js

AurelioDeRosa commented 8 years ago

I've had the same problem with webpack 1.13.1 and webpack-dev-server 1.14.1 on Windows 10. Adding the following code to the webpack.config.js file solved the issue:

plugins: [
   new webpack.OldWatchingPlugin()
]
jshbrntt commented 8 years ago

@Kekesed I managed to get it working it appears that it was caused by the paths not being correct for Windows. Wrap any applicable paths in path.resolve and path.join should do the job.

Here's the updated config feel free to clone my repo and test for yourselves.

cooervo commented 8 years ago

This is what worked for me in windows 10:

//Webpack.config.js file:

var debug = process.env.NODE_ENV !== "production";
var webpack = require('webpack');
var path = require('path');

module.exports = {
  context: path.join(__dirname, "src"),
  devtool: debug ? "inline-sourcemap" : null,
  entry: "./js/client.js",
  module: {
    loaders: [
      {
        test: /\.jsx?$/,
        exclude: /(node_modules|bower_components)/,
        loader: 'babel-loader',
        query: {
          presets: ['react', 'es2015', 'stage-0'],
          plugins: ['react-html-attrs', 'transform-class-properties', 'transform-decorators-legacy'],
        }
      }
    ]
  },
  output: {
    path: path.join(__dirname, '/src/'),
    publicPath: '/src/', // instead of publicPath: '/build/'
    filename: 'client.min.js'
  },
  plugins: debug ? [] : [
    new webpack.optimize.DedupePlugin(),
    new webpack.optimize.OccurenceOrderPlugin(),
    new webpack.optimize.UglifyJsPlugin({ mangle: false, sourcemap: false }),
  ],
};

Go to cmd and type: webpack-dev-server --watch-poll

This is my dir structure: image

In browser go to: http://localhost:8080/webpack-dev-server/

sushicutta commented 8 years ago

Windows 10 - IntelliJ Ultimate (aka Webstrom) this solved it for me:

<< Depending on what editor you're using, that could be causing the issue. Just found out that WebStorm was giving me this problem from Windows but not on Ubuntu (the settings must have been different on each).

The setting I had to disable which made all the difference was use "safe write" (found in Appearance & Behaviour > System Settings), which saves changes first to a temporary file. Saving like that doesn't get picked up by webpack of course, was the cause of much frustration. >> Thanks to @lostpebble

SpaceK33z commented 8 years ago

Closing because there are several answers to the problem. Some of these issues are also documented.

If anyone still has an issue, feel free to create a new issue.

alb3rto269 commented 8 years ago

This might be related to: https://github.com/webpack/webpack-dev-server/issues/324 The solution posted in that other issue solved my problem.

fazalrasel commented 8 years ago

Those using Polling, watch for RAM use...

An-Dang commented 8 years ago

I used Intellij 2016.2.3 on Win1 and I've also solved the problem with ctrl + s.

awesomund commented 8 years ago

Also experienced this problem with webpack-hot-middleware on my own express-server.

Adding watchOptions to my webpack-dev-middleware-options solved this for me.

relevant part of my server.js:

app.use(require('webpack-dev-middleware')(compiler, {
  noInfo: true,
  publicPath: webpackConfig.output.publicPath,
  watchOptions: {
    aggregateTimeout: 300,
    poll: 1000
  }
}));
dharmesh-khandelwal commented 8 years ago

@dryoma Thank You!! I removed () from the folder name, and live reloading works :)

CocaCola183 commented 8 years ago

@wmira Save my life

jartaud commented 8 years ago

@awesomund works for me. Vue Cli webpack, Laravel Homestead, Win10,

Kielan commented 8 years ago

Crazy this issue has been closed a year ago, tons of people on many machines still have it, and no solution by authors. On osx and have the same problem.

I know one could say "it's open source you should fix it"

SpaceK33z commented 8 years ago

There is not really a clear issue here, various people have posted their various issues here. If you still have a problem with reloading, please create a new issue and fill in all details. Locking this thread.