Skip to content

Latest commit

 

History

History
113 lines (75 loc) · 3.14 KB

install.md

File metadata and controls

113 lines (75 loc) · 3.14 KB

Install guide

Luxon provides different builds for different JS environments. See below for a link to the right one and instructions on how to use it. Luxon supports all modern platforms, but see the support matrix for additional details.

Basic browser setup

You can also load the files from a CDN.

Just include Luxon in a script tag. You can access its various classes through the luxon global.

<script src="luxon.js"></script>

You may wish to alias the classes you use:

var DateTime = luxon.DateTime;

Node.js

Supports Node.js 6+. Install via NPM:

npm install --save luxon
const { DateTime } = require("luxon");

If you want to work with locales, you need ICU support:

  1. For Node.js 13+, it comes built-in, no action necessary
  2. For older versions of Node.js (only 12 is supported), you need to install it yourself:
    1. Install a build of Node.js with full ICU baked in, such as via nvm: nvm install -s --with-intl=full-icu --download=all or brew: brew install node --with-full-icu
    2. Install the ICU data externally and point Node.js to it. The instructions on how to do that are below.

The instructions for using full-icu as a package are a little confusing. Node.js can't automatically discover that you've installed it, so you need to tell it where to find the data, like this:

npm install full-icu
node --icu-data-dir=./node_modules/full-icu

You can also point to the data with an environment var, like this:

NODE_ICU_DATA="$(pwd)/node_modules/full-icu" node

AMD (System.js, RequireJS, etc)

requirejs(["luxon"], function(luxon) {
  //...
});

ES6

import { DateTime } from "luxon";

Webpack

npm install --save luxon
import { DateTime } from "luxon";

Types

There are third-party typing files for Flow (via flow-typed) and TypeScript (via DefinitelyTyped).

For Flow, use:

flow-typed install luxon

For TypeScript, use:

npm install --save-dev @types/luxon

React Native

React Native >=0.70 works just fine out of the box. Older versions of React Native for Android (or if you disable Hermes) doesn't include Intl support by default, which you need for a lot of Luxon's functionality.

For React Native >=0.60, you should configure the build flavor of jsc in android/app/build.gradle:

-def jscFlavor = 'org.webkit:android-jsc:+'
+def jscFlavor = 'org.webkit:android-jsc-intl:+'

For even older versions of React Native you can use jsc-android-buildscripts to fix it.