Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

TypeScript Emotion Plugin .https://emotion.sh/

License

NotificationsYou must be signed in to change notification settings

LeetCode-OpenSource/emotion-ts-plugin

Repository files navigation

CircleCIcodecovDownloads

Features

Feature/SyntaxNativeBabel PluginTypeScript PluginNotes
css``
css(...)Generally used for object styles.
styled('div')`` syntaxBoth string and object styles work without this plugin.
styled.div`` syntaxSupporting the shortcut syntax without the Babel plugin requires a large list of valid elements to be included in the bundle.
components as selectorsAllows an emotion component to beused as a CSS selector.
Minification⛔️Any leading/trailing space between properties in yourcss andstyled blocks is removed. This can reduce the size of your final bundle.
Dead Code EliminationUglifyjs will use the injected/*#__PURE__*/ flag comments to mark yourcss andstyled blocks as candidates for dead code elimination.
Source MapsWhen enabled, navigate directly to the style declaration in your javascript file.
Contextual Class NamesGenerated class names include the name of the variable or component they were defined in.

Usage

const{ join}=require('path')constMiniCssExtractPlugin=require('mini-css-extract-plugin')constHtmlWebpackPlugin=require('html-webpack-plugin')const{ createEmotionPlugin}=require('emotion-ts-plugin')module.exports={entry:'./tests/fixtures/simple.tsx',output:{filename:'[name].[hash].js',path:join(process.cwd(),'dist'),},resolve:{extensions:['.tsx','.ts','.js','.jsx'],},mode:'development',devtool:'cheap-module-source-map',module:{rules:[{test:/\.(j|t)sx?$/,loader:'ts-loader',options:{transpileOnly:true,getCustomTransformers:()=>({before:[createEmotionPlugin({// <------------------- heresourcemap:true,autoLabel:true,labelFormat:'[local]',// if the jsxFactory is set, should we auto insert the import statementautoInject:true,// set for react@17 new jsx runtime// only effect if `autoInject` is true// set it in createEmotionPlugin options rather than in `tsconfig.json` will generate more optimized codes:// import { jsx } from 'react/jsx-runtime' for files not using emotion// import { jsx } from '@emotion/react/jsx-runtime' for files using emotionjsxImportSource:'@emotion/react',}),],}),compilerOptions:{// set jsx pragma to jsx or alias which is from the@emotion/react package to enable css property in jsx componentjsxFactory:'jsx',},},exclude:/node_modules/,},{test:/\.css$/,use:[MiniCssExtractPlugin.loader,'css-loader?minimize'],},],},plugins:[newHtmlWebpackPlugin({template:join(process.cwd(),'tests','fixtures','index.html'),}),],}

for customized exported(re-exported) styled

interfaceCustomModule{// module name used in import statementmoduleName:string// `true` if you may import libs from 'my-emotion/subpath'includesSubPath?:boolean// all available names exported from custom moduleexportedNames:string[]// we may do some additional work on styled function, so if styled is reexport, you should specify it herestyledName?:string// has default exporthasDefaultExport?:boolean}createEmotionPlugin({  ...otherConfig,customModules:[{moduleName:'my-emotion',includesSubPath:true,exportedNames:['myStyled','myCss']styledName:'myStyled',}]})

About

TypeScript Emotion Plugin .https://emotion.sh/

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp