简体   繁体   中英

How to parameterize aliased paths in babel's `Module Resolver`?

Using babel-plugin-module-resolver I would like to alias paths using more than one paramters.

I have the following paths:

/foo/components/filename.jsx

/bar/components/filename.jsx

I would like to alias these paths with a single regex in such a way that:

import * from '@foo/filename' ---> import * from '/foo/components/filename'

Namely, @{foldername}/{filename} becomes /{foldername}/components/{filename}

Thank you

You can make configuration in.babelrc file

{ "plugins": [ [ "module-resolver", { "cwd": "babelrc", "root": ["./"], "alias": { "@foo": "./foo/components", "@bar": "./bar/components", } } ] ] }

Just make sure you fill '"root":' where./foo and./bar placed

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM