Skip to content

Transforms import and require statements into ones with packages versions if specified

License

Notifications You must be signed in to change notification settings

klaviyo/babel-plugin-napkin-modules

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

babel-plugin-napkin-modules

Transforms imports:

import moment from 'moment';
import ethers from 'ethers';
const axios = require('axios');

into ones with versions if specified via config:

import moment from 'moment';
import ethers from 'ethers-1.0.1';
const axios = require('axios-5.1.2');

Installation

npm add babel-plugin-napkin-modules

Usage

.babelrc:

{
  "plugins": [
    ["napkin-modules", {
        "modules": {
            "moment": "*",
            "ethers": "1.0.1",
            "axios": "5.1.2"
        }
    }]
  ]
}

transform():

const pluginOptions = {
  modules: {
    moment: '*',
    ethers: '1.0.1',
    axios: '5.1.2'
  }
}

transform(code, {
  presets: [['@babel/preset-env', { modules: false }]],
  plugins: [['babel-plugin-napkin-modules', pluginOptions]]
}).code;

Options

Name Type Required Default Description
modules object yes {} An object with all the modules and corresponding versions, with "*" to represent "latest" where no transform happens

About

Transforms import and require statements into ones with packages versions if specified

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •