watchWebpack is compiling all the files

As per the webpack documentation on watching files

webpack can keep an eye on files and recompile them whenever there are changes.

My understanding is that this implies webpack will only compile the files that have been modified.

I have a configuration file named webpack.config.js structured like this:

module.exports = {
    watch: true,
    watchOptions: {
        ignored: /node_modules/,
    },
    entry: {
        "first": './web/assets/js/first.tsx',
        "second": './web/assets/js/second.tsx',
    },
    // other stuff
}

However, when I run ./node_modules/.bin/webpack, the output log suggests that ALL files are being compiled,

Webpack is currently monitoring the files…

Hash: d0ac7b9d70b906068f77
Version: webpack 4.3.0
Time: 10462ms
Built at: 3/29/2018 11:50:43 AM
              Asset       Size  Chunks             Chunk Names
    first.js    234 KiB       0  [emitted]  first
second.js  739 bytes       1  [emitted]  second
Entrypoint second = second.js
Entrypoint first = first.js
  [13] ../locale-data/index.js (ignored) 15 bytes {0} [built]
  [14] ./web/assets/js/react/component/First/First.tsx 1.05 KiB {0} [built]
  [15] ./web/assets/js/translations/tr.ts 4.83 KiB {0} [built]
  [16] ./web/assets/js/translations/it.ts 4.64 KiB {0} [built]
  [17] ./web/assets/js/translations/fr.ts 4.78 KiB {0} [built]
  [18] ./web/assets/js/translations/en.ts 4.31 KiB {0} [built]
  [19] ./web/assets/js/translations/de.ts 4.67 KiB {0} [built]
  [31] ./lib/locales (ignored) 15 bytes {0} [built]
  [37] ./lib/locales (ignored) 15 bytes {0} [built]
  [57] ./web/assets/js/first.tsx 559 bytes {0} [built]
  [58] ./web/assets/js/second.tsx 350 bytes {1} [built]
    + 48 hidden modules

Even if I make a change in first.tsx, the output remains the same. It appears that every file is being recompiled instead of just the one that has changed. Is there something I'm missing or misunderstanding here?

My intention is to solely recompile the files that have undergone modifications which is how I believe webpack watch should operate.

Update: To further support this point, I deleted both compiled files, altered a line in one entry point, yet the watcher still compiled both.

Update2: Here are steps for reproduction

Steps to reproduce: Assuming you already have yarn/npm installed.

  • Clone my repository from https://github.com/tzfrs/webpack-watch-bug
  • Initially run yarn install or npm install.
  • Execute ./node_modules/.bin/webpack. This should generate two files in the dist folder and automatically start watching.
  • Delete dist/second.js
  • Make a change in src/first.js
  • src/second.js remains unchanged but will still be recompiled (due to dist/second.js being recreated).

Answer №1

Webpack and other similar watchers store the entire bundle in memory and monitor a file stream. It operates like an asynchronous reduce function, updating the accumulated bundle each time new data is pushed to the stream until the task is completed when the stream closes.

If there is an out directory specified, the watcher will write the latest version of the bundle (the entire bundle) to that directory whenever a change occurs. Although we may perceive this as the main objective, it can be considered more of a "side effect" based on the reduce analogy.

This doesn't mean that everything is recompiled from scratch each time...in fact, unexpected changes such as a risky deletion can disrupt the watcher since it does not start over completely with each modification.

To see this in action, try cloning a larger project and observe the contrast between the initial compilation (full bundle) and subsequent updates (single files). You should notice a significant difference in the time taken for each process.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Is there a way to show a progress bar that functions as the background for a table row

My table is structured as follows: th1 th2 th3 th4 th5 th6 td1 td2 td3 td4 td5 td6 td1 td2 td3 td4 td5 td6 I am looking to incorporate a feature where new rows are dynamically added using a form that triggers ...

Ways to reposition JavaScript output within a webpage

I am new to HTML, CSS, and JavaScript and I have a question regarding how they work together. I can use JavaScript to display objects on the page, but I'm unsure how to move them around like other elements. Is CSS the solution for this? Any advice w ...

What is the best way to paginate a dynamically updated data table using AJAX in Laravel?

I'm currently facing an issue with rendering a Blade template in Laravel. The template includes an HTML table populated with data fetched via AJAX, and I need to implement manual pagination using Laravel's LengthAwarePaginator. The main Blade fi ...

JQuery fixed div bounces unpredictably when scrolling

Currently, I have a scenario on my webpage where there is a div called RightSide positioned on the far right side below another div named TopBanner. The TopBanner div remains fixed at the top of the screen even when the user scrolls down, which is exactly ...

Is there a distinction in invoking a service through reference or directly in Dependency Injection?

QUERY: Are there any discernible differences between the two instances of utilizing a factory service? Instance 1: angular.module('ramenBattleNetworkApp') .controller('MainCtrl', function ($scope, Helpers) { var testArray = [1 ...

If you're not utilizing v-model.lazy, Vue3 Cleave js may encounter functionality issues

I am currently experimenting with cleavejs to format the thousand separator in my input numbers. I've noticed a strange behavior where if I input 1000.123, it displays as 1,000.12 which is the correct format. However, the v-model value remains as 1000 ...

js extracting information from the XML response using response.text()

Currently, I am sending an ajax request to an API that returns data in XML format. Upon receiving the responseXml data, it gets displayed, but I'm unsure about how to parse it and access specific data elements such as item.line or item.origTime. Shou ...

Fetching the jquery variable within an HTML document: A step-by-step guide

Here is the content of my check.js JavaScript file, which includes a function: function fun2(userid) { $.ajax({ type: 'POST', url: 'ex.php', data: {userid: userid}, success: function (data) { ...

Having trouble passing data from router to View with EJS in Express. Despite trying, still encountering ReferenceError message

I encountered an issue when trying to display form errors to the user. I attempted to pass the errors from the router to my view file. Error Message ReferenceError: e:\2016\passport\views\register.ejs:38 36| 37| <div ...

Sending a Django form using AJAX and jQuery: A step-by-step guide

After researching various tutorials on django AJAX forms, I've found that each one offers a different method, but none of them seem simple. Being new to AJAX, I'm feeling a bit confused by the complexity involved. In my specific case, I have a m ...

Display the table once the radio button has been selected

Before we proceed, please take a look at the following two images: image 1 image 2 I have over 20 fields similar to 'Image 1'. If "Yes" is selected, then a table like in 'Image 2' should be displayed. This means I have 20 Yes/No fields ...

Managing UTC calculations with date-fns library in Node.js: A complete guide

Having some trouble with the date-fns library when trying to manipulate UTC dates. When attempting to add or subtract dates, it seems like the library isn't handling them correctly. An example: > const { add } = require('date-fns'); undef ...

What is the best way to use AJAX to send a downloadable file in WordPress?

Currently working on developing a WordPress plugin and could use some assistance ...

The Ajax post function is not functioning as expected

Here is my code: $.ajax({ type: "POST", url: "mailyaz.php", data: { name: "testest" } }); Currently, the code works with a simple message of "testest". However, I am trying to post my javascript variable (var mysubjec ...

Can you provide the name of the slideshow plugin used on the Wipro website?

Can anyone tell me the name of the image slide show featured on: http://www.wipro.com/index.htm? Also, does anyone know where I can find the script for free? I am looking to incorporate it into a page that is coded in php, html, css, and javascript. Than ...

Having trouble making jQuery code disable input field based on checkbox status

Is there a way to automatically disable the price input field once the checkbox is checked and clear any existing text? I seem to be having trouble with my current code.. <script src="http://code.jquery.com/jquery-1.9.1.js"></script> <scr ...

The "add to cart" button is unresponsive

My issue is that the add to cart button on my website is not responding properly. I have implemented JavaScript on the add to cart button, where I have assigned an attribute called data-product with a value of {{product.id}}. var updateBtns = document.g ...

How can I add text to an HTML5 SVG similar to using the HTML5 <p> tag?

I am currently working on creating dynamic rectangular boxes and I am facing some difficulties with inserting text into the shapes. The SVG text requires setting x and y coordinates in separate text tags, and doesn't have built-in width and height pro ...

Is there a way to retrieve information from a different object?

Access the code on Plunker I am working with two data structures - ingredients and recipes [{ "id":"1", "name": "Cucumber" }, .. ] and [{ "id":"1", "name": "Salad1", "recipein":[1, 3, 5] }, { ... } ] My goal is to ...

Is it better to utilize AngularJS $http service for making requests, or should I opt for jQuery AJAX if available

When working on my project, I rely on the angularjs framework and always enjoy utilizing the $http service for ajax calls. However, I have come across situations in the project where the UI is not directly impacted by the ajax call and angularjs bindings a ...