Ordering the source files for the Grunt index task using globbing

Currently, I am utilizing VS2015 along with a grunt task in order to gather all the java-script files within my project and then insert them into my template index.html before executing the build. The issue that arises is the dependency order of these files. Specifically, I need to ensure that angular.js is included before ui-bootstrap-tpls.js to avoid any potential Reference errors. The problem lies in the fact that the src wildcard used in the index task is fetching the files in a particular order that does not align with the required dependency graph. Is there a way to customize this order without explicitly listing out each sub-directory, thus defeating the purpose of the hands-free template grunt task and complicating future additions of new dependencies (i.e. without having to add new directories)?

The index task has been registered with the following configuration:

index: {
        dev: {
            dir: '<%= wwwroot_dir %>',
            src: [
               '<%= build_dir %>/wwwroot/**/*.js',
            ]

Additionally, a multi-task has been implemented:

grunt.registerMultiTask('index', 'Process index.html template', function () {
    var dirRE = new RegExp('^(' + grunt.config('build_dir') + '/' + grunt.config('wwwroot_dir')
                                + '|' + grunt.config('compile_dir') + '/' + grunt.config('wwwroot_dir')
                                + '|' + grunt.config('build_dir')
                                + '|' + grunt.config('compile_dir')
                                + ')\/', 'g');

    var jsFiles = filterForJS(this.filesSrc).map(function (file) {
        return file.replace(dirRE, '');
    });

    var cssFiles = filterForCSS(this.filesSrc).map(function (file) {
        return file.replace(dirRE, '');
    });

    var sourcePath = userConfig.app_files.htmltemplate;

    grunt.file.copy(sourcePath, this.data.dir + '/index.html', {
        process: function (contents, path) {
            return grunt.template.process(contents, {
                data: {
                    scripts: jsFiles,
                    styles: cssFiles,
                    version: grunt.config('pkg.version')
                }
            });
        }
    });
});

An example of how the index.html file would look like:

    <html data-ng-app="app" data-ng-controller="AppCtrl" ng-init="">
    <head>
      <title data-ng-bind="pageTitle">MY APP</title>
      <meta charset="utf-8">
      <meta http-equiv="X-UA-Compatible" content="IE=edge" />
      <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">

      <!-- compiled CSS --><% styles.forEach( function ( file ) { %>
      <link rel="stylesheet" type="text/css" href="<%= file %>" />
      <% }); %>

      <!-- compiled JavaScript --><% scripts.forEach( function ( file ) { %>
      <script type="text/javascript" src="<%= file %>"></script>
      <% }); %>
   </head>
   <body>
      <div data-ui-view></div>
   </body>
    </html>

Example of defined directories (to be avoided if possible):

index: {
        dev: {
            dir: '<%= wwwroot_dir %>',
            src: [
                  '<%= wwwroot_dir %>/lib/angular/*.js',
                  '<%= wwwroot_dir %>/lib/angular-bootstrap/*.js',
                  ....etc
            ]

Answer №1

Through a brief investigation, I stumbled upon the information provided at gruntjs.com

In an effort to streamline complex globbing patterns, Grunt allows for arrays of file paths or globbing patterns to be specified. These patterns are processed sequentially, with matches prefixed by ! excluding files from the result. The resulting set is then made unique.

After observing the uniqueness brought about by this process, I decided to prioritize the essential dependencies at the beginning and utilize the wildcard later on. Interestingly, it seems that the uniqueness feature has successfully removed the duplicate instances while retaining the necessary ones.

index: {
        dev: {
            dir: '<%= wwwroot_dir %>',
            src: [
                '<%= wwwroot_dir %>/lib/jquery/dist/*.js',
                '<%= wwwroot_dir %>/lib/angular/*.js',
               '<%= wwwroot_dir %>/lib/**/*.js',
            ]
        }

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

While attempting to reinstall the admob-free plugin via npm, I encountered an error stating that it was missing a package.json file

While developing an app using Ionic, I encountered an issue with the AdMob plugin not being installed correctly. Trying to resolve this, I attempted to reinstall the plugin multiple times but kept running into errors. Seeking help from various threads, I ...

What could be causing the error with React npm start and webpack-dev-server version 3.11.1?

I encountered an error while running npm start in my React application: The react-scripts package provided by Create React App requires a specific dependency: "webpack-dev-server": "3.11.1" Do not attempt manual installation as your ...

Is there a way for me to determine if a route has been defined at the start of my AngularJS ui-router application?

My AngularJS SPA application utilizes angular-ui-router. Normally, the application starts when the user visits: (a) www.example.com and then automatically loads the index.html page. At this point, I want the application to directly transition to the home ...

Dependencies in AngularJS factories

I'm currently using AngularJS to extract data from mongodb. I have been attempting to utilize a factory to retrieve this information through the $http method. Despite researching and trying numerous approaches, none seem to work for me. In addition t ...

Blur the AngularJS button after it is clicked

Currently, I am utilizing AngularJS within a Salesforce setup. One of the functionalities involves a button that triggers several automations in Salesforce upon being clicked, which works perfectly fine. However, the automation process takes approximately ...

Unable to retrieve the width of an `element` using Angular's built-in jQuery method

I'm attempting to retrieve the width of an element using the AngularJS link method, but I'm not seeing the expected result. Here's my code: var myApp = angular.module("myApp", ['ngResource']); myApp.factory("server", function($r ...

JHipster's Advanced Master-Detail User Interface

Can a master-detail form be created in JHipster? I have successfully generated two entities: Order Item (with many-to-one relationship to Order) Now, I am looking for a way to include CRUD operations for Items within the Order form. Any suggestions or ...

Angular-ui does not support the ng-disable directive

<h3 class="pulse-green-text"><span class="icon ico_pulse_download"></span>VPN Certificate</h3> <div class="vpn-cert" ng-controller="vpnController vpnCert"> <form method="post" name="userform" class="form-horizontal" id="u ...

angularjs - the mysterious disappearance of $route.parent

Is there a way to achieve similar behavior as shown in this fiddle http://jsfiddle.net/W2C45/6/? I am encountering an error when trying to call $route.parent(this); The error message reads: TypeError: Object # has no method 'parent' I suspect ...

Issue: Module 'socket.io' not found while attempting to push changes via git

I've been attempting to upload a project onto a dokku server using the command below. git push dokku master However, during the upload process, I encountered the following error: -----> Running pre-flight checks For smoother zero downtime deplo ...

The syntax of AngularJS directives

Apologies for my lack of experience with this question :) I am working on displaying a progress bar in AngularJS using UI Bootstrap. The directive works perfectly when the value is hardcoded: <progress percent="67"></progress> However, I en ...

Angular facilitates the seamless uploading of files to S3

Utilizing this particular plugin Alright, so here's the issue I'm facing: I have been able to generate a signed S3 URL on my server and successfully upload a file using the following method: How it used to work: shell curl -T file.jpg http:// ...

Utilize the directive method within the transcluded content by making a call

Trying to call a method within a directive from transcluded content. The structure of my HTML is: <typeahead class="typeahead" model="customers" filtered-model="customersfiltered" ng-model="selectedcustomer"> <ul> <li ng-click="select ...

Utilizing Vue Cli's Webpack Proxy feature

While working on a project using the vue-cli and the Webpack template, I am facing some difficulties with setting up a custom host. Currently, Webpack is listening to localhost:8080, but I need it to work with a custom domain like . Has anyone found a solu ...

"An issue has been identified where the ui.bootstrap.accordion component is not functioning correctly

I struggled to implement the accordion feature from https://angular-ui.github.io/bootstrap/#!#accordion. After countless attempts with bootstrap version 4.0.0, I switched to 3.0.0 and finally achieved the desired results. Version 4 displayed only a clickab ...

Encountering Issue Following Attempt to Upgrade to Newest NPM Release

I attempted to upgrade NPM using the command below: sudo npm install -g npm@latest However, instead of updating NPM successfully, I now encounter an error every time I try to execute a Node-related command: SyntaxError: Block-scoped declarations (let, c ...

Having difficulty installing TypeScript on my machine

https://i.stack.imgur.com/l6COf.pngHaving trouble installing TypeScript with the following error: npm WARN registry Using outdated package data from https://registry.npmjs.org/ due to an error during revalidation. npm ERR! code E500 npm ERR! 500 Interna ...

Instructions for setting a default value for ng-options when dealing with nested JSON data in AngularJS

I need help setting a default value for my ng-options using ng-init and ng-model with dependent dropdowns. Here is an example of my code: <select id="country" ng-model="statessource" ng-disabled="!type2" ng-options="country for (country, states) in c ...

Combining server-side and client-side routing in AngularJS: A comprehensive guide

Currently, I am in the process of transitioning a project to an Angular-based Single Page Application (SPA). The project is originally built using node/locomotivejs and serves templates from the server side. Due to its large size, we are converting it to A ...

Navigating from the root view to a (grand)child view with Angular2: Mastering Direct Links

I am currently exploring Angular 2 and have encountered a perplexing issue that I need assistance in debugging. An Illustrative Scenario In my project, I have an AppComponent that manages the fundamental level routing. Each subsequent level of routing is ...