From 1deea83a05481d5f4d676ddd7da92a1cd37dcf1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=81=8F=E5=8F=B3?= Date: Mon, 31 Oct 2016 12:09:06 +0800 Subject: [PATCH] refactor: keep index.js as entry (#3397) --- components/index.tsx | 9 +++++++++ index.js | 35 +---------------------------------- package.json | 2 +- typings/custom-typings.d.ts | 6 ++++++ 4 files changed, 17 insertions(+), 35 deletions(-) diff --git a/components/index.tsx b/components/index.tsx index 47244c7f55..6dca06cac8 100644 --- a/components/index.tsx +++ b/components/index.tsx @@ -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'; diff --git a/index.js b/index.js index c672262baa..94017e32ba 100644 --- a/index.js +++ b/index.js @@ -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'); diff --git a/package.json b/package.json index 0161fbb45c..f92a85a56c 100644 --- a/package.json +++ b/package.json @@ -25,7 +25,7 @@ "bugs": { "url": "https://github.com/ant-design/ant-design/issues" }, - "main": "dist/antd", + "main": "lib/index.js", "files": [ "dist", "lib" diff --git a/typings/custom-typings.d.ts b/typings/custom-typings.d.ts index 2d82bbe31d..e0b46ce082 100644 --- a/typings/custom-typings.d.ts +++ b/typings/custom-typings.d.ts @@ -75,3 +75,9 @@ declare module 'rc-upload'; declare module 'rc-collapse'; declare module 'rc-form*'; + +declare var process: { + env: { + NODE_ENV: string + } +};