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 moduleexports = 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"runtime:calc/divide";
will be transformed to (webpack bundles output)
var main = "default";var util = ;var add = "add";var Mynav = "Nav";var Banner = "Banner";; __my_require__;