Security News
vlt Debuts New JavaScript Package Manager and Serverless Registry at NodeConf EU
vlt introduced its new package manager and a serverless registry this week, innovating in a space where npm has stagnated.
@babel/plugin-transform-react-pure-annotations
Advanced tools
Mark top-level React method calls as pure for tree shaking
The @babel/plugin-transform-react-pure-annotations package is a Babel plugin designed to enhance optimization for React components by automatically annotating React components with `/*#__PURE__*/` comments. These comments signal to JavaScript bundlers and minifiers, such as Terser, that the component functions can be safely tree-shaken if they are not used. This can lead to smaller bundle sizes in production builds.
Automatic Pure Annotation for Functional Components
Automatically adds pure annotations to functional React components, indicating that they can be safely removed if unused.
Before:
const MyComponent = () => <div>Hello World</div>;
After:
const MyComponent = /*#__PURE__*/() => <div>Hello World</div>;
Automatic Pure Annotation for Class Components
Automatically adds pure annotations to the return value of render methods in class components, aiding in their potential tree-shaking.
Before:
class MyComponent extends React.Component {
render() {
return <div>Hello World</div>;
}
}
After:
class MyComponent extends React.Component {
render() {
return /*#__PURE__*/<div>Hello World</div>;
}
}
Transforms React.createElement calls to object literals. This can improve performance by reducing the overhead of these calls at runtime. However, it does not specifically focus on tree-shaking like @babel/plugin-transform-react-pure-annotations does.
Hoists element creation to the highest scope possible. This can improve performance in React applications by reducing the need to recreate the same elements on each render. While it optimizes performance, its approach is different from adding pure annotations for tree-shaking.
Mark top-level React method calls as pure for tree shaking
See our website @babel/plugin-transform-react-pure-annotations for more information.
Using npm:
npm install --save-dev @babel/plugin-transform-react-pure-annotations
or using yarn:
yarn add @babel/plugin-transform-react-pure-annotations --dev
FAQs
Mark top-level React method calls as pure for tree shaking
We found that @babel/plugin-transform-react-pure-annotations demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 4 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
vlt introduced its new package manager and a serverless registry this week, innovating in a space where npm has stagnated.
Security News
Research
The Socket Research Team uncovered a malicious Python package typosquatting the popular 'fabric' SSH library, silently exfiltrating AWS credentials from unsuspecting developers.
Security News
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.