Skip to content

refactor test import path, remove redundancy index.js #13

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

Open
1 task done
paranoidjk opened this issue Jul 17, 2017 · 7 comments
Open
1 task done

refactor test import path, remove redundancy index.js #13

paranoidjk opened this issue Jul 17, 2017 · 7 comments
Assignees
Labels

Comments

@paranoidjk
Copy link
Member

paranoidjk commented Jul 17, 2017

ref: react-component/tree-select#62

踩了个坑,nodejs 读目录会优先尝试 pkg.main, 失败才会 fallback 到 index.js

https://github.com/nodejs/node/blob/master/lib/module.js#L115

所以用例里面 import TreeSelect from '..'; 会优先引用到 lib。

cc @react-component/admin

  • tree-select
@paranoidjk paranoidjk self-assigned this Jul 17, 2017
@paranoidjk paranoidjk added the bug label Jul 22, 2017
yesmeck added a commit to react-component/select that referenced this issue Jul 25, 2017
@yesmeck
Copy link
Member

yesmeck commented Jul 25, 2017

@paranoidjk
Copy link
Member Author

其实就是为了给 example 或者 test 里面 import Foo from 'rc-foo' 来做 alias 的...

@yesmeck 默认 alias 做一个 fallback , 先取 /index.js , 再取 /src/index.js

@paranoidjk
Copy link
Member Author

@yesmeck 或者统一用 pkg.config.entry? #14

@paranoidjk
Copy link
Member Author

paranoidjk commented Aug 6, 2017

@paranoidjk
Copy link
Member Author

paranoidjk commented Aug 13, 2017

Goal

  • rc-component maintainer wirte import path just like the user's way in example demo.
  • but make it actually use the src file

Proposal

import { foo } from 'rc-component'; // will redirect to import { foo } from 'rc-component/index.js' or import { foo } from 'rc-component/src/index.js'

import foo from 'rc-component/lib/foo'; // will redirect to import foo from 'rc-component/src/foo.js' 

done in react-component/rc-tools@c1a01a5...53592b7

@paranoidjk
Copy link
Member Author

对于 ts 的项目,没有 /index.js, 只有 /src/index.tsx 这种情况下 alias 到 src/index.tsx 是不行的,因为 ts 不能当 webpack entry。

直接 src/index.js 也不行, 因为 compile to lib 和 es 的时候会出问题

@yesmeck 有空处理下这个么?

@paranoidjk paranoidjk assigned yesmeck and unassigned paranoidjk Oct 23, 2017
@paranoidjk
Copy link
Member Author

paranoidjk added a commit to react-component/swipeout that referenced this issue Jun 12, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants