频道
bg

Emotion Babel

coding十月 15, 20221mins
Frontend Babel

.babelrcH2

"emotion" must be the first plugin in your babel config plugins list.

bash

{
"plugins": ["@emotion"]
}

@emotion 会使用@emotion/babel-plugin

而之前的emotion 会使用[babel-plugin-emotion](https://www.npmjs.com/package/babel-plugin-emotion)

可能是根据plugin返回的name匹配的

bash

export default function (babel: *, options: *) {
if (
options.autoLabel !== undefined &&
!AUTO_LABEL_VALUES.includes(options.autoLabel)
) {
throw new Error(
`The 'autoLabel' option must be undefined, or one of the following: ${AUTO_LABEL_VALUES.map(
s => `"${s}"`
).join(', ')}`
)
}
let t = babel.types
return {
name: '@emotion',
inherits: syntaxJsx,
visitor: ...

但是babel官方的手册是根据包名匹配的,推测是出了包名,还有其他的规则,例如@emotion 会找@emotion/babel-plugin

bash

const EXACT_RE = /^module:/;
const BABEL_PLUGIN_PREFIX_RE = /^(?!@|module:|[^/]+\/|babel-plugin-)/;
const BABEL_PRESET_PREFIX_RE = /^(?!@|module:|[^/]+\/|babel-preset-)/;
const BABEL_PLUGIN_ORG_RE = /^(@babel\/)(?!plugin-|[^/]+\/)/;
const BABEL_PRESET_ORG_RE = /^(@babel\/)(?!preset-|[^/]+\/)/;
const OTHER_PLUGIN_ORG_RE = /^(@(?!babel\/)[^/]+\/)(?![^/]*babel-plugin(?:-|\/|$)|[^/]+\/)/;
const OTHER_PRESET_ORG_RE = /^(@(?!babel\/)[^/]+\/)(?![^/]*babel-preset(?:-|\/|$)|[^/]+\/)/;
const OTHER_ORG_DEFAULT_RE = /^(@(?!babel$)[^/]+)$/;

评论


新的评论

匹配您的Gravatar头像

Joen Yu

@2022 JoenYu, all rights reserved. Made with love.