Skip to content

Commit

Permalink
fix: rm rollup for core, reduce @types/react version
Browse files Browse the repository at this point in the history
fix docs to exclude core
  • Loading branch information
Long Ho committed Aug 6, 2019
1 parent 223d2cf commit 336d365
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 32 deletions.
2 changes: 1 addition & 1 deletion docs/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ There are a few API layers that React Intl provides and is built on. When using
- [ECMAScript Internationalization API](#ecmascript-internationalization-api)
- [FormatJS Internationalization Formatters](#formatjs-internationalization-formatters)
- [React Intl API](#react-intl-api)
- [`defineMessages`](#definemessages)
- [`defineMessages`](#definemessages)
- [Injection API](#injection-api)
- [`useIntl` hook (currently available in 3.0.0 beta)](#useintl-hook-currently-available-in-300-beta)
- [`injectIntl` HOC](#injectintl-hoc)
Expand Down
18 changes: 4 additions & 14 deletions docs/Advanced-Usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,15 @@

<!-- toc -->

- [Core `react-intl` & pre-parsing messages](#core-react-intl--pre-parsing-messages)
- [Pre-parsing messages](#core-react-intl--pre-parsing-messages)
- [Caveats](#caveats)
- [Imperative APIs](#imperative-apis)

<!-- tocstop -->

## Core `react-intl` & pre-parsing messages
## Pre-parsing messages

We've also provided a core package that has the same API as the full `react-intl` package but without our parser. What this means is that you would have to pre-parse all messages into `AST` using [`intl-messageformat-parser`](https://www.npmjs.com/package/intl-messageformat-parser) and pass that into `IntlProvider`.

This is especially faster since it saves us time parsing `string` into `AST`. The use cases for this support are:
You can also pre-parse all messages into `AST` using [`intl-messageformat-parser`](https://www.npmjs.com/package/intl-messageformat-parser) and pass that into `IntlProvider`. This is especially faster since it saves us time parsing `string` into `AST`. The use cases for this support are:

1. Server-side rendering or pre-parsing where you can cache the AST and don't have to pay compilation costs multiple time.
2. Desktop apps using Electron or CEF where you can preload/precompile things in advanced before runtime.
Expand All @@ -31,7 +29,7 @@ const messages = {

// During runtime
// ES6 import
import {IntlProvider, FormattedMessage} from 'react-intl/core';
import {IntlProvider, FormattedMessage} from 'react-intl';
import * as ReactDOM from 'react-dom';

ReactDOM.render(
Expand All @@ -41,18 +39,10 @@ ReactDOM.render(
); // will render `hello world`
```

The package size is also roughly 30% smaller:

| Package | Minified Size | Minzipped Size |
| ----------------- | ------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------- |
| `react-intl` | ![minified size](https://badgen.net/badgesize/normal/https://unpkg.com/react-intl@next/dist/react-intl.min.js) | ![minzipped size](https://badgen.net/badgesize/gzip/https://unpkg.com/react-intl@next/dist/react-intl.min.js) |
| `react-intl/core` | ![core min size](https://badgen.net/badgesize/normal/https://unpkg.com/react-intl@next/dist/react-intl-core.min.js) | ![core minzipped size](https://badgen.net/badgesize/gzip/https://unpkg.com/react-intl@next/dist/react-intl-core.min.js) |

### Caveats

- Since this approach uses `AST` as the data source, changes to `intl-messageformat-parser`'s `AST` will require cache invalidation
- `AST` is also larger in size than regular `string` messages but can be efficiently compressed
- Since `react-intl/core` does not have a parser, it will not be able to process string-based `defaultMessage` (will render the string as is w/o any token value replacement).

## Imperative APIs

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"@formatjs/intl-relativetimeformat": "^2.5.0",
"@types/hoist-non-react-statics": "^3.3.1",
"@types/invariant": "^2.2.30",
"@types/react": "^16.8.24",
"@types/react": "^16.0.0",
"hoist-non-react-statics": "^3.3.0",
"intl-format-cache": "^4.1.4",
"intl-locales-supported": "^1.4.2",
Expand Down
16 changes: 0 additions & 16 deletions rollup.config.dist.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,20 +52,4 @@ export default [
external: ['react'],
plugins,
},
{
input: p.resolve('lib/core.js'),
output: {
file: p.resolve(`dist/react-intl-core.${isProduction ? 'min.js' : 'js'}`),
format: 'umd',
name: 'ReactIntl',
banner: copyright,
exports: 'named',
sourcemap: true,
globals: {
react: 'React',
},
},
external: ['react'],
plugins,
},
];

0 comments on commit 336d365

Please sign in to comment.