Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Watch files not required with webpack #34

Closed
gunta opened this issue Jun 28, 2014 · 13 comments
Closed

Watch files not required with webpack #34

gunta opened this issue Jun 28, 2014 · 13 comments

Comments

@gunta
Copy link

gunta commented Jun 28, 2014

Hi! Would it be possible to add to webpack-dev-server and middleware an option to watch also files outside the required ones?
This is needed specially for the HTML files, and maybe some css ones.

Thank you!

@sokra
Copy link
Member

sokra commented Jun 28, 2014

This should be possible within a plugin. Something similar to this:

plugins: [
  function(compiler) {
    compiler.plugin("after-compiler", function() {
      this.fileDependencies.push("/path/to/my/file");
      this.contextDependencies.push("/path/to/my/folder");
    }
  }
]

@kurtharriger
Copy link

I gave this a try and added this to the top of my gruntfile:

function WatchExternalFilesPlugin() {}
WatchExternalFilesPlugin.prototype.apply = function(compiler) {
  compiler.plugin("after-compile", function(compilation, callback) {
    compilation.fileDependencies.push("./app/worksheet.html");
    callback();
  });
};

When I change worksheet.html I see in the javascript console:

App updated. Recompiling... 
[WDS] App hot update... client?f5c9:52
[HMR] Checking for updates on the server... dev-server.js?05e4:41
GET http://localhost:8991/aa9359377b69ed42a399.hot-update.json 404 (Not Found) bootstrap aa9359377b69ed42a399?000c:23
[HMR] No Update found. 

If I comment out the HotModuleReplacementPlugin it will refresh the page otherwise it does nothing.

@tomek-he-him
Copy link

+1 for this feature

@Ciantic
Copy link

Ciantic commented Mar 28, 2015

Is this possible or not?

@jdeal
Copy link

jdeal commented Apr 21, 2015

Bit of a janky solution, but I used the text-loader module to do something like this. (In my case, CSS generated outside of webpack, but same principal.)

Basically, just npm install text-loader and then make a watch.js entry point (which you'll not actually use). In your watch.js file, add in text files like:

require('text!./app/worksheet.html');

That way, watch.js will get changed any time you change worksheet.html, and your app will get reloaded.

A better variant of this would be to have a "hash-loader" which would just MD5 hash the content and use that instead of the actual content, because in this case you don't actually need the content, just something to notify that there's a change. Should be pretty easy to create such a loader.

@airwin
Copy link

airwin commented Apr 29, 2015

+1

@jaredleechn
Copy link

👏

@SpaceK33z
Copy link
Member

Closing issue because the answer provided is clear; make a loader for this, or use an existing one :).

@ghost
Copy link

ghost commented Aug 15, 2017

Did anyone ever come up with a solution for this? It doesn't seem like fileDependencies or contextDependencies exist anywhere.

@dudewad
Copy link

dudewad commented Sep 4, 2017

@sokra shouldn't this be compiler.plugin('after-compile'...? I can't find any hooks anywhere called after-compiler.

@Fridus
Copy link

Fridus commented Nov 8, 2017

Hi, try this : https://github.com/Fridus/webpack-watch-files-plugin ;)

@sap9433
Copy link

sap9433 commented Nov 13, 2017

Just wrote a plugin that does exactly the same - solves your problem - https://www.npmjs.com/package/filewatcher-webpack-plugin .

@Fridus looks like this 1 got move power under its sleeve.

@ivanm376
Copy link

ivanm376 commented Jun 6, 2018

possible problem for Linux users see https://webpack.js.org/configuration/watch/#not-enough-watchers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests