execute gulp script - combine and compress components

How can I efficiently concatenate and minify modules in my project?

I have a list of JavaScript files from different bower components:

<script type="text/javascript" src="bower_components/angular-route/angular-route.js"></script>
<script type="text/javascript" src="bower_components/angular-bootstrap/ui-bootstrap-tpls.js"></script>
<script type="text/javascript" src="bower_components/angular-ui-router/release/angular-ui-router.min.js"></script>
<script type="text/javascript" src="bower_components/satellizer/satellizer.min.js"></script>
etc...

My goal is to combine them into a single file like this:

<script src="js/all_bower_components.js"></script>

While I already have a build process for my own JS files that works well, concatenating and minifying them into main.js, the structure of bower components is less predictable:

bower_components/
   angular/
       angular.js
       index.js
       other random js files which aren't the ones I need
   jquery/
       dist/
           jquery.js
       src/
           bunch of other crap

Currently, my approach involves looping through all components and subfolders looking for .js files. However, this method may include unnecessary files like index.js in Angular:

gulp.task('modules', function() {
    return gulp.src(['bower_components/**/*.js'])
        .pipe(concat('modules.js'))
        .pipe(uglify())
        .pipe(gulp.dest('public/js'));
});

Do you have any suggestions or alternative approaches?

Answer №1

Have you considered using main-bower-files? This clever gulp extension is designed to automatically extract all the necessary .js and .css files from your bower components by analyzing their bower.json file and identifying the files listed as main. If needed, you can customize the extraction process to meet specific requirements that differ from the bower.json configuration. I have personally found this tool incredibly helpful for bundling a vendor.js and vendor.css when working on projects with multiple dependencies.

Best of luck with your project!

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

Retrieve the properties of an object

I have a JavaScript program where I retrieve values from a JSON file and store them in an array. However, when I attempt to access the elements of this array, it returns nothing. Below is the function that pushes temperatures: temperatures = [] get_info ...

Leveraging ng-src and performing an HTTP GET request

I am currently working with an image handler that fetches image byte streams from a database and returns an HTTP response with content-type set to "image/jpeg." Within my AngularJS application, I want to retrieve these images and display them in a table. ...

Optimizing the If operator in JavaScript to function efficiently without causing the page to reload

While delving into jQuery and attempting to create a slider, I encountered a problem. After the slider passed through the images for the second time, the first image would not appear. My approach involved using margin-left to move the images. $(document ...

Prevent tab switching from occurring by disabling click functionality on tabs

I've got different tabs set up in a similar way <md-tabs md-selected="selectedTab()"> <md-tab label="General"></md-tab> <md-tab label="Type"></md-tab> <md-tab label="Details"></md-tab> </md-tab ...

Navigating through designated interval inside js es6 map

I am currently working with a JavaScript map structure that is sorted based on time, storing object states. Map(key:time(inMilli), value: {object attributes}) My goal is to efficiently retrieve a collection of all values within a specific start and e ...

Cleve js does not include delimiters in its date output

In my Vue.js project, I decided to implement a date input field using cleave.js. After passing the following options: options="{date: true, delimiter: '/', datePattern: ['m', 'd', 'Y']}" I encountered an issue wh ...

How to get rid of blank options in a select element using Angular?

Currently, I am facing an issue with a select element that is linked to an array and used for listing purposes. The problem arises when the array is empty, causing an unwanted option element to be added to the select element. This results in the list being ...

Initializing Three.js to load the model

I have a 3D model that I initially had in the 3DS format. I then converted it to OBJ and finally to JS format. Now, my goal is to load this model into another JS file. Below you'll find the code snippet I've written for this purpose: var loader ...

The selenium click function is successful, but it fails to locate the element on the subsequent window

I am currently working with Angularjs ui-routes and I have a link that looks like this. <a ui-sref="devs" href="#/devs"> Devs</a> This is my code snippet: from selenium import webdriver driver = webdriver.Chrome('selenium-tests/chromed ...

Remove XML data from a record with a button click by utilizing AJAX in AngularJS

Hey there! I'm struggling to remove a record from an XML file that displays data in table form using AngularJS. Here is my code: The XML file content: <UserDetail> <Detail> <EmployeeID>124578</EmployeeID> <Employ ...

Executing JavaScript in Page Object Model

When working on my automation script using Java with Selenium and the Page Object Model, I sometimes find it necessary to utilize Javascript Executor. This is because default WebDriver clicks can result in exceptions when elements are not found. Within th ...

A guide to monitoring and managing errors in the react-admin dataProvider

Rollbar has been successfully integrated into my react-admin app to track uncaught errors. However, I've noticed that errors thrown by the dataProvider are not being sent to Rollbar. It seems like errors from the dataProvider are internally handled w ...

Guide to reactivating click functionality on a div using jQuery

Here is the code snippet in question: if ($selector.html().indexOf("radio") > 0) { if ($oldSelected != null) { // enable clicks on old selected radio button $oldSelected.children().bind('click', function ( ...

Displaying data in JSON format using AngularJS

My JSON data is structured as follows: var data = [ "val1":[ {"DATE":a1, "HEADER":b1, "MESSAGES":c1}, {"DATE":a2, "HEADER":b2, "MESSAGES":c2}, {"DATE":a6, "HEADER":b6, "MESSAGES":c6}, ], "val2":[ {"DATE":a5, " ...

Why does my ngFor consistently refresh while the array remains unchanged?

Issue at hand: Whenever I launch this component, the ngFor div continuously updates and causes my RAM to deplete. Typically, ngFor is triggered when the array is updated; however, in my case, the array (announcements) only updates once in the constructor. ...

Limit the execution speed of a JavaScript function

My JavaScript code is set up to trigger a click event when the user scrolls past a specific element with the class .closemenu. This is meant to open and close a header menu automatically as the user scrolls through the page. The problem I'm facing is ...

Unusual performance issues observed in a flexbox when adjusting window size in mobile Chrome

Encountering an unusual issue with flexbox on a mobile browser. For a visual demonstration, view this gif Specifically happening on Chrome mobile on a Google Pixel phone. Using a resize script to adjust element sizes due to limitations with 100vh: windo ...

The use of `await` within a loop may not function as anticipated when the code is being run through Puppeteer, yet it functions flawlessly when executed in the browser's console

Currently, I am assessing the functionality of the codeToBeEvaluated function within a browser environment using puppeteer. Within codeToBeEvaluated, there is a while loop designed to trigger an alert (referenced as LINE B) every 10 seconds. The issue ari ...

How can we determine if a Node.js application will remain operational?

How is the longevity of a Node.js app determined? For example, consider this code snippet: console.log('Hello World'); In this case, the phrase will be printed and the app will exit immediately. However, with a web server that is actively lis ...

Ensure menu options are aligned to the right using material-ui

My material-ui menu currently has the following setup: <span> <Link to="/issues"> <Button style={isActive(history, "/issues")}>Issues </Button> </Link> <Link to="/users"> <Button style={isActive(his ...