Socket
Socket
Sign inDemoInstall

babel-plugin-custom-import

Package Overview
Dependencies
25
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    babel-plugin-custom-import

a babel plugin for ignoring some import syntax


Version published
Weekly downloads
3
increased by200%
Maintainers
1
Install size
4.34 MB
Created
Weekly downloads
 

Readme

Source

babel-plugin-custom-import

Intro

It's a babel plugin to transform the ESM (import) syntax to your own call expression (e.g. __my_require__()) , in order to passby webpack's compiling.

Installation

yarn add -D babel-plugin-custom-import

Usage

webpack config -> babel plugin

// webpack.config.js

module.exports = {
  entry: {
    // ...
  },
  output: {
    // ...
  },
  module: {
    rules: [
      {
        test: /\.js|jsx$/,
        use: {
          loader: "babel-loader",
          options: {
            plugins: [
              // default configuration
              "babel-plugin-custom-import",
              // custom configuration
              [
                "babel-plugin-custom-import",
                {
                  externalScheme: "^runtime:",
                  syncFunc: "__my_require__",
                  asyncFunc: "__my_require__",
                  asyncFuncAttr: "async",
                  isReplaceScheme: true
                }
              ]
            ]
          }
        }
      }
    ]
  }
  // ...
};

Example

Then, source code

import main from "runtime:main";
import * as util from "runtime:util";
import { add } from "runtime:calc";
import { Nav as Mynav, Banner } from "runtime:common/component";
import "runtime:common/reset";

import("runtime:calc/divide").then(divide => {
  alert(divide(3, 2));
});

will be transformed to (webpack bundles output)

var main = __my_require__("main")["default"];
var util = __my_require__("util");
var add = __my_require__("calc")["add"];
var Mynav = __my_require__("common/component")["Nav"];
var Banner = __my_require__("common/component")["Banner"];
__my_require__("common/reset");

__my_require__.async("calc/divide").then(divide => {
  alert(divide(3, 2));
});

Keywords

FAQs

Last updated on 29 Sep 2020

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • 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