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');
npm add babel-plugin-napkin-modules
.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;
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 |