![]() For Typescript 1.x try adding 'allowSyntheticDefaultImports': true in compilerOptions in your tsconfig. For Typescript 2.x try adding 'moduleResolution': 'node' in compilerOptions in your tsconfig.json file. ![]() That said, I think that's an okay tradeoff. Note: If you have trouble importing moment. The main con I see with this is that anybody using UMD bundles would need to include additional script tags with all dependencies from other sources, e.g:, and that these would not be tree shaked, thus requiring larger bundles. Package.json should contain all dependencies listed in externals as dependencies, and not devDependencies or peerDependencies. Thus, I imagine my file to look like this: const path = require("path") Ĭonst. Use it by default when building or interacting with APIs, communicating times over a wire, etc. Luxon can parse a wide range of them, but provides direct support for formatting only a few of them: Generally, you'll want the first one. In my mind, the library should avoid including any external dependencies, since these risk being duplicated by the library user's application if they were to use the same dependencies. ISO 8601 is the most widely used set of string formats for dates and times. React should go into rollupOptions.external, since it requires a single React instance is run in the application. I'm also wary of the final bundle size of the user's application. ![]() Example var changeddate moment().format() Output Note that when you use only the format method, it displays current Date and Time as shown above. Install via NPM npm install moment Import and use in your Typescript file const moment require('moment') let now moment (). Let's say I'm building a library with a few dependencies: react, moment, lodash, and uuid, and I want to distribute this in both ES and UMD format. moment ().format () moment ().format (String) Observe the following examples to gain a better understanding on displaying date using the format method. As of version 2.13.0, Moment includes a typescript definition file.
0 Comments
Leave a Reply. |