|
2 | 2 |
|
3 | 3 | The intlify core module for i18n
|
4 | 4 |
|
| 5 | +## Which dist file to use? |
| 6 | + |
| 7 | +### From CDN or without a Bundler |
| 8 | + |
| 9 | +- **`core(.runtime).global(.prod).js`**: |
| 10 | + - For direct use via `<script src="...">` in the browser. Exposes the `IntlifyCore` global |
| 11 | + - Note that global builds are not [UMD](https://github.com/umdjs/umd) builds. They are built as [IIFEs](https://developer.mozilla.org/en-US/docs/Glossary/IIFE) and is only meant for direct use via `<script src="...">` |
| 12 | + - In-browser locale messages compilation: |
| 13 | + - **`core.global.js`** is the "full" build that includes both the compiler and the runtime so it supports compiling locale messages on the fly |
| 14 | + - **`core.runtime.global.js`** contains only the runtime and requires locale messages to be pre-compiled during a build step |
| 15 | + - Inlines internal the bellow packages - i.e. it’s a single file with no dependencies on other files. This means you **must** import everything from this file and this file only to ensure you are getting the same instance of code |
| 16 | + - `@intlify/shared` |
| 17 | + - `@intlify/message-resolver` |
| 18 | + - `@intlify/message-compiler` |
| 19 | + - Contains hard-coded prod/dev branches, and the prod build is pre-minified. Use the `*.prod.js` files for production |
| 20 | + |
| 21 | +- **`core(.runtime).esm-browser(.prod).js`**: |
| 22 | + - For usage via native ES modules imports (in browser via `<script type="module">`) |
| 23 | + - Shares the same runtime compilation, dependency inlining and hard-coded prod/dev behavior with the global build |
| 24 | + |
| 25 | +### With a Bundler |
| 26 | + |
| 27 | +- **`core(.runtime).esm-bundler.js`**: |
| 28 | + - For use with bundlers like `webpack`, `rollup` and `parcel` |
| 29 | + - Leaves prod/dev branches with `process.env.NODE_ENV` guards (must be replaced by bundler) |
| 30 | + - Does not ship minified builds (to be done together with the rest of the code after bundling) |
| 31 | + - Imports dependencies (e.g. `@intlify/message-compiler`, `@intlify/message-resolver`) |
| 32 | + - Imported dependencies are also `esm-bundler` builds and will in turn import their dependencies (e.g. `@intlify/message-compiler` imports `@intlify/shared`) |
| 33 | + - This means you **can** install/import these deps individually without ending up with different instances of these dependencies, but you must make sure they all resolve to the same version |
| 34 | + - In-browser locale messages compilation: |
| 35 | + - **`core.runtime.esm-bundler.js` (default)** is runtime only, and requires all locale messages to be pre-compiled. This is the default entry for bundlers (via `module` field in `package.json`) because when using a bundler templates are typically pre-compiled (e.g. in `*.json` files) |
| 36 | + - **`core.esm-bundler.js`**: includes the runtime compiler. Use this if you are using a bundler but still want locale messages compilation (e.g. templates via inline JavaScript strings) |
| 37 | + |
| 38 | +### For Node.js (Server-Side) |
| 39 | + |
| 40 | +- **`core.cjs(.prod).js`**: |
| 41 | + - For use in Node.js via `require()` |
| 42 | + - If you bundle your app with webpack with `target: 'node'` and properly externalize `@intlify/core`, this is the build that will be loaded |
| 43 | + - The dev/prod files are pre-built, but the appropriate file is automatically required based on `process.env.NODE_ENV` |
| 44 | + |
5 | 45 | ## :copyright: License
|
6 | 46 |
|
7 | 47 | [MIT](http://opensource.org/licenses/MIT)
|
0 commit comments