What could be causing me to receive two builds when using Webpack?

I am trying to capture the hash of the build by using a callback function in webpack:

const compiler = webpack(webpackConfig, function (err, stats) {
  debug("Hash", stats.hash)
})

However, I am encountering an issue where two builds are generated and only one hash can be captured from within the callback. I need to access the other hash instead.

Here is the output with a callback function:

app:server Hash +7s ea34c7a4d34baae1c353
webpack built d796ba7633cf5b1023a0 in 6673ms
Hash: ea34c7a4d34baae1c353
Version: webpack 1.13.1
Time: 6649ms
Asset       Size  Chunks             Chunk Names
app.ea34c7a4d34baae1c353.js    1.27 MB       0  [emitted]  app
1.counter.ea34c7a4d34baae1c353.js     247 kB       1  [emitted]  counter
vendor.ea34c7a4d34baae1c353.js     389 kB       2  [emitted]  vendor
app.ea34c7a4d34baae1c353.js.map    1.54 MB       0  [emitted]  app
1.counter.ea34c7a4d34baae1c353.js.map     303 kB       1  [emitted]  counter
vendor.ea34c7a4d34baae1c353.js.map     466 kB       2  [emitted]  vendor
favicon.ico    24.8 kB          [emitted]
index.html  595 bytes          [emitted]
Child html-webpack-plugin for "index.html":
Asset    Size  Chunks       Chunk Names
index.html  553 kB       0
webpack: bundle is now VALID.
  Hash: d796ba7633cf5b1023a0
Version: webpack 1.13.1
Time: 6673ms
Asset       Size  Chunks             Chunk Names
app.d796ba7633cf5b1023a0.js    1.17 MB       0  [emitted]  app
vendor.d796ba7633cf5b1023a0.js     389 kB       1  [emitted]  vendor
app.d796ba7633cf5b1023a0.js.map    1.42 MB       0  [emitted]  app
vendor.d796ba7633cf5b1023a0.js.map     466 kB       1  [emitted]  vendor
favicon.ico    24.8 kB          [emitted]
index.html  595 bytes          [emitted]
Child html-webpack-plugin for "index.html":
Asset    Size  Chunks       Chunk Names
index.html  553 kB       0
webpack: bundle is now VALID.

Output without using a callback:

Hash: c5e31d1eb986b7ef318d
Version: webpack 1.13.1
Time: 3891ms
Asset       Size  Chunks             Chunk Names
app.c5e31d1eb986b7ef318d.js    1.26 MB       0  [emitted]  app
1.counter.c5e31d1eb986b7ef318d.js    30.6 kB       1  [emitted]  counter
vendor.c5e31d1eb986b7ef318d.js     389 kB       2  [emitted]  vendor
app.c5e31d1eb986b7ef318d.js.map    1.54 MB       0  [emitted]  app
1.counter.c5e31d1eb986b7ef318d.js.map    37.9 kB       1  [emitted]  counter
vendor.c5e31d1eb986b7ef318d.js.map     466 kB       2  [emitted]  vendor
favicon.ico    24.8 kB          [emitted]
index.html  595 bytes          [emitted]
Child html-webpack-plugin for "index.html":
Asset    Size  Chunks       Chunk Names
index.html  553 kB       0
webpack: bundle is now VALID.

The file link provided for reference: https://github.com/davezuko/react-redux-starter-kit/blob/master/server/main.js

Answer №1

After some investigation, I have discovered that in the Webpack's source code, if a callback is provided to the webpack(options, callback) function, it will automatically run itself:

function webpack(options, callback) {
    ...
    if(callback) {
      ...
      compiler.run(callback);
    }
    return compiler;
}

To add a callback, you can do so by adding a plugin like this:

compiler.plugin("done", stats => {
  debug(hash)
})

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

The xslt code is failing to invoke the JavaScript function

I am currently utilizing xslt for the transformation of xml to html. Below is an example of an .xml file. <ImportOrganizationUtility-logging> <log-session module-name="ImportOrganizationUtility" end="17:54:06" start="17 ...

Having a minor problem in attempting to retrieve a random value

Having trouble generating a random number from a function. Can someone help explain? const MyButton = document.querySelector(".Flipper"); MyButton.addEventListener("click", recordLog); function recordLog (){ MyButton.style.backgr ...

"Embedding PHP code within HTML tags, which is then embedded within

Running into an issue within a while loop... echo 'var contentString = '<div id="content" > <div id="bodyContent"> <p>' + $row[name]+ '</p> ...

"Encountering a problem with numerous callbacks in the getJSON method

I am working on creating marker pop ups that display information from different ajax requests on a map. In order to make the second call, I utilize an userID obtained from the first call. While the information from the second call is displayed correctly, ...

Conceal Tooltips with Materialize CSS

I'm trying to figure out how to hide the tooltip that appears when hovering over this element using Materialize CSS. <li><a class="btn-floating green" onclick="window.print();return false;"><i class="material-icons tooltipped" data-pos ...

Issues with rendering in-line styles in ReactJS after a state update

I'm currently working on implementing a basic state change for a button in React. 'use strict'; class ReactButton extends React.Component { constructor(props) { super(props); this.state = {hovering: false}; } onClick() { ...

Ensure that the input field only accepts numerical values

Can anyone help me with an issue I'm facing in my plunker? I have an input text field that I want to accept only numbers. Despite trying normal AngularJS form validation, the event is not firing up. Has anyone encountered a similar problem or can prov ...

Error: Unable to call topFrame.window.changeSelectedBarStyle because it is not a valid function. What could be causing this

This function is called changeSelectedBarStyle: function changeSelectedBarStyle(tdId){ $("#menuTable td").each(function(index){ if(this.id == tdId){ $(this).removeClass("menuPanel"); $(this).addClass("menuPanelSelected" ...

"Interactive Connect 4 Game in Javascript - Drop the disk into the bottom row of the chosen

Check out this awesome Connect4 game I found: http://codepen.io/anon/pen/lmFJf I have a specific goal in mind for the game. When I click on an empty space in any column, I want it to automatically drop into the lowest available spot in that column, follow ...

The query callback does not recognize 'done' as a function, leading to a

I'm attempting to save the result of a query into a variable. I've learned that using a callback is necessary for this task. However, I am encountering errors in the process. function fetchUserData(user) { if (user.checkUserStatus) { var u ...

Stop jQuery function from activating twice during scrolling

I'm looking for a solution to optimize my code that detects if an element is in the viewport and triggers certain actions. Currently, it re-runs the code every time a scroll event occurs when the element is above the fold. Is there a way to make it on ...

JavaScript - issue with event relatedTarget not functioning properly when using onClick

I encountered an issue while using event.relatedTarget for onClick events, as it gives an error, but surprisingly works fine for onMouseout. Below is the code snippet causing the problem: <html> <head> <style type="text/css"> ...

Efficiently Loading Vue Components with Webpack 2

I am interested in experimenting with lazy loading using webpack. I have divided my app by routes, and each route requires a specific component: const Home = resolve => { require.ensure([ "../components/Home/Home.vue" ], () => { resolv ...

Bypass the Array.reduce method in JavaScript

I'm currently working on finding an elegant solution to a toy example pattern. The goal is to stop the reduce algorithm immediately and return 0 when an element with a value of 0 is encountered, without processing the rest of the elements. let factor ...

A guide on extracting individual Json fields and assigning them to separate variables

I have a JSON object that I need to break down into individual fields and then use each field separately. However, the code I wrote below is not functioning correctly and returns "undefined" in the alert message. This is my code snippet: $( document ).r ...

Incorporating mootools scripts into a gwt application

My issue involves creating an animation on a Composite that should start when data is loading. To test this, I created animations on regular divs using HTML: <div class="LoadDataWidget"> <div id="arrow" class="greenArrow"></div> < ...

An effective way to prevent right-clicking on iframes across all websites

I am facing an issue with disabling right click for the iframe. I've successfully disabled it for the default URL of the IFrame, but when displaying any other webpage, the right click remains usable. Below are the sample codes I have used: document.o ...

Is there a way to identify if you are at the bottom row of a column defined by CSS styling?

I have implemented the new CSS-style column to divide a single unordered list into multiple columns. Now, I am trying to figure out how to target the last element in each column using JavaScript or CSS. Here is my HTML: <ul> <li /> <li ...

The useEffect alert is triggered before the component is re-rendered

Can someone help me understand why the HP in the code below is displayed as "1" when the alert is thrown, and only set to "0" after I confirm the alert? Shouldn't the component be rerendered before the alert is thrown so that it has already been displ ...

Looking for assistance with implementing the Vue CDN script in a Laravel Blade template

Hey everyone, currently I am working on a project called Register Page. My goal is to incorporate Vue cdn and Vue Consoles within the blade template. I have implemented a show/hide option without any console errors appearing. However, when I click on the ...