react-component.github.io icon indicating copy to clipboard operation
react-component.github.io copied to clipboard

refactor test import path, remove redundancy index.js

Open paranoidjk opened this issue 8 years ago • 7 comments

ref: https://github.com/react-component/tree-select/issues/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

  • [x] tree-select

paranoidjk avatar Jul 17 '17 07:07 paranoidjk

index.js 原来是给这里用的 https://github.com/react-component/rc-tools/blob/f162f2858e9008616fb344478cd44332cffc77d7/lib/getWebpackCommonConfig.js#L25

yesmeck avatar Jul 25 '17 07:07 yesmeck

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

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

paranoidjk avatar Jul 25 '17 07:07 paranoidjk

@yesmeck 或者统一用 pkg.config.entry? https://github.com/react-component/react-component.github.io/issues/14

paranoidjk avatar Jul 25 '17 07:07 paranoidjk

https://github.com/react-component/rc-tools/commit/c705b6dc1a5fa963b9d28717b23167a3463f2029

paranoidjk avatar Aug 06 '17 03:08 paranoidjk

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 https://github.com/react-component/rc-tools/compare/c1a01a5ebc603c071dec50031d674f7694cb7d1a...53592b714542ba014c3c23f09ca686a1af0506a2

paranoidjk avatar Aug 13 '17 08:08 paranoidjk

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

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

@yesmeck 有空处理下这个么?

paranoidjk avatar Oct 23 '17 08:10 paranoidjk

我最近没空....

可以用这个库做例子 https://github.com/react-component/m-pull-to-refresh

https://github.com/react-component/m-pull-to-refresh/blob/master/examples/base.js#L2 这个改掉就会出问题

cc @warmhug

paranoidjk avatar Oct 23 '17 08:10 paranoidjk