What could be causing the issue with uglify not functioning properly with AngularJS content?

I've created some gulp tasks to assist in building my web project. One of the tasks involves minifying js files. Here is the task code snippet:

gulp.task('minify' , function() {
  console.log('Copy minified js ');
    return gulp.src('dist/www/**/*.js'])
    .pipe(uglify().on('error', function(e){
        console.log(e);
        }))
    .pipe(gulp.dest('dist/www'));
});

When I run the task by using gulp minify, an error is thrown:

{ [Error: E:XXXXXX\dist\tmp\bootstrap.js: SyntaxError: Unexpected token: name (mainModule)]
  message: 'E:XXXXXX\\dist\\tmp\\bootstrap.js: SyntaxError: Unexpected token: name (mainModule)',
  fileName: 'E:XXXXXX\\dist\\bootstrap.js',
  lineNumber: 1,
  stack: 'Error\n    at new JS_Parse_Error (eval at <anonymous> (E:XXXXXX\gfgfgfgf\\gulp-uglify\\node_modules\\uglify-js\\tools\\node.js:28:1), <anonymous>:1534:18)\n    at js_error (eval at <anonymous> (

This is the content of the bootstrap.js file causing the issue:

import mainModule from './src/main';

angular.element(document).ready(function() {
  angular.bootstrap(document, [mainModule.name], { strictDi: true });
});

I need help understanding why this isn't working as expected. Any insights would be greatly appreciated!

Thank you!

Answer №1

If you're looking to minify your Angular components, be sure to include the necessary Angular dependency injection annotation first. Before applying uglify, consider running your code through ng-annotate as a preprocessing step.

Update: It's worth noting that there are compatibility issues when trying to uglify ES6 JavaScript; in such cases, it's recommended to utilize Babel for code transformation before proceeding with uglification.

Hopefully this information proves helpful!

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

What steps should I take to create an object that can be converted into a JSON schema like the one shown here?

I'm facing a rather simple issue, but I believe there's something crucial that I'm overlooking. My objective is to iterate through and add elements to an object in order to generate a JSON structure similar to the following: { "user1": ...

When a Javascript function marked as async is executed, it will return an object

Async function is returning [object Promise] instead of the desired real value. Interestingly, I can see the value in the console log. It seems like this behavior is expected from the function, but I'm unsure how to fix my code. This code snippet is ...

The title of the Electron application remains consistent

My application is being packaged using electron-packager, but it's not changing its name and still displays "Electron." It's supposed to use the productName in my package.json file, but for some reason, it doesn't change. Even after creati ...

Tips for creating modular Angular controllers

Feel free to modify the title as needed. I am familiar with writing controllers in a modular manner. var controllers = {}; controllers.ToDoController = function($scope){ //... }; Alternatively, you can achieve the same results using: var app = angul ...

Struggles with fading in and out

I'm currently working on enhancing a pure CSS rollover with a smooth transition/fade effect, but I'm encountering some difficulties in achieving the desired outcome. The concept involves displaying a new div called "online-hover" when hovering o ...

Is there a way to transfer ngClass logic from the template to the TypeScript file in Angular?

I am implementing dropdown filters for user selection in my Angular application. The logic for adding classes with ngClass is present in the template: <div [ngClass]="i > 2 && 'array-design'"> How can I transfer this ...

Get the maximum width in pixels through JavaScript when it is specified in different units within the CSS

I'm looking to retrieve the max-width value in px from CSS for use in a JavaScript code. The challenge is that this value might be specified in different units in the CSS file. Any suggestions on how to achieve this using JavaScript? const element = ...

Guide to developing a manual tally counter with recorded logs using HTML and JavaScript

I am currently in need of assistance with creating a manual input counter using the App Script Editor. My website design already includes a single input textbox, a reset button, and a disabled box. What I would like to achieve is that when I enter a numb ...

Utilize the HTTP.get function to serve files in the img src attribute

I am facing an issue where my file can only be accessed if I include an x-authentication token in the header of the "GET" http request. Unfortunately, using a cookie is not an option in this case. This means I cannot simply call for the file by its URL in ...

Generating an Array of objects through the use of the each method

Currently, I am in the process of developing a web scraper using node.js along with puppeteer and cheerio. Although I can successfully display the desired strings in the console.log, I am facing challenges in determining if this task is achievable. $(&apo ...

Is it possible to use the same HTML select/dropdown menu for multiple rows in a table?

I am working with an HTML table that usually has between 10-30 rows, each containing a column for "item name". The drop down menu consists of about 75 products to choose from. In order to reduce the page size, I want to use a single drop down list for all ...

Using Vue.js to process JSON data

My issue lies within this JSON data. I am trying to consume only the first element of the array using Vue.js 2 in order to display it. I was able to achieve this successfully using the console, but not with Vue.js. This line of code in the console works: ...

Facing the issue of "Protractor not syncing with the page" while trying to navigate an Angular website

I'm currently attempting to follow the tutorial for Protractor on the official Protractor website, but I've hit a roadblock at step 0. My setup involves using protractor and webdriver-manager version 6.0.0. I am running Linux (Ubuntu 18.06) as m ...

Console command to change paragraph tag color---Modifying the color

I am attempting to change the color of all paragraph tags on a webpage to white by utilizing the console. My initial attempt was: document.p.style.color = 'white'; However, this method did not have the desired effect. Interestingly, I have had s ...

Detect keypress within a BrowserWindow even when multiple BrowserView components are present

In my Electron application, I have a main BrowserWindow that contains the main user interface index.html, along with multiple BrowserView elements: browserWindow = new BrowserWindow({ width: width, height: height, frame: false }); browserWindow.webContents ...

Navigating the json return values within an angular.js action success callback can be achieved through the following

Attempting to perform a POST request with angular.js resources and implementing success and error callbacks. wbsModule.factory('gridData', function($resource) { //define resource class var root = {{ root.pk }}; var csrf = '{{ cs ...

Is there a more effective method for detecting changes in a class variable in JavaScript, aside from using setInterval()?

Is there a more readable way to monitor changes of a class variable from its instance? Although I can use setInterval() to achieve this, the code becomes quite difficult to read. let calibrator = new Calibrator("hardwareName"); calibrator.connect(); let ...

Issue with mapStateToProps not reflecting changes in props after localStorage modification

Currently, I am working on a redux application that involves authentication. My main concern right now is ensuring that the user remains logged in whenever they interact with the app. Below is a snippet from the bottom of my App.jsx file: function mapStat ...

Having trouble with ui-sref functionality within a Bootstrap dropdown menu

In the header.html file, I have the following angular code: <div id="navbar" class="navbar-collapse collapse"> <ul class="nav navbar-nav navbar-right"> &l ...

Working with MySQL in Node.js using async/await

Struggling with utilizing async/await in Node.js with MySQL as it consistently returns an undefined value. Can someone shed light on what could be causing this issue? See my code snippet below. const mysql = require('promise-mysql'); var co ...