Monitoring a folder using webpack

Currently, I have webpack set up in my development environment to bundle all of my dependencies. To help concatenate various js files and include them in a script tag within the markup, I am utilizing the

webpack-merge-and-include-globally
plugin.

Although when I run webpack with the --watch flag, it only watches my entry file (build/index.js). What I really need is for webpack to also watch every file within the /build/ directory, along with any additional files or directories I may add there - essentially, I require a "deep watch". Is there a way to configure webpack to achieve this deep watch for an arbitrary directory not connected to my entry file?

webpack.config.js

const path = require('path');
const TerserPlugin = require("terser-webpack-plugin");
const merge = require('webpack-merge-and-include-globally');

module.exports = {
    entry: "./build/index.js",
    module: {
        rules: [
            {
                test: /\.s[ac]ss$/i,
                use: [
                    "style-loader",
                    "css-loader",
                    "sass-loader",
                ],
            },
        ],
    },
    output: {
        path: path.resolve(__dirname,'dist'),
        filename: 'bundle.js'
    },

    plugins: [
        new merge({
            files: {
                "./app.js" : [
                    './build/js/app.js',
                    './build/js/controllers/*',
                ],
            },
        }),
    ],

    optimization: {
        minimize: process.env.NODE_ENV === 'production',
        minimizer: [new TerserPlugin()]
    },

    mode: process.env.NODE_ENV === 'production' ? 'production' : 'development'

}

Answer №1

For an efficient solution, consider incorporating the following webpack-watch-files plugin:

import WatchExternalFilesPlugin from 'webpack-watch-files-plugin'

const config = {
  // ... your existing webpack configuration ...
  plugins: [
    // ....
    new WatchExternalFilesPlugin({
      files: [
        './src/**/*.js',
        '!./src/*.test.js'
      ]
    })
  ]
}

Answer №2

To ensure continuous building after any file changes, remember to include watch: true in the configuration settings. This will trigger a rebuild whenever a file is saved. Keep in mind that you still need to manually start the initial build 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

The most efficient method for searching and deleting elements from an array in Mongoose

I'm currently struggling with my implementation of mongoose in express. It seems like I'm using too many queries just to add something to a document, and I can't help but feel that there's a simpler way to achieve this. This function i ...

Distribute your SolidJS Typescript components on npm

Recently, I developed a SolidJS TypeScript UI component and successfully published it to the npm registry. The project structure is organized as follows: |-app |-index.html |-src |-index.tsx |-App.tsx |-utils |- ... |-com ...

The alertify.alert function encounters issues when used within the response of a mithril m.request

I'm currently working on a project utilizing mithril.js and also integrating alertify.js. I am encountering an issue when trying to alert some data in the response. Strangely, it doesn't work as expected. However, if I use the same alert function ...

What is the process for generating a file in Node and Express on my server and subsequently transmitting it to my client for download? My technology stack includes NextJS for both frontend and backend operations

How can I generate a file using Express and Node on my server, and then successfully download it to the client? My tech stack includes NextJS for both frontend and backend, and with React as the frontend framework. I'm facing difficulty figuring out h ...

Activate the dialog box exclusively after data has been submitted via the submit button on a form

My goal is to create a data saving functionality with a next button. After filling out the form, clicking on the next button triggers a popup dialog asking, "Do you want to submit your data?" To achieve this, I included the following code in my submit but ...

The npm update command seems to be disregard the information provided by npm outdated

After running npm outdated on my project, I discovered that there were multiple outdated packages. Subsequently, I executed npm update, which successfully updated some of the packages but not all. Even after running npm outdated again, the remaining outdat ...

Encountering Hermes errors while running npx react-native run-ios

I've been troubleshooting the npx react-native run-ins command for the last hour, encountering these persistent errors: ERROR TypeError: undefined is not a function, js engine: hermes ERROR Invariant Violation: Failed to call into JavaScript modul ...

How can I retrieve objects using the JSON function?

I need to design a function that returns objects like the following: function customFunction(){ new somewhere.api({ var fullAddress = ''; (process address using API) (return JSON data) })open(); } <input type= ...

Loop through items in a list using Angular.js and display each item within an <

I am facing an issue where the model returned from the server contains html tags instead of plain text, such as b tag or i tag. When I use ng-repeat to create a list based on this model, the html is displayed as pure text. Is there a filter or directive av ...

Retrieve the row id from the table by clicking on a button in a modal box using jQuery

I am encountering a challenge with a small task due to my limited experience in jQuery. I have a table where each row has an icon. When the icon is clicked, a modal box appears with some content. After closing the modal box, I want to retrieve the table ro ...

Use the regex tag in a React component to find a specific tag by name within two different possible

Looking for a regex that can identify <Field ...name="document"> or <FieldArray ...name="document"> within a multiline text string so they can be replaced with an empty string. The text string is not formatted as HTML or XHTML, it simply conta ...

Remove an item from an array within Express using Mongoose

{ "_id": "608c3d353f94ae40aff1dec4", "userId": "608425c08a3f8db8845bee84", "experiences": [ { "designation": "Manager", "_id": "609197056bd0ea09eee94 ...

What are the steps involved in converting a MERN application into a desktop application?

As a beginner in front-end application development, I recently created a MERN application in React with separate frontend and backend parts. Everything is working smoothly, but now I want to convert it into a desktop application that can run independently ...

Ensuring the website retains the user's chosen theme upon reloading

I have been developing a ToDo App using MongoDB, EJS, and Node JS. My current challenge involves implementing a theme changer button that successfully changes colors when clicked. However, whenever a new item is added to the database, the page reloads caus ...

Is there a way to update all scoped packages to a specific tagged version at once?

Is there a method to upgrade all scoped packages to a specific tag other than latest? For example, let's say I have multiple packages under the scope @scope, such as @scope/pkg1, @scope/pkg2, and so on. These packages have tags like stable. Is it pos ...

Node.js encounters an npm error during the installation of the Express package

Encountering an issue with npm install express. The error message reads "Unexpected end of JSON input while parsing near '..."dist":{"shasum":"e84'". > 0 info it worked if it ends with ok > 1 verbose cli [ 'D:\\Prog ...

Preserving the button's state when clicked

Here is my code snippet: <blink> const [thisButtomSelected, setThisButtomSelected] = useState(false); var thisButton = []; const onAttributeClick = (e) => { thisButton[e.currentTarget.value] = { thisID: e.currentTarget.id, thisName: e. ...

Is there a method to generate an endless carousel effect?

Hello, I am trying to create an infinite carousel effect for my images. Currently, I have a method that involves restarting the image carousel when it reaches the end by using the code snippet progress = (progress <= 0) ? 100 : 0;. However, I don't ...

Investigating the variety of HTTP 206 responses pertaining to video content

Currently, I am utilizing Amazon CloudFront to serve HTML5 videos. These videos are being requested through HTTP range requests and the expected responses are often in the form of HTTP 206 Partial Content. I have a requirement where I want to log the requ ...

Creating a custom pipe that converts seconds to hours and minutes retrieved from an API can be achieved by implementing a transformation function

Can someone please provide guidance on creating a custom pipe in Angular 8 that converts seconds to hours and minutes? Thank you. <div class="col-2" *ngFor="let movie of moviesList"> <div class="movie"> {{ movie.attributes.title }} ...