Skip to content

支持 resolve alias #158

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 24, 2021
Merged

支持 resolve alias #158

merged 2 commits into from
Dec 24, 2021

Conversation

nighca
Copy link
Collaborator

@nighca nighca commented Dec 24, 2021

改动

fix #149 build-config 添加配置 resolve.alias,详情如下:

resolve

类型:object

对于模块解析行为的配置,在扩展时会合并原值。

resolve 的字段描述如下:

  • resolve.alias

    类型:object

    配置别名以控制对特定模块或路径的解析行为;如配置 { "foo": "src/foo" },则模块 foo 会被解析到 <项目根目录>/src/foo,模块 foo/bar 会被解析到 <项目根目录>/src/foo/bar

    resolve.alias 的字段描述如下:

    • resolve.alias.(.*)

      类型:string

      解析目标的路径(相对于项目根目录),如 "src/foo"

场景

常见的场景有:

  • 通过配置 { "@": "src" } 来实现 @ 到源代码目录的映射,如 @/constants/foo 会被解析到 <BUILD_ROOT>/src/constants/foo
  • lib(如 portal-base)中的开发预览项目可以通过配置 { "portal-base": ".." } 来引用 lib 本身的内容,见 https://github.com/qbox/portal-base/pull/647
  • 依赖 Node.js core module polyfill 的项目可以通过类似 { "crypto": "crypto-browserify" } 的配置来实现之,详见 Node.js core modules polyfill #151 (comment)

@nighca nighca changed the title add resolve in build-config 支持 resolve alias Dec 24, 2021
Copy link
Collaborator

@liaoyu liaoyu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@nighca nighca merged commit 845f5da into qiniu:master Dec 24, 2021
@nighca nighca mentioned this pull request Dec 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

支持 resolve alias
2 participants