Gathering detailed insights and metrics for babel-plugin-optimize-clsx
Gathering detailed insights and metrics for babel-plugin-optimize-clsx
Gathering detailed insights and metrics for babel-plugin-optimize-clsx
Gathering detailed insights and metrics for babel-plugin-optimize-clsx
npm install babel-plugin-optimize-clsx
Typescript
Module System
84.8
Supply Chain
98.7
Quality
75.6
Maintenance
100
Vulnerability
99.6
License
Total Downloads
3,033,324
Last Day
2,853
Last Week
19,634
Last Month
99,564
Last Year
1,021,504
Minified
Minified + Gzipped
Latest Version
2.6.2
Package Id
babel-plugin-optimize-clsx@2.6.2
Size
21.32 kB
Publised On
18 Jun 2021
Cumulative downloads
Total Downloads
Last day
-32.2%
2,853
Compared to previous day
Last week
-19.8%
19,634
Compared to previous week
Last month
9%
99,564
Compared to previous month
Last year
60.6%
1,021,504
Compared to previous year
26
Babel plugin to optimize the use of clsx, classnames, and all libraries with a compatible API
yarn add babel-plugin-optimize-clsx --dev
or
npm install babel-plugin-optimize-clsx --save-dev
Name | Version |
---|---|
Babel | ^7.0.0 |
Node | >=8 |
1clsx({ 2 [classes.disabled]: disabled, 3 [classes.focusVisible]: focusVisible && !disabled, 4}); 5 6// Transforms to 7 8clsx(disabled && classes.disabled, focusVisible && !disabled && classes.focusVisible);
1clsx({ 2 [classes.disabled]: disabled, 3 [classes.focusVisible]: focusVisible && !disabled, 4}); 5 6// Transforms to 7 8clsx(disabled ? classes.disabled : focusVisible && classes.focusVisible);
1clsx({ 2 [classes.focusVisible]: this.state.focusVisible, 3 [focusVisibleClassName]: this.state.focusVisible, 4}); 5 6// Transforms to 7 8clsx(this.state.focusVisible && [classes.focusVisible, focusVisibleClassName]);
1function foo(props) { 2 const { position: p } = props; 3 const x = clsx({ 4 [classes.x]: p === 'top', 5 [classes.y]: p === 'bottom', 6 }); 7} 8 9foo.propTypes = { 10 position: PropTypes.oneOf(['top', 'bottom']), 11}; 12 13// Transforms to 14 15function foo(props) { 16 const { position: p } = props; 17 const x = clsx(p === 'top' ? classes.x : classes.y); 18} 19 20foo.propTypes = { 21 position: PropTypes.oneOf(['top', 'bottom']), 22};
1const x = clsx({ 2 btn: true, 3 'col-md-1': true, 4 ['btn-primary']: true, 5}); 6 7// Transforms to 8 9const x = 'btn col-md-1 btn-primary';
1const x = clsx({ 2 btn: true, 3 'btn-foo': isDisabled, 4 'btn-bar': !isDisabled, 5}); 6 7// Transforms to 8 9const x = 'btn ' + (isDisabled ? 'btn-foo' : 'btn-bar');
Benchmarks can be found in the benchmark
directory
Name | Type | Default value |
---|---|---|
libraries | string[] | ['clsx', 'classnames'] |
By default the plugin looks for import
and require
statements for clsx
and classnames
and uses that to know which function calls to optimize. If you're using another library with a compatible API you can overwrite that with this option.
1{ 2 "plugins": [ 3 [ 4 "babel-plugin-optimize-clsx", 5 { 6 "libraries": ["clsx", "classnames", "my-custom-library"] 7 } 8 ] 9 ] 10}
Name | Type | Default value |
---|---|---|
functionNames | string[] | [] |
If you want the plugin to match on all functions with a specific name, no matter where it comes from you can specify them using this option. An example for this is if you have clsx
as a global function and thus don't import it.
1{ 2 "plugins": [ 3 [ 4 "babel-plugin-optimize-clsx", 5 { 6 "functionNames": ["myClsxImplementation"] 7 } 8 ] 9 ] 10}
Name | Type | Default value |
---|---|---|
removeUnnecessaryCalls | boolean | true |
By default the plugin will remove unnecessary function calls and if all calls are removed, imports. If you need to keep them, you can set this option to false.
Example of some unnecessary calls
1import clsx from 'clsx'; 2const x = clsx('foo', 'bar'); 3const y = clsx({ classA: foo === 'a', classB: foo !== 'a' }); 4const z = clsx({ 5 classA: foo === 'a', 6 classB: foo !== 'a', 7 classC: bar === 'c', 8 classD: bar !== 'c', 9}); 10 11// Transforms to 12 13const x = 'foo bar'; 14const y = foo === 'a' ? 'classA' : 'classB'; 15const z = (foo === 'a' ? 'classA ' : 'classB ') + (bar === 'c' ? 'classC' : 'classD');
Name | Type | Default value |
---|---|---|
collectCalls | boolean | false |
Writes all function calls, before they are optimized, to a file. Used to help test the plugin on repositories.
No vulnerabilities found.
No security vulnerabilities found.