angular.js loaded instead of angular.min.js with requirejs
NickName:Daniel Ask DateTime:2015-06-16T19:26:01

angular.js loaded instead of angular.min.js with requirejs

I'm using Webjars to import AngularJS into my web project. For some reason the minified version of AngularJS won't be served even though I'm referencing those in my main. I was expecting to see angular.min.js and angular-route.min.js being loaded, but I'm seeing the regular angular.js and angular-route.js. What am I doing wrong here?

My main.js:

'use strict';

requirejs.config({
  paths: {
    'angular': '../lib/angularjs/angular.min',
    'angular-route': '../lib/angularjs/angular-route.min',
    'async': '../lib/requirejs-plugins/src/async'
  },
  shim: {
    'angular': {
      exports : 'angular'
    },
    'angular-route': {
      deps: ['angular'],
      exports : 'angular'
    }
  }
});

require(['angular', './controllers', './directives', './filters', './services', 'angular-route','./places-autocomplete','async','./gmaps'],
    function(angular, controllers) {
        initialize();

        // Declare app level module which depends on filters, and services
        angular.module('myApp', ['myApp.filters', 'myApp.services', 'myApp.directives', 'ngRoute']).
        config(['$routeProvider', function($routeProvider) {
            ....
        }]);

        angular.bootstrap(document, ['myApp']);

    });

My html loads requirejs like this:

<script>
   @Html(org.webjars.RequireJS.getSetupJavaScript(routes.WebJarAssets.at("").url))
</script>
<script data-main="@routes.Assets.versioned("javascripts/main.js")"
        src="@routes.WebJarAssets.at(WebJarAssets.locate("require.min.js"))"></script>

and the above requirejs.config snippet resides in main.js

Copyright Notice:Content Author:「Daniel」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/30866230/angular-js-loaded-instead-of-angular-min-js-with-requirejs

Answers
Peter Paul Kiefer 2015-06-17T08:42:50

I looked into the sources of requirejs. Here's what I found:\n\nrequirejs splits each path, you defined in the config object, into its components (i.e. the directories, the filename and the extension). For some reason (node module naming conventions) the last extension is dropped. They do not check if that's a '.js'. Then this path array is used to access a module. Without a plugin rquirejs only handles .js files. It adds a .js if nessecary. \n\nNow you can see what happens in your example. In the first step requirejs drops the .min extension. When it loads the module it joins the path components and adds a .js to the end. Then it loads the full module and not the minified version.\n\nIf you add a .js to your paths, then this .js was dropped and the .min is still there. ",


More about “angular.js loaded instead of angular.min.js with requirejs” related questions

angular.js loaded instead of angular.min.js with requirejs

I'm using Webjars to import AngularJS into my web project. For some reason the minified version of AngularJS won't be served even though I'm referencing those in my main. I was expecting to see an...

Show Detail

How can I develop with the full angular.js but deploy to production with angular.min.js?

When developing webapps with AngularJS and hosting them temporally on my local computer, it's better to use the un-minified angular.js because the minified file has much less useful error messages.

Show Detail

RequireJS: How do I unload previously loaded javascript file? Aka Exclusive Dependancies? Or maybe Reset RequireJS?

I have 2 javascript files that cannot co-exist. If a user click on one button, it loads one js file. If a user clicks another button, it loads the other file. But the last one needs to be unloaded

Show Detail

Angular unable to instantiate module when loaded using RequireJS

There is something really weird going on when I'm using RequireJS with AngularJS. I managed to load all my angular dependencies through RequireJS. I can see those scripts downloaded when I open up ...

Show Detail

RequireJS - Loading an already loaded module

I am trying to use RequireJS to load browser modules and I came into an interesting problem. I have 3 modules named a, b and c having these simple source code: a.js define(['./b', './c'], functi...

Show Detail

Loading Angular from CDN via RequireJS is not injected

In my project I want to use RequireJS and bootstrap my app as follows: requirejs.config({ baseUrl: 'scripts/vendor', paths: { jquery: [ 'https://ajax.googleapis.com/ajax/libs/jquery/1....

Show Detail

Load requirejs library only if it is not loaded on page

I am new in using requirejs(2.1.19). Currently i am developing an app using it. My problem what happens if some user already have requirejs(&lt;2.1.19) on its page. It means two versions of requi...

Show Detail

Using Breeze with RequireJS, Angular is loaded

Using TypeScript, AMD, "requirejs", "breeze" but not "angular", I just upgraded from Breeze 1.4.0 to 1.4.6. Now, when "breeze" is loaded, it also tries to load "angular" which fails with... Module

Show Detail

AngularJS - ngRoute not loaded?

Application code looks like: var myApp = angular.module('myApp', ['ngRoute']); myApp.config(['$routeProvider', function($routeProvider){ $routeProvider. when('/login', { tem

Show Detail

In tests: Make sure all JS is loaded with requirejs

I'm having some problems with our feature specs. I currently suspect requirejs to be the evildoer. It seems that our specs (Rails with capybara-webkit) start running before all JavaScript files are

Show Detail