Having trouble with Angular minification not properly updating templates?

As a newcomer to angular development, I am currently working on creating components for AEM 6.2 using angular and utilizing gulp to minify the js files for all the components. In my gulpfile, I have set up the following configuration:

var uglify = require('gulp-uglify');
var pump = require('pump');
var gp_concat = require('gulp-concat');
var gp_rename = require('gulp-rename');
var gp_ignore = require('gulp-ignore');
var gp_htmlmin = require('gulp-htmlmin');
var templates = require('gulp-angular-templatecache');

var paths = require('../paths');
var utils = require('../utils');

var base = [
  paths.APP,
  paths.ETC,
  paths.DESIGN
];

gulp.task('minify', function () {
  var filesToInclude = ['**/app/components/**/*.js '];
  var excludeCondition = '**/*.spec*.js'
  return gulp.src(filesToInclude)
    .pipe(gp_ignore.exclude(excludeCondition))
    .pipe(gp_concat('all.concat.js'))
    .pipe(gulp.dest('dist'))
    .pipe(gp_rename('all.min.js'))
    .pipe(plugins.ngAnnotate())
    .pipe(uglify())
    .pipe(gulp.dest('dist'));
});

The minification of the JS files is successful; however, the issue arises in the HTML templates for each component. The references to the controller still use the original controller name instead of the minified one. For example:

<section data-ng-controller="MyController as mc" ng-cloak>
  <div class="mc-name">
    Hi, {{mc.userName}}
  </div>
</section>

Since I am relatively new to Angular development, I am unsure of how the linkage between templates and controllers works in a way that allows the minification process to update all references accordingly. Any guidance on what might be missing would be greatly appreciated. Thank you!

Answer №1

A while back, I encountered a similar issue in AEM 6.1 where there were conflicting versions of minification tools like YUI Compressor causing trouble. I vaguely remember that the version of YUI Compressor in 6.1 was outdated and caused issues which were resolved in version 6.2. It's possible that this conflict is leading to double minification, potentially with different versions of YUI Compressor.

One solution could be to disable minification in AEM and rely solely on Angular minification, but this may lead to AEM clientLibs not being minified as desired.

Another approach could be to let AEM handle the minification instead of using the angular compiler. I believe this is what I ended up doing at the time, although I do recall receiving a hotfix from Adobe daycare for the same issue a couple of years ago. So, it might be worth exploring that option as well.

Answer №2

It is recommended to utilize the controller using vm and injector syntax for better minification

`rmToolkit.controller('QuestionsCtrl', QuestionsCtrl);
 QuestionsCtrl.$inject = ['$scope', '$rootScope', '$stateParams', '$state','Data_Service'];
 function QuestionsCtrl($scope, $rootScope,) {
   var vm = this;
}`

This updated syntax should help resolve any minification issues

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

When activated, JavaScript is producing an undefined response

This is a function with the following designer code. I have made updates to include the latest answer. function OnClientLoBChecked(sender, args) { var ChkBoxLOB = document.getElementById("<%= cbFLoB.ClientID %>"); var ChkBoxDis = document ...

What causes .obj files to not respond to directional light in three.js?

Can anyone explain why the .obj file is not displaying directional light similar to the box? Both have identical materials. You can find the code on GitHub: https://github.com/triple-verge/triple-verge-website/blob/master/src/js/modules/logo-3d.js#L52 H ...

Using Google App Script for Slides to center-align text within a text box

Currently, I am tackling a project that demands the center alignment of text within a textbox on a google slide using a google app script. The primary objective is to fetch text from a google worksheet and an image from google drive. Subsequently, combine ...

Explore the world of textures transferring from Maya to Three.js

I'm looking to convert a Maya model to JavaScript for a simple model with textures. The conversion works fine, but the textures are not showing up. Here is my code: var loader = new THREE.JSONLoader(); loader.load( "models/t2.js", function(geometry) ...

"Maintaining Consistency: Ensuring The First Row is Repeated on Every

When trying to save a PDF using jspdf, I encountered an issue with tables in my HTML. The tables do not have headers, but JsPDF is automatically repeating the first row of the table on every page, causing overlap. I don't want headers on every new pag ...

Aligning container divs at the center in various screen resolutions

I recently constructed a portfolio website using Bootstrap and Isotope JS. In my layout, I have a container div which works perfectly when viewed on a desktop browser - displaying 3 divs in one line. However, the issue arises when the resolution changes an ...

Is it possible to implement PortalVue in multiple Vue.js single file components?

While working on Vue.js (single file components), I have discovered three methods of passing data around: local state/props, store, and utilizing PortalVue. Through my experiments with PortalVue, I successfully implemented both portal and portal-target wit ...

The functionality of d3.dispatch() is not performing as anticipated

Recently, I delved into the world of D3.js to explore its capabilities. One particular concept that caught my attention is d3.dispatch(), and I've been experimenting with it for about a week now. Below is a simple example: <script src="d3.min. ...

Postman: Iterating through requests with various input data sets to dynamically generate the request body

I am facing a challenge with my login API request that requires 3 parameters (userName, password, and remember) in the request body. Out of these parameters, userName and password are mandatory, while remember is optional. The input data is being pulled fr ...

Filtering for Material Autocomplete is limited to the getOptionLabel field

Currently, I am utilizing the Google Material-UI autocomplete component. It is currently only filtering based on the "getOptionLabel" option field when text is entered into the input field. However, I would like the autocomplete to filter based on more tha ...

A guide on extracting the current website URL in a React application

I wanted to find a method to duplicate the text from a URL so that users could easily share the link with others. ...

What is the best approach for creating a test case for a bootstrap-vue modal component

Exploring ways to effectively test the bootstrap vue modal display function. On the project page, the modal toggles its visibility using the toggleModal method triggered by a button click. The modal's display style is switched between 'none' ...

Is there a way to combine multiple incoming WebRTC audio streams into one cohesive stream on a server?

I am currently working on developing an audio-conferencing application for the web that utilizes a WebSocket server to facilitate connections between users and enables streaming of audio. However, I am looking to enhance the system by transforming the serv ...

Is it possible for SqlCommand.ExecuteReader to automatically open the database connection?

Unusual behavior is happening on my website. I have a WCF Data service that provides JSON data to populate a jqGrid using javascript/ajax calls. In addition, there is server-side code that also accesses the same WCF service to retrieve data. Within my WC ...

Adjust the overall size of the CSS baseball field

Attempting to adjust the size of the baseball field proved challenging, as it wasn't a simple task. Is there a way to achieve this effectively? Thanks, HTML - is using DIV the only method for resizing? I couldn't find a way to resize everything a ...

Are 'const' and 'let' interchangeable in Typescript?

Exploring AngularJS 2 and Typescript led me to create something using these technologies as a way to grasp the basics of Typescript. Through various sources, I delved into modules, Typescript concepts, with one particularly interesting topic discussing the ...

Pressing the HTML button will reveal the cart details in a fresh display box

I have been working on setting up a button to display the items in the shopping cart. I have successfully created the cart itself, but now I am facing the challenge of creating a button called showYourCart that will reveal a box containing the cart detai ...

The installation of Protractor using `sudo npm install -g protractor` on Mac resulted

Encountered an error when running sudo npm install -g protractor, seems like the folder/files are missing. Any suggestions on how to resolve this issue? Thank you in advance :) npm ERR! Darwin 15.6.0 npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm ...

Oops! Make sure to call google.charts.load before calling google.charts.setOnLoadCallback to avoid this error

My HTML file includes the following imports: <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script> ...

Tips for displaying a refresh indicator while making an ajax call for refreshing data:

I have successfully implemented jQuery code that refreshes a specific div every 10 seconds without reloading the entire page. However, during this refresh process, the user does not visually perceive any changes happening in the browser. While there are n ...