Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion packages/gatsby-plugin-emotion/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,25 @@ module.exports = {
{
resolve: `gatsby-plugin-emotion`,
options: {
// Accepts all options defined by `babel-plugin-emotion` plugin.
// Accepts the following options, all of which are defined by `babel-plugin-emotion` plugin.
// The values for each key in this example are the defaults the plugin uses.
`sourceMap`: true,
`autoLabel`: process.env.NODE_ENV !== 'production',
`labelFormat`: `[local]`,
`cssPropOptimization`: true
},
},
],
}
```

## Options

The plugin supports the same options that you can pass into [`babel-plugin-emotion`](https://emotion.sh/docs/babel-plugin-emotion#options).

| Option | Type | Description | Default | Required |
| ------------------- | ------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------- | -------- |
| sourceMap | boolean | Tells the plugin to inject source maps for use in browser dev tools in development. | `true` | |
| autoLabel | boolean | Automatically adds the label property to styles so that class names generated by css or styled include the name of the variable the result is assigned to. You can read more about this option in [`babel-plugin-emotion`'s docs](https://emotion.sh/docs/babel-plugin-emotion#autolabel) | `process.env.NODE_ENV !== 'production'` | |
| labelFormat | string | Only works when `autoLabel` is set to true. It allows you to define the format of the resulting label. The format is defined via string where variable parts are enclosed in square brackets []. For example `labelFormat: "my-classname--[local]"`, where `[local]` will be replaced with the name of the variable the result is assigned to. | "[local]" | |
| cssPropOptimization | boolean | Assumes that you are using something to make `@emotion/core`’s jsx function work for all jsx. If you are not doing so and you do not want such optimizations to occur, disable this option. | `true` | |
24 changes: 24 additions & 0 deletions packages/gatsby-plugin-emotion/src/gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,27 @@ export const onCreateBabelConfig = ({ actions }, pluginOptions) => {
},
})
}

exports.pluginOptionsSchema = ({ Joi }) =>
Joi.object({
sourceMap: Joi.boolean()
.default(true)
.description(
`This option tells the plugin to inject source maps for use in browser dev tools in development.`
),
autoLabel: Joi.boolean()
.default(process.env.NODE_ENV !== `production`)
.description(
`This option automatically adds the label property to styles so that class names generated by css or styled include the name of the variable the result is assigned to. You can read more about this option in babel-plugin-emotion's docs: https://emotion.sh/docs/babel-plugin-emotion#autolabel`
),
labelFormat: Joi.string()
.default(`[local]`)
.description(
`This option only works when autoLabel is set to true. It allows you to define the format of the resulting label. The format is defined via string where variable parts are enclosed in square brackets []. For example labelFormat: "my-classname--[local]", where [local] will be replaced with the name of the variable the result is assigned to.`
),
cssPropOptimization: Joi.boolean()
.default(true)
.description(
`This option assumes that you are using something to make @emotion/core’s jsx function work for all jsx. If you are not doing so and you do not want such optimizations to occur, disable this option.`
),
})