Skip to content

Commit c705b6d

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

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

lib/getWebpackCommonConfig.js

Lines changed: 15 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,21 @@ 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+
alias[`${name}$`] = pkgSrcMain;
38+
2639
alias[`${name}/${constants.tsCompiledDir}`] = cwd;
40+
2741
alias[name] = cwd;
2842
return resolve;
2943
}

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.0",
44
"description": "offline tools for react component",
55
"keywords": [
66
"react",

0 commit comments

Comments
 (0)