gatsby-plugin-emotion
Version:
Gatsby plugin to add support for Emotion
37 lines (36 loc) • 2.34 kB
JavaScript
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.onCreateBabelConfig = void 0;
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var onCreateBabelConfig = function onCreateBabelConfig(_ref, pluginOptions) {
var actions = _ref.actions,
store = _ref.store;
if (store.getState().config.jsxRuntime === "automatic") {
actions.setBabelPlugin({
name: require.resolve("@emotion/babel-plugin"),
options: (0, _extends2.default)({
sourceMap: process.env.NODE_ENV !== "production",
autoLabel: "dev-only"
}, pluginOptions ? pluginOptions : {})
});
} else {
actions.setBabelPreset({
name: require.resolve("@emotion/babel-preset-css-prop"),
options: (0, _extends2.default)({
sourceMap: process.env.NODE_ENV !== "production",
autoLabel: "dev-only"
}, pluginOptions ? pluginOptions : {})
});
}
};
exports.onCreateBabelConfig = onCreateBabelConfig;
exports.pluginOptionsSchema = function (_ref2) {
var Joi = _ref2.Joi;
return 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.string().default("dev-only").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 @emotion/babel-plugin's docs: https://emotion.sh/docs/@emotion/babel-plugin#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/react\u2019s jsx function work for all jsx. If you are not doing so and you do not want such optimizations to occur, disable this option.")
});
};