@noxx/babel-plugin-a2rp
v1.0.1
Published
Converts aliases in Strings to relative paths
Downloads
120
Maintainers
Readme
Babel Plugin - Aliases to Relative Paths
Converts aliases in Strings to relative paths
Install
npm i -D @noxx/babel-plugin-a2rp
Usage
First create aliases that can be utilized by the plugin. The format for the aliases Object are key value pairs where the key is the alias, and value is the actual path that maps to a specific directory.
// aliases.js
const { resolve } = require('path');
const ROOT = resolve(__dirname, './');
const SRC = `${ ROOT }/src`;
module.exports = {
COMPONENTS: `${ SRC }/components`,
SERVER: `${ SRC }/server`,
};
In your babel.config.js
file, add the plugin at the top of the plugins
list
to ensure aliases are replaced and paths are resolved correctly.
const aliases = require('./aliases');
module.exports = (api) => {
api.cache(true);
return {
plugins: [
['@noxx/babel-plugin-a2rp', { aliases }],
// other plugins
],
};
};