Security News
Input Validation Vulnerabilities Dominate MITRE's 2024 CWE Top 25 List
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
babel-plugin-async-import
Advanced tools
Platform-agnostic asynchronous imports
import React, { Suspense } from 'react';
export default function LazyContainer({ name, ...props }) {
const LazyComponent = React.lazy(() => import(`./pages/${name}`));
return (
<Suspense fallback="Loading...">
<LazyComponent {...props} />
</Suspense>
);
}
module.exports = {
plugins: [
// Default options
['async-import', {
// browser: 'import(REQUEST)',
// node: 'Promise.resolve(require(REQUEST))'
}],
// Common template
['async-import', {
template: 'myCustomImport(REQUEST)'
}],
]
};
Use BABEL_TARGET
to choose the output template:
BABEL_TARGET=browser babel src --copy-files --out-dir dist
BABEL_TARGET=node babel src --copy-files --out-dir dist
Consider a simple application with the following structure:
App
├── Page1
├── Page2
├── Page3
└── Page4
Bundling with webpack yields:
# static import
main.dfdad3d5930fe00fd037.js 526 kB 0 [emitted] [big] main
# require.ensure
chunk.0.6440f6c153085827a48b.js 24.3 kB 0 [emitted]
main.943ecc70fec31c6444f4.js 503 kB 1 [emitted] [big] main
# async import
chunk.0.9491e6c24e3b87d1d63f.js 12.9 kB 0 [emitted]
chunk.1.f37226ca0aefdcb8b991.js 3.7 kB 1 [emitted]
chunk.2.84348279875f5fba6e99.js 3.74 kB 2 [emitted]
chunk.3.c7cdc567dea9bd59569a.js 3.71 kB 3 [emitted]
main.058200e44cf45d9723b4.js 503 kB 4 [emitted] [big] main
FAQs
Platform-agnostic asynchronous imports
The npm package babel-plugin-async-import receives a total of 183 weekly downloads. As such, babel-plugin-async-import popularity was classified as not popular.
We found that babel-plugin-async-import demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.