Babel Preset Cozy App
What's babel-preset-cozy-app?
A shareable configuration for Cozy Applications or Scripts.
This package is a Babel preset already used by create-cozy-app
.
To install:
yarn add --dev babel-preset-cozy-app
Usage with a Create Cozy App projects
If you started your project using create-cozy-app
, you don't need to do anything, you should already have a .babelrc
configured to used this preset.
Usage with other projects
If you want to use this preset, you first need to have Babel installed (cf documentation).
Then, in a file named .babelrc
(the Babel configuration file), you can use the preset using the following way:
{
"presets": ["cozy-app"]
}
Options
node
(boolean): false
by default
By default, this babel preset targets browsers but you can target node by using the node
option:
{
"presets": [
["cozy-app", {
"node": true
}]
]
}
react
(boolean): true
by default
By default, this babel preset uses the react
preset (babel-preset-react
) but you can disable this behaviour with the react
option to false
as following:
{
"presets": [
["cozy-app", {
"react": false
}]
]
}
transformRegenerator
(boolean): true
by default (for browsers only)
By default, this babel preset uses babel-plugin-transform-runtime
to transform regenerator functions on the runtime. But sometimes (not always) it could break CSPs due to some eval usage so you can disable this behaviour with the transformRegenerator
option to false
as following:
{
"presets": [
["cozy-app", {
"transformRegenerator": false
}]
]
}
Lib option
When the lib option is activated, import/export
nodes are not transpiled. This gives the downstream bundler
the ability to prune unused module away. It works by configuring babel-preset-env with {"modules": false}
.
Advanced
You can have control on the options passed to babel-preset-env
and babel-plugin-transform-runtime
:
presetEnv
will be passed to babel-preset-env
transformRuntime
will be passed to babel-plugin-transform-runtime
{
"presets": [
["cozy-app", {
"presetEnv": { "modules": false },
"transformRuntime": { "helpers": true }
}]
]
}
In this case, we do not want preset-env
to touch to import/export
and want the inlined Babel helpers
to be replaced by imports from babel-runtime
.
See the options on the official docs :
https://babeljs.io/docs/en/babel-preset-env#modules
https://babeljs.io/docs/en/babel-plugin-transform-runtime#helpers
What's Cozy?
Cozy is a platform that brings all your web services in the same private space. With it, your webapps and your devices can share data easily, providing you with a new experience. You can install Cozy on your own hardware where no one's tracking you.
Get in touch
You can reach the Cozy Community by:
License
babel-preset-cozy-app
is distributed under the MIT license.