Exciting release!Introducing "safe npm". Learn more
Socket
Log inDemoInstall

babel-plugin-transform-dynamic-imports-to-static-imports

Package Overview
Dependencies
0
Maintainers
2
Versions
4
Issues
File Explorer

Advanced tools

babel-plugin-transform-dynamic-imports-to-static-imports

transform dynamic import to static imports

    1.0.0latest
    GitHub

Version published
Maintainers
2
Weekly downloads
882
increased by19.35%

Weekly downloads

Changelog

Source

[1.0.0][] - 2021-03-31

  • Declare API stable :tada:
  • Add changelog

Readme

Source

babel-plugin-transform-dynamic-imports-to-static-imports

npm build

A transform to translate dynamic imports to static imports

Installation:

npm install babel-plugin-transform-dynamic-imports-to-static-imports

Usage:

with configuration file:

{ "plugins": ["babel-plugin-transform-dynamic-imports-to-static-imports"] }

Via CLI

babel --plugins babel-plugin-transform-dynamic-imports-to-static-imports script.js

via node API

require("@babel/core").transform("code", { plugins: ["babel-plugin-transform-dynamic-imports-to-static-imports"], });

Example of Transform

input:

import * as zero from "./zero"; import "./one"; async function test() { import("./two"); await import("./three"); import("./four") .then((test) => { /* do something */ }) .then(); await import("./five").then((test) => { /* do something */ }); }

output:

import * as $$1 from "./five"; import * as $$0 from "./four"; import "./three"; import "./two"; import * as zero from "./zero"; import "./one"; async function test() { Promise.resolve($$0) .then((test) => { /* do something */ }) .then(); await Promise.resolve($$1).then((test) => { /* do something */ }); }

for more examples see test.js

Caveat

dynamic imports with dynamic paths do not have a static equivalent.

async function test() { import(`dynamic${test}`); await import(`dynamic${test}`); import(`dynamic${test}`) .then((test) => { /* do something */ }) .then(); await import(`dynamic${test}`).then((test) => { /* do something */ }); }

will output:

async function test() { import(`dynamic${test}`); await import(`dynamic${test}`); import(`dynamic${test}`) .then((test) => { /* do something */ }) .then(); await import(`dynamic${test}`).then((test) => { /* do something */ }); }

for more examples see test.js

Keywords

FAQs

Last updated on 31 Mar 2021

Did you know?

Socket installs a Github app to automatically flag issues on every pull request and report the health of your dependencies. Find out what is inside your node modules and prevent malicious activity before you update the dependencies.

Install Socket
Socket
support@socket.devSocket SOC 2 Logo

Product

  • Package Issues
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc