![Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility](https://cdn.sanity.io/images/cgdhsj6q/production/97774ea8c88cc8f4bed2766c31994ebc38116948-1664x1366.png?w=400&fit=max&auto=format)
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
swc-plugin-transform-cx-jsx
Advanced tools
Having improved performance, this plugin replaces babel-plugin-transform-cx-jsx
.
This is an SWC plugin that transforms JSX code wrapped inside <cx>
tags into plain JavaScript.
Example:
const page = (
<cx>
<div>
<h1>Cx</h1>
<p>Some text</p>
</div>
</cx>
);
becomes
const page = {
type: HtmlElement,
tag: "div",
children: [
{
type: HtmlElement,
tag: "h1",
children: ["Cx"],
},
{
type: HtmlElement,
tag: "p",
children: ["Some text"],
},
],
};
Functional components in CxJS have to be wrapped inside a createFunctionalComponent
call. When transformFunctionalComponents
is set to true
the plugin will automatically add the call for expressions which immediately return a <cx>
block. i.e. (props) => <cx></cx>;
const MySuperTextField = ({label, value}) => <cx>
<TextField value={value} label={label} mod="super" validation-mode="inline" />
</cx>;
becomes
const MySuperTextField = createFunctionalComponent(({label, value}) => <cx>
<TextField value={value} label={label} mod="super" validation-mode="inline" />
</cx>);
Small gains in bundle size can be gained if trimWhitespace
is set to true
. This will remove the whitespace between elements, unless the parent element has the ws
or preserveWhitespace
flag set. Some elements, such as code, should not be touched and this can be addressed using the trimWhitespaceExceptions
configuration parameter.
Example 1
<cx>
<div>
<div />
</div>
</cx>
const page = {
type: HtmlElement,
tag: "div",
children: [
" " //<- This line will be removed
{
type: HtmlElement,
tag: "div",
},
" " //<- This line will be removed
],
};
Example 2
<cx>
<div ws>
<div />
</div>
</cx>
const page = {
type: HtmlElement,
tag: "div",
ws: true,
children: [
" " //<- This line will be preserved because of the ws parameter
{
type: HtmlElement,
tag: "div",
},
" " //<- This line will be preserved because of the ws parameter
],
};
Install the package using the yarn add swc-plugin-transform-cx-jsx
command.
Inside the webpack.config.js
file, import manifest from 'cx/manifest'
- const manifest = require('cx/manifest');
, and replace babel-loader
with swc-loader
(make sure to add it above other SWC plugins):
{
loader: 'swc-loader',
options: {
jsc: {
loose: true,
target: 'es2022',
parser: {
syntax: 'typescript',
decorators: true,
tsx: true,
},
experimental: {
plugins: [
[
require.resolve('swc-plugin-transform-cx-jsx/swc_plugin_transform_cx_jsx_bg.wasm'),
{ trimWhitespace: true, autoImportHtmlElement: true },
],
],
},
transform: {
react: {
pragma: 'VDOM.createElement',
},
},
},
},
}
FAQs
Transpile JSX into Cx config objects.
The npm package swc-plugin-transform-cx-jsx receives a total of 99 weekly downloads. As such, swc-plugin-transform-cx-jsx popularity was classified as not popular.
We found that swc-plugin-transform-cx-jsx demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.