Security News
The Risks of Misguided Research in Supply Chain Security
Snyk's use of malicious npm packages for research raises ethical concerns, highlighting risks in public deployment, data exfiltration, and unauthorized testing.
babel-plugin-bundled-import-meta
Advanced tools
Babel plugin to rewrite import.meta for bundled usage
Babel plugin to rewrite import.meta.url for use in bundles.
This module requires node.js 8 or above and @babel/core
.
npm i babel-plugin-bundled-import-meta
Add bundled-import-meta
to plugins
in your babel settings.
{
"plugins": [
["bundled-import-meta", {
"mappings": {
"node_modules": "/assets"
},
"bundleDir": "html"
}]
]
}
This example will assume that html/
will directly contain the bundled JavaScript.
node_modules/
served from /assets
. Any use of import.meta
outside these
two folders will throw an exception.
If no mappings match it is assumed that bundleDir
is served from the same directory
as the output bundle. In the example where bundleDir is set to html
it is assumed
that assets in html/components
will be published in ./components
relative to the
bundled JavaScript.
Default process.cwd()
.
This maps source paths to server URL's. Key's represent local source paths, values represent base URL which would be used for the unbundled build. Value URL's can be relative or absolute. Relative URL's will be resolved at runtime using the bundle URL as the base URL.
Default {}
.
It's necessary to know the full URL of the bundle as loaded by the browser. The best way to determine this is different based on what type of bundle will be used.
Supported styles are: amd
, cjs
, esm
, iife
, umd
, system
. Default esm
.
The esm
import style generates import.meta.url
to detect the bundled URL. This
is not compatible with webpack so use another method. If anyone knows of a 'best'
option for use with webpack please open an issue or PR.
When bundling with rollup you should generally use esm
here. The only exception is
if rollup is generating an esm
bundle for targets that do not support
import.meta.url
. If you are using import.meta.url
in your code but must maintain
compatibility with browsers that do not support this it is probably best to have rollup
generate a different bundle format.
See rollup-demo for a mock package showing use of this plugin with rollup.
Tests are provided by xo and ava.
npm install
npm test
This module is based on code found in polymer-build.
babel-plugin-bundled-import-meta
for enterpriseAvailable as part of the Tidelift Subscription.
The maintainers of babel-plugin-bundled-import-meta
and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source dependencies you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact dependencies you use. Learn more.
FAQs
Babel plugin to rewrite import.meta for bundled usage
The npm package babel-plugin-bundled-import-meta receives a total of 8,736 weekly downloads. As such, babel-plugin-bundled-import-meta popularity was classified as popular.
We found that babel-plugin-bundled-import-meta 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
Snyk's use of malicious npm packages for research raises ethical concerns, highlighting risks in public deployment, data exfiltration, and unauthorized testing.
Research
Security News
Socket researchers found several malicious npm packages typosquatting Chalk and Chokidar, targeting Node.js developers with kill switches and data theft.
Security News
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.