I would like to know with the current build system of ionic 2 how would we include third party libs made with ES5, here’s the example:
I want to use moment.js inside a component, but the code is in ES5, how do i include it in my component?
I saw something like this:
import * as moment from ‘moment’;
This doesn’t breaks but it doesn’t expose the api as the docs show them to us, maybe including the script in the index.html with a script tag? but then what happens when you compile, will that file in node_modules be still avaliable?
The “correct” way to handle it (if you’re working with a ts app) is to include a relevant d.ts file in the build path. You can find moment.js’s d.ts file here. If you’re wanting to keep files like this out of your VCS you can use the tsd but it adds yet another package management system. If you’re just needing the one package pulling it down may be easier.
Once you have it in your workspace, add it to your tsconfig.json file in the files section like this:
A d.ts file provides typescript typing information to the js files- basically it lets the ts compiler know how to work with the file. In general you can leave it off but you won’t get intellisense and you will see ts build errors, but the application /probably/ still includes the file.