What is the best way to install and use Lodash for a brand new Ionic v1 project?

I am used to bower and importing the lodash.min.js in index.html from bower_components/ folder. However since bower is deprecated I would like to use the distribution from npm instead but I see no easy way of including lodash.min.js from node_modules without copying it into the www folder and importing it from there…

Is that really the best way or do I need some kind of build system, i.e. gulp, for fetching these files and including them in my app project?

Best regards

npm install lodash --save (will save in your package.json)

in component/service you want to use lodash
import * as _ from ‘lodash’;

Is that possible for a v1 project? I thought you need some kind of build system for those kind of ES6 imports.

Does v1 use webpack?

Nope. Type ionic start --type=ionic1 in your terminal and choose the template sidemenu to see for yourself.

Indeed, so you need to import using AngularJS style:

I’m using Lodash in my ionic v1 project now, and I’d like to share my way with you.
I feel that you don’t need to make an extra use of build system.
First, include the lodash.min.js in your index.html.

<script src="bower_components/lodash/dist/lodash.min.js"></script>

Then, in your app.js

angular.module('app', []) 
...
// Make lodash working in controllers
.constant('_', window._)

.run(function($rootScope) {
  // Make lodash working in views
  $rootScope._ = window._;
});

Hope this helps you.

Hello again! Yes, that would work but I am not talking about using a depdency with bower, but with NPM and no build system. Maybe this is not possible after all.