Skip to content

Commit

Permalink
refactor: keep index.js as entry (ant-design#3397)
Browse files Browse the repository at this point in the history
  • Loading branch information
afc163 authored and benjycui committed Oct 31, 2016
1 parent 915ebd6 commit 1deea83
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 35 deletions.
9 changes: 9 additions & 0 deletions components/index.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
/* eslint no-console:0 */
// this file is not used if use https://github.com/ant-design/babel-plugin-import
if (process.env.NODE_ENV !== 'production') {
if (typeof console !== 'undefined' && console.warn) {
console.warn(`You are using prebuilt antd,
please use https://www.npmjs.com/package/babel-plugin-import to reduce app bundle size.`);
}
}

export { default as Affix } from './affix';

export { default as AutoComplete } from './auto-complete';
Expand Down
35 changes: 1 addition & 34 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,34 +1 @@
/* eslint no-console:0 */
// this file is not used if use https://github.com/ant-design/babel-plugin-import

function camelCase(name) {
return name.charAt(0).toUpperCase() +
name.slice(1).replace(/-(\w)/g, (m, n) => {
return n.toUpperCase();
});
}

const req = require.context('./components', true, /^\.\/[^_][\w-]+\/(style\/)?index\.tsx?$/);

req.keys().forEach((mod) => {
let v = req(mod);
if (v && v.default) {
v = v.default;
}
const match = mod.match(/^\.\/([^_][\w-]+)\/index\.tsx?$/);
if (match && match[1]) {
if (match[1] === 'message' || match[1] === 'notification') {
// message & notification should not be capitalized
exports[match[1]] = v;
} else {
exports[camelCase(match[1])] = v;
}
}
});

if (process.env.NODE_ENV !== 'production') {
if (typeof console !== 'undefined' && console.warn) {
console.warn(`You are using prebuilt antd,
please use https://www.npmjs.com/package/babel-plugin-import to reduce app bundle size.`);
}
}
module.exports = require('./components');
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"bugs": {
"url": "https://github.com/ant-design/ant-design/issues"
},
"main": "dist/antd",
"main": "lib/index.js",
"files": [
"dist",
"lib"
Expand Down
6 changes: 6 additions & 0 deletions typings/custom-typings.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,9 @@ declare module 'rc-upload';
declare module 'rc-collapse';

declare module 'rc-form*';

declare var process: {
env: {
NODE_ENV: string
}
};

0 comments on commit 1deea83

Please sign in to comment.