Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Import angularjs minified version

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?

like image 710
Rashad Ibrahimov Avatar asked Nov 20 '25 13:11

Rashad Ibrahimov


1 Answers

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';
like image 95
Rashad Ibrahimov Avatar answered Nov 22 '25 04:11

Rashad Ibrahimov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!