Import angularjs minified version

2k Views Asked by At

I'm using webpack, angular 1.x and have the following code

import angular from 'angular';

which works good, but the problem is that included file is too big (angularjs - 1.15mb). It will be better of course to use minified version of angularjs, but when I change code to

import angular from 'angular/angular.min.js';

it doesn't work properly, I mean it seems like angular.min.js doesn't export appropriate angular object.

What's the right way to use minified version of library?

2

There are 2 best solutions below

2
Rashad Ibrahimov On BEST ANSWER

I've found github issue regarding the problem, it's good idea to use exports-loader. My solution is:

webpack.config.js

...
// Add alias, so webpack looks for minified version of angular
resolve: {
    alias: {
        angular: "angular/angular.min.js"
    }
}

...
// Add exports loader for angular
modules: {
    loaders: [
        {
            test: /angular\.min\.js$/,
            loader: 'exports?angular'
        }
    ]
}

After this configuration we can easily import minified version of angular using the following command

let angular = require('angular');

// or es6 version

import angular from 'angular';
2
Ansari Milah Ibrahim On

U can use angular cli and just type

ng build -prod

Then your minified file are in dist foldeer. It must be smaller, and u can upload that ini your public_html