Creating a Webpack setup to concatenate JavaScript files

Currently, I am utilizing webpack 4 to package my dependencies, specifically AngularJS, in the following manner:

index.js

require('angular');
require('angular-ui-router');
// ...

webpack.config.js

const path = require('path');

module.exports = {

  mode: "development",
  entry: "./build/index.js",
  output: {
      path: __dirname + '/public/js',
      filename: "bundle.js"
  }
}

With this setup, a file named bundle.js is created containing all the necessary dependencies.

In addition, I am interested in using webpack as a task runner to combine the Angular JS files from the directory /build/js into a single file (referred to as app.js) that will be saved within /public/js.

My ultimate goal is to have the contents of the concatenated angular files (that would typically reside in app.js) included within bundle.js, alongside the existing dependencies. However, I am uncertain if this approach is feasible or recommended practice.

Answer №1

According to @Pete's comment, webpack input can accept an array of entry paths. Although webpack itself does not support glob pattern directly, you can utilize the glob package for this purpose (assuming you have webpack installed, or you can download it from here):

const glob = require('glob');

module.exports = {
  mode: 'development',
  entry: glob.sync('./src/**/*.js'), // ['./src/a.js', './src/dir/b.js']

  ...
}

I hope this information proves useful!

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 setInterval method in Typescript/Javascript is unable to invoke other functions

I have a situation where I need to call the function callMe() every 1000 ms. While this setup is functioning as expected, I am encountering an issue when trying to call another function from within callMe(). The error message I am receiving is: uncaught ...

Populate a Textbox Automatically using a Dropdown List

MVC 4 Changing multiple display fields based on DropDownListFor selection Having some issues trying to implement the solution mentioned above. It seems like there might be a problem with either my javascript code or the controller. JavaScript in View ...

Tips for handling a JSON payload retrieved through a POST request

I'm currently working on a button that triggers a POST call to retrieve a json response from the server. My goal is to display this json response in a new (chrome) browser tab. Here's what I have so far using Angular: $http.post(url, data) .t ...

Here is a way to display the chosen option from a list using Angular Js

Seeking guidance on Angular.Js - I have a dropdown that successfully picks the selected data, but fails to display the selected value upon revisit. Is there a specific property I should set for this functionality? Snippet of my code: <select class=& ...

Displaying array elements at random in a React application

In the process of creating a compact React application with the assistance of the Potter-API, users can explore specific characters or spells. The app fetches data from the API and displays 6 random items (characters/spells) that lead to detailed views whe ...

tips on incorporating chosen while still enabling text input

I am currently utilizing chosen to showcase a single selection from a lengthy array of choices. In addition, I am seeking the functionality to enable users to submit a choice that is not listed among the available options. This customization is specifica ...

The Importance and Purpose of Incorporating a Callback

Understanding asynchronous operations and callbacks has been a challenge for me. To improve my familiarity with these concepts, I've been studying code examples that utilize them. However, there's one aspect of this specific code snippet that con ...

How to Align a Button in the Middle with Bootstrap?

Hey there! I'm working on creating a video list. I've utilized the bootstrap grid system to put it together. Here's the code I have so far: I'm trying to center the play button both vertically and horizontally within the thumbnail. Any ...

Comparing identical elements in JavaScript

Crucial Note I want to clarify that I have no intentions of scamming, phishing, or causing any harm. My goal is to develop a website magnifier similar to using a magnifier on paper. Dilemma Let me paint the picture for you. I've effectively copied ...

Error encountered with NodeJS Express Module: TypeError - Unable to access property 'finished' as it is undefined

Recently, I've been working on creating an API that can extract text from a website based on specific keywords. To achieve this, I utilized Selenium to load the site and retrieve the text. However, I encountered an issue with sending the extracted tex ...

What could be causing my checkbox to become unresponsive and fail to reset?

I recently created a function to update my page title when the toggle button is clicked, but unfortunately, it seems to be getting stuck after the click. I can't seem to pinpoint the issue with this function, as I've tried coding it in both JQuer ...

What could be causing the value of my variable tabledata to be undefined?

In my code, I am trying to achieve the functionality of returning a row from a table when it is clicked. This is accomplished using the jQuery function $("tr.table").click(function)..... Subsequently, I aim to store the data of this table row in ...

Validating Linkedin URLs with JavaScript for Input Fields

I've created a basic form with an input field for a LinkedIn URL. Is there a way to validate that this field only accepts valid LinkedIn URLs? Thank you! ...

Is it possible to invoke JavaScript code from TypeScript?

I'm struggling with calling a JavaScript file from TypeScript. After resolving one import issue and adjusting the base function for tsc recognition, I'm now stuck on recognizing a declared function prototype in the JavaScript file. Although I ha ...

Only refresh the content when there are updates from the ajax call

Currently, I am populating an HTML table with data retrieved through an AJAX request. The AJAX call is made at regular intervals of X seconds. I am specifically looking for a way to update the table only when the new data fetched from the AJAX call diffe ...

Non-responsive behavior triggered by a button click event (JavaScript)

Help needed with displaying results on the same page for an online calculator I'm creating. Why are the results not showing up as expected? I want users to input 4 pieces of information, have the logic executed, and then display the answers below th ...

My Discord.JS bot seems to be moving at a snail's pace, and I can

Apologies for the lackluster title, I'm struggling to come up with something better. I'm currently running a self-bot (I understand it goes against the terms of service but I'm experimenting) that needs to download new files (specifically i ...

What event gets triggered in the Google search bar?

When we type something in the Google search box, auto-complete results appear. After selecting one, it automatically executes without needing to trigger focusout() or any click(). How is this functionality created? ...

Node.js equivalent of PHP's SimpleXMLParser

One of the most user-friendly XML reading and writing APIs I've come across is PHP's SimpleXMLElement. For instance, to generate a DOM for the following XML code: <root> <foo> <bar baz="goo"> moo ...

Is it possible for ajax to provide me with the information regarding the data size of the URL

Is there a way for the xjr object to access the total data size in KB or MB? I have been using the progress event and it can track this, so I was curious about obtaining the total data size. Here is the code snippet: var container = Pub.el('#super-1 ...