diff --git a/.eslintrc.js b/.eslintrc.js index a8d6638874f6e7687714b5b061125bbf3bc00677..f06f75feef4a196fa4d71d8388a892d7aaf54c74 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -1,28 +1,9 @@ -const fabric = require('@umijs/fabric'); +const fabric = require('@duanledexian/umi-config'); module.exports = { ...fabric.default, rules: { ...fabric.default.rules, - 'import/no-extraneous-dependencies': [ - 2, - { - optionalDependencies: true, - devDependencies: ['**/tests/**.js', '/mock/**/**.js', '**/**.test.js', '**/**._mock.js'], - }, - ], - 'import/no-named-as-default': 0, - }, - settings: { - ...fabric.default.settings, - // support import modules from TypeScript files in JavaScript files - 'import/resolver': { - node: { extensions: ['.js', '.ts', '.tsx'] }, - alias: { - map: [['@', './src'], ['utils', './src/utils'], ['config', './config']], - extensions: ['.ts', '.js', '.jsx', '.json'], - }, - }, }, globals: { ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION: true, diff --git a/.npmrc b/.npmrc new file mode 100644 index 0000000000000000000000000000000000000000..882af8d093d51a42791c7c1d7c9ce0551cbdfa32 --- /dev/null +++ b/.npmrc @@ -0,0 +1 @@ +puppeteer_download_host = https://npm.taobao.org/mirrors \ No newline at end of file diff --git a/.prettierrc.js b/.prettierrc.js index 7b597d78917c7e33a81bb3e83c6067f6a9a970e6..347877026736179f959197dbff152922a90532e3 100644 --- a/.prettierrc.js +++ b/.prettierrc.js @@ -1,4 +1,4 @@ -const fabric = require('@umijs/fabric'); +const fabric = require('@duanledexian/umi-config'); module.exports = { ...fabric.prettier, diff --git a/.stylelintrc.js b/.stylelintrc.js index c2030787de72c5cffc44099fbdbae55c32afd482..559ecd841804b23e5cf58a4d60716ee9916242d8 100644 --- a/.stylelintrc.js +++ b/.stylelintrc.js @@ -1,4 +1,4 @@ -const fabric = require('@umijs/fabric'); +const fabric = require('@duanledexian/umi-config'); module.exports = { ...fabric.stylelint, diff --git a/config/config.ts b/config/config.ts index cd2052c8ece4730c4abecea94e26c5868fb17833..0dca86014d40fd9e39be03120ea2ee5a69e271d4 100644 --- a/config/config.ts +++ b/config/config.ts @@ -1,16 +1,15 @@ import { IConfig, IPlugin } from 'umi-types'; import defaultSettings from './defaultSettings'; // https://umijs.org/config/ -import theme from './theme.config'; - -import os from 'os'; import slash from 'slash2'; import webpackPlugin from './plugin.config'; const path = require('path'); const { pwa } = defaultSettings; // preview.pro.ant.design only do not use in your production ; // preview.pro.ant.design 专用环境变量,请不要在你的项目中使用它。 +const { ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION } = process.env; + +const isAntDesignProPreview = ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION === 'site'; -const { ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION, TEST, NODE_ENV } = process.env; const plugins: IPlugin[] = [ [ 'umi-plugin-react', @@ -40,15 +39,10 @@ const plugins: IPlugin[] = [ }, } : false, - ...(!TEST && os.platform() === 'darwin' - ? { - dll: { - include: ['dva', 'dva/router', 'dva/saga', 'dva/fetch'], - exclude: ['@babel/runtime', 'netlify-lambda'], - }, - hardSource: false, - } - : {}), + dll: { + include: ['dva', 'dva/router', 'dva/saga', 'dva/fetch'], + exclude: ['@babel/runtime', 'netlify-lambda'], + }, }, ], [ @@ -60,10 +54,10 @@ const plugins: IPlugin[] = [ autoAddMenu: true, }, ], -]; // 针对 preview.pro.ant.design 的 GA 统计代码 -// preview.pro.ant.design only do not use in your production ; preview.pro.ant.design 专用环境变量,请不要在你的项目中使用它。 +]; -if (ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION === 'site') { +// 针对 preview.pro.ant.design 的 GA 统计代码 +if (isAntDesignProPreview) { plugins.push([ 'umi-plugin-ga', { @@ -72,34 +66,17 @@ if (ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION === 'site') { ]); } -const uglifyJSOptions = - NODE_ENV === 'production' - ? { - uglifyOptions: { - // remove console.* except console.error - compress: { - drop_console: true, - pure_funcs: ['console.error'], - }, - }, - } - : {}; export default { - // add for transfer to umi plugins, - define: { - ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION: - ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION || '', // preview.pro.ant.design only do not use in your production ; preview.pro.ant.design 专用环境变量,请不要在你的项目中使用它。 - }, block: { defaultGitUrl: 'https://github.com/ant-design/pro-blocks', }, - treeShaking: true, + hash: true, targets: { ie: 11, }, - devtool: ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION ? 'source-map' : false, - // 路由配置 + devtool: isAntDesignProPreview ? 'source-map' : false, + // umi routes: https://umijs.org/zh/guide/router.html routes: [ { path: '/', @@ -336,8 +313,14 @@ export default { }, ], }, + { + component: './404', + }, ], }, + { + component: './404', + }, ], // Theme for antd // https://ant.design/docs/react/customize-theme-cn @@ -349,6 +332,14 @@ export default { // pathRewrite: { '^/server': '' }, // }, // }, + // Theme for antd: https://ant.design/docs/react/customize-theme-cn + theme: { + 'primary-color': primaryColor, + }, + define: { + ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION: + ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION || '', // preview.pro.ant.design only do not use in your production ; preview.pro.ant.design 专用环境变量,请不要在你的项目中使用它。 + }, ignoreMomentLocale: true, lessLoaderOptions: { javascriptEnabled: true, @@ -360,7 +351,7 @@ export default { context: { resourcePath: string; }, - localIdentName: string, + _: string, localName: string, ) => { if ( @@ -400,4 +391,13 @@ export default { config: path.join(__dirname, '../src', '../config'), public: path.join(__dirname, '../public'), }, + /* + proxy: { + '/server/api/': { + target: 'https://preview.pro.ant.design/', + changeOrigin: true, + pathRewrite: { '^/server': '' }, + }, + }, + */ } as IConfig; diff --git a/jest.config.js b/jest.config.js index 147a0252e938fa18917cac5bdc4446e1f86765a8..c06625f492d3f6d65eecbc1368db83d3ae9e6787 100644 --- a/jest.config.js +++ b/jest.config.js @@ -3,6 +3,6 @@ module.exports = { preset: 'jest-puppeteer', extraSetupFiles: ['./tests/setupTests.js'], globals: { - ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION: false, // preview.pro.ant.design only do not use in your production ; preview.pro.ant.design 专用环境变量,请不要在你的项目中使用它。 + ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION: false, }, }; diff --git a/package.json b/package.json index 02f18ae625d279743680cd88e74ee86d68a55dcf..12f7bc146efde853cac88a1817d8fa60ae0c4752 100644 --- a/package.json +++ b/package.json @@ -34,7 +34,7 @@ }, "husky": { "hooks": { - + "pre-commit": "npm run lint-staged" } }, "lint-staged": { @@ -94,16 +94,18 @@ }, "devDependencies": { "@ant-design/colors": "^3.1.0", + "@duanledexian/umi-config": "^1.0.10", "@types/classnames": "^2.2.7", "@types/history": "^4.7.2", "@types/jest": "^24.0.13", "@types/lodash": "^4.14.134", + "@types/mockjs": "^1.0.2", + "@types/numeral": "^0.0.25", "@types/qs": "^6.5.3", "@types/react": "^16.8.19", "@types/react-document-title": "^2.0.3", "@types/react-dom": "^16.8.4", "@types/numeral":"^0.0.25", - "@umijs/fabric": "^1.0.5", "babel-eslint": "^10.0.1", "chalk": "^2.4.2", "check-prettier": "^1.0.3", @@ -129,9 +131,8 @@ "stylelint": "^10.1.0", "webpack-theme-color-replacer": "^1.1.5", "mockjs": "^1.0.1-beta3", - "@types/mockjs":"^1.0.2", - "eslint-import-resolver-alias": "^1.1.2" - }, + "@types/mockjs":"^1.0.2" + }, "optionalDependencies": { "puppeteer": "^1.17.0" }, diff --git a/scripts/fetch-blocks.js b/scripts/fetch-blocks.js index 9e182b75e96a3a0a8f36c90ad6899f83510b3f17..996ef78f8f28630d3e61daafbbd5cff3e7916ee5 100644 --- a/scripts/fetch-blocks.js +++ b/scripts/fetch-blocks.js @@ -41,6 +41,9 @@ const findAllInstallRouter = router => { const filterParentRouter = (router, layout) => { return [...router] .map(item => { + if (!item.path && item.component === '404') { + return item; + } if (item.routes && (!router.component || layout)) { return { ...item, routes: filterParentRouter(item.routes, false) }; } @@ -94,7 +97,7 @@ const installBlock = async () => { console.log('install ' + chalk.green(item.name) + ' to: ' + chalk.yellow(item.path)); gitFiles = gitFiles.filter(file => file.path !== gitPath); const skipModifyRouter = item.routes ? '--skip-modify-routes' : ''; - const cmd = `umi block add https://github.com/ant-design/pro-blocks/tree/master/${gitPath} --path=${item.path} ${skipModifyRouter}`; + const cmd = `umi block add https://github.com/ant-design/pro-blocks/tree/master/${gitPath} --path=${item.path} ${skipModifyRouter}`; try { await execCmd(cmd); console.log(`install ${chalk.hex('#1890ff')(item.name)} success`); diff --git a/src/components/CopyBlock/index.tsx b/src/components/CopyBlock/index.tsx index 9ee05ae8739bd1f254aad654f0fe0911feebad7e..fb9d8ac09a40007aaab24e13a29fc1dbc13658ef 100644 --- a/src/components/CopyBlock/index.tsx +++ b/src/components/CopyBlock/index.tsx @@ -33,7 +33,7 @@ const onBlockCopy = (label: string) => { const BlockCodeView: React.SFC<{ url: string; }> = ({ url }) => { - const blockUrl = `npx umi block add ${firstUpperCase(url)} --path=${url}`; + const blockUrl = `npx umi block add ${firstUpperCase(url)} --path=${url}`; return (
Sorry, the page you visited does not exist.
+ +