在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:per2plex/babel-project-relative-import开源软件地址:https://github.com/per2plex/babel-project-relative-import开源编程语言:JavaScript 100.0%开源软件介绍:Babel Project Relative ImportBabel plugin to transform project relative import paths to file relative import paths.
Highly inspired by babel-root-import.
Tested with babel-cli, babel-loader, grunt-babel and gulp-babel. Does also transform to the same path under Windows. Notice for Webpack usersIf you're using Webpack to bundle your application this plugin may not be needed.
You can use Webpacks's resolve.alias for the same behaviour, which also works
for Upgrade from 1.xThere are two breaking changes:
Example// project/dir/test.js
import Test from '~/otherdir/example.js'
// project/dir/subdir/test.js
import Test from '~/otherdir/subdir/example.js' Will be transformed to: // project/dir/test.js
import Test from './../otherdir/example.js'
// project/dir/subdir/test.js
import Test from './../../otherdir/subdir/example.js' Install
UsageAdd babel-project-root-import to your plugins in your {
"plugins": [
"babel-project-relative-import"
]
} Plugin OptionssourceDirIf all your source files are inside a subdirectory set this option to the path of the subdirectory so paths get resolved correctly. {
"plugins": [
["babel-project-relative-import", {
"sourceDir": "src/"
}]
]
} importPathPrefixIf you want to have a custom prefix which will be used to detect imports, you
can set this option, defaults to {
"plugins": [
["babel-project-relative-import", {
"importPathPrefix": "^"
}]
]
} |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论