Skip to content

Commit 54cecce

Browse files
committed
feat: if no /index.js, fallback to src/index.js
close #13
1 parent c1a01a5 commit 54cecce

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

lib/getWebpackCommonConfig.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict';
22

33
const path = require('path');
4+
const fs = require('fs');
45
const resolveCwd = require('./resolveCwd');
56
const cwd = process.cwd();
67
const pkg = require(resolveCwd('package.json'));
@@ -22,8 +23,26 @@ function getResolve() {
2223
alias,
2324
};
2425
const name = pkg.name;
25-
alias[`${name}$`] = resolveCwd('index.js');
26+
27+
// https://github.com/react-component/react-component.github.io/issues/13
28+
// we dont't want rc-component examples/test code import rc-component from lib
29+
// we want test with src
30+
let pkgSrcMain = resolveCwd('index.js');
31+
if (!fs.existsSync(pkgSrcMain)) {
32+
pkgSrcMain = resolveCwd('src/index.js');
33+
if (!fs.existsSync(pkgSrcMain)) {
34+
console.error('Get webpack.resolve.alias error: no /index.js or /src/index.js exist !!');
35+
}
36+
}
37+
38+
// redireact import { foo } from 'rc-component'
39+
// to 'rc-component/index.js' or 'rc-component/src/index.js'
40+
alias[`${name}$`] = pkgSrcMain;
41+
// redireact import foo from 'rc-component/lib/foo'
42+
// to 'rc-component/src/foo.js'
43+
alias[`${name}/lib`] = resolveCwd('./src');
2644
alias[`${name}/${constants.tsCompiledDir}`] = cwd;
45+
2746
alias[name] = cwd;
2847
return resolve;
2948
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "rc-tools",
3-
"version": "6.3.7",
3+
"version": "6.4.1",
44
"description": "offline tools for react component",
55
"keywords": [
66
"react",

0 commit comments

Comments
 (0)