1.0.1 • Published 3 years ago
import-to-inlined-require-babel-plugin v1.0.1
Import to Inline Require - babel plugin
Used to converted import statements into an inline require statements. Useful when trying to avoid requiring modules that are eventually unused in a particular code path and without using a bundler for tree shaking.
By converting each import statement into it's inlined require statement equivalent your code load only the necessary modules for it's runtime operation.
For example if plugin is applied to the code:
import { mapKeys } from 'lodash'
let myObj = {...}
if (someCondition) {
myObj = mapKeys(myObj, (v, k) => v)
}the output will be
let myObj = {...}
if (someCondition) {
myObj = require('lodash').mapKeys(myObj, (v, k) => v)
}and so lodash module will not be loaded unless someCondition is actually true.
conversion examples
namespace imports
import { namespace } from 'module' const value = namespaceconst value = require('module').namespacerenamed namespace imports
import { namespace as somethingElse } from 'module' const value = namespaceconst value = require('module').namespaceall namespaces imports
import * as allNamespace from 'module' const value = allNamespaceconst value = require('module')default import
import allNamespace from 'module' const value = allNamespaceconst value = require('module').default