一覧へ戻る
cscxj/rollup-plugin-alias(新しいタブで開きます)
主要言語: TypeScript
- star 数
- 2
- watcher 数
- 1
- fork 数
- 0
- issue 数
- 0
- 最終更新
- 2022/08/13
主要言語: TypeScript
Rollup plugin for alias, in order to better serve monorepo.
This is an enhancement to the original rollup-plugin-alias, starting and borrowing from this fork.
This plugin is compatible with all rollup-plugin-alias uses, And allows you to replace aliases based on the path of the importer.
# with npm npm install -D @cxj-npm/rollup-plugin-alias # with yarn yarn add -D @cxj-npm/rollup-plugin-alias # with pnpm pnpm install -D @cxj-npm/rollup-plugin-alias
Please Refer to https://www.npmjs.com/package/@rollup/plugin-alias
On this basis, you can use a function to generate a replacement.
This function is defined as:
(find: string | RegExp, importer: string) => string
在一个monorepo项目中(apps和packages目录下都是repo),我希望使用别名@都指向对应repo的src目录,而不是当前运行的repo的src目录。可以这样做
alias({ entries: [ { find: '@', replacement: (_, importer) => { // importer 是使用别名的文件的绝对路径 const pkgPath = importer.match(/^(.+(apps|packages)\/.+?\/).*/)?.[1] if (!pkgPath) { throw Error('在非项目指定目录下的文件中使用了别名:' + importer) } return path.resolve(__dirname, pkgPath, './src') } } ] })