How to use babel-plugin-dynamic-import-node - 5 common examples

To help you get started, we’ve selected a few babel-plugin-dynamic-import-node examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github babel / babel / packages / babel-plugin-transform-modules-commonjs / src / index.js View on Github external
export default declare((api, options) => {
  api.assertVersion(7);

  const transformImportCall = createDynamicImportTransform(api);

  const {
    loose,

    // 'true' for non-mjs files to strictly have .default, instead of having
    // destructuring-like behavior for their properties.
    strictNamespace = false,

    // 'true' for mjs files to strictly have .default, instead of having
    // destructuring-like behavior for their properties.
    mjsStrictNamespace = true,
    allowTopLevelThis,
    strict,
    strictMode,
    noInterop,
    lazy = false,
github babel / babel / packages / babel-plugin-transform-modules-systemjs / src / index.js View on Github external
CallExpression(path, state) {
        if (t.isImport(path.node.callee)) {
          if (!this.file.has("@babel/plugin-proposal-dynamic-import")) {
            console.warn(MISSING_PLUGIN_WARNING);
          }

          path.replaceWith(
            t.callExpression(
              t.memberExpression(
                t.identifier(state.contextIdent),
                t.identifier("import"),
              ),
              [getImportSource(t, path.node)],
            ),
          );
        }
      },
github codesandbox / codesandbox-importers / packages / import-utils / src / create-sandbox / utils / extract-requires.ts View on Github external
const walk = require("acorn/dist/walk");

require("acorn-dynamic-import/lib/inject").default(acorn);
require("acorn-jsx/inject")(acorn);
require("acorn-object-spread/inject")(acorn);

const ECMA_VERSION = 2017;

const config = {
  presets: [require("babel-preset-env"), require("babel-preset-react")],
  plugins: [
    require("babel-plugin-transform-async-to-generator"),
    require("babel-plugin-transform-object-rest-spread"),
    require("babel-plugin-transform-class-properties"),
    require("babel-plugin-transform-decorators-legacy").default,
    require("babel-plugin-dynamic-import-node").default
  ]
};

export default function exportRequires(code: string) {
  const requires: string[] = [];
  try {
    const { ast } = babel.transform(code, config);

    if (ast) {
      traverse(ast, {
        enter(path: any) {
          if (
            path.node.type === "CallExpression" &&
            path.node.callee.name === "require" &&
            path.node.arguments[0]
          ) {
github babel / babel / packages / babel-plugin-transform-modules-amd / src / index.js View on Github external
}
        if (!resolveId || !rejectId) {
          resolveId = path.scope.generateUidIdentifier("resolve");
          rejectId = path.scope.generateUidIdentifier("reject");
          state.resolveId = resolveId;
          state.rejectId = rejectId;
        }

        let result = t.identifier("imported");
        if (!noInterop) result = wrapInterop(path, result, "namespace");

        path.replaceWith(
          template.expression.ast`
            new Promise((${resolveId}, ${rejectId}) =>
              ${requireId}(
                [${getImportSource(t, path.node)}],
                imported => ${resolveId}(${result}),
                ${rejectId}
              )
            )`,
        );
      },

babel-plugin-dynamic-import-node

Babel plugin to transpile import() to a deferred require(), for node

MIT
Latest version published 4 years ago

Package Health Score

77 / 100
Full package analysis