Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I force a recompile when using Webpack Dev Server?

I'm using webpack-dev-server on a fairly large project at work. Sometimes, it doesn't recompile when I save a file, as it's supposed to, and I'm forced to repeat :w (the save command in Vim) until a few times for it to respond. It seems quite arbitrary how long it takes for the dev server to "notice" that I'm saving the file and trigger a recompliation, sometimes to the point where I just restart the entire dev server.

Is there a way to manually force a recompilation the same way saving a file should do it? Could I send the path to the file(s) I want recompiled somehow?

like image 773
ahstro Avatar asked Nov 21 '16 10:11

ahstro


2 Answers

This is not the stock webpack experience, so there is no built-in support for external tools to trigger re-builds (this should already have been facilitated by system events).

webpack uses chokidar to monitor the filesystem for changes. Try running with CHOKIDAR_USEPOLLING=250 webpack-dev-server $ARGS and see if that improves the experience for you.

If it doesn't work, I'm afraid you'll have to resort to running the server via the Node API and then exposing some endpoint which you can ping on changes.

like image 113
Filip Dupanović Avatar answered Oct 16 '22 12:10

Filip Dupanović


There are two issues going on in your question. One for webpack and one for Vim.

The easiest way to re-trigger webpack is to "fool it" into thinking a watched file changed. Say hello to the touch command. If one of your watched files is for example README.md, you can type touch README.md in your favorite terminal and webpack will do its magic (this command updates the timestamp of the target file to 'now').

In the case of using Vim, something else is happening. When you :w, according to Vim's configured file-saving behavior, Vim may decide to rename the old file and create a new file instead, saving the buffer to the newly created file. This makes it harder for the webpack watcher to notice changes. However, this can be changed in Vim. It's matter of adding a single line to your .vimrc, see: https://github.com/webpack/webpack/issues/781#issuecomment-95523711

To summarize, manually re-triggering a webpack build:

Touch a file in your project -> touch file/in/project.fun
(or)
Change your .vimrc -> :set backupcopy=yes

like image 39
Amir Eldor Avatar answered Oct 16 '22 12:10

Amir Eldor