UNPKG

2.83 kBMarkdownView Raw
1# `@4c/babel-preset`
2
3A configurable, batteries included, babel preset for libraries and web apps.
4
5Includes the following presets and plugins:
6
7- [preset-env](https://babeljs.io/docs/en/babel-preset-env#modules)
8- [preset-react](https://babeljs.io/docs/en/babel-preset-react)
9- [react-intl](https://github.com/yahoo/babel-plugin-react-intl)
10- [class-properties](https://babeljs.io/docs/en/babel-plugin-syntax-class-properties)
11- [dev-expression](https://www.npmjs.com/package/babel-plugin-dev-expression)
12- [export-extensions](https://babeljs.io/docs/en/babel-plugin-proposal-export-default-from)
13- [optional-chaining](https://babeljs.io/docs/en/babel-plugin-proposal-optional-chaining)
14
15## Install
16
17```sh
18yarn add @4c/babel-preset -D
19```
20
21## Configure
22
23Without options:
24
25```json
26{
27 "presets": ["@4c"]
28}
29```
30
31With options;
32
33```json
34{
35 "presets": [
36 [
37 "@4c",
38 {
39 "target": "web-app",
40 "modules": false,
41 "intl": { "prefix" "@mylib" },
42 }
43 ]
44 ]
45}
46```
47
48## Options
49
50In addition to the options below, all [preset-env](https://babeljs.io/docs/en/babel-preset-env#modules) are
51accepted to be overridden when the defaults aren't sufficient. By default the preset
52picks a set of known safe combinations tailored to the chosen `target`.
53
54### `target`
55
56`'web' | 'web-app' | 'node'`, defaults to `'web'`
57
58The overall build environment target. Used to set some smart presets as well as
59configure the `preset-env` targets.
60
61**node**
62
63- `targets` set to node `10` in production and `current` in development
64- `modules` set to `commonjs`
65- `intl` is disabled
66
67**web**
68
69- `targets` uses the browserlist config is (determined by .browserslistrc, etc) if available or
70 defaults to `['ie >= 11', 'last 2 Edge versions', 'last 4 Chrome versions', 'last 4 Firefox versions', 'last 2 Safari versions'];`
71
72**web-app**
73
74- uses the same targets as `web`
75- defaults `modules` to `false`
76- defaults `runtime` to `true`
77
78### `development`
79
80`boolean`, defaults to `false`
81
82Uses a more development friendly set of `targets` as well as toggles development plugins for react ([see](https://babeljs.io/docs/en/babel-preset-react#development). When `true` the `current` version of node for node targets and
83`esmodules` for web targets. You can read more [here](https://babeljs.io/docs/en/babel-preset-env#targetsesmodules).
84
85### `modules`
86
87`"commonjs' | false`, defaults to `false` except when `target` is `'web-app'` and `'commonjs'` otherwise
88
89The [preset-env](https://babeljs.io/docs/en/babel-preset-env#modules) modules option. controls the output module format
90
91### `runtime`
92
93Turns on the babel runtime transform.
94
95### `intl`
96
97`boolean | { prefix: string, messagesDir: string }`
98
99Configures the `react-intl` babel plugin to extract and output localized strings
100prefixed by the package name or provided `prefix`