├── .gitignore ├── CHANGELOG.md ├── LICENSE ├── README.md ├── changelog.config.js ├── commitlint.config.js ├── config ├── env.js ├── jest │ ├── cssTransform.js │ └── fileTransform.js ├── modules.js ├── paths.js ├── pnpTs.js ├── webpack.config.js └── webpackDevServer.config.js ├── doc └── state-tree-v2.png ├── package.json ├── plop ├── actions │ └── index.js ├── config.js ├── generators │ ├── component.js │ └── module.js ├── prompts │ └── index.js └── templates │ ├── component.class.jsx.hbs │ ├── component.function.jsx.hbs │ ├── component.module.scss.hbs │ ├── module.action.js.hbs │ ├── module.reducer.js.hbs │ ├── module.saga.js.hbs │ └── module.selector.js.hbs ├── plopfile.js ├── public ├── favicon.ico ├── images │ ├── icon-charts.svg │ ├── icon-dashboard.svg │ ├── icon-employee.svg │ ├── icon-hotel.svg │ ├── icon-member.svg │ ├── icon-notice.svg │ ├── icon-profile.svg │ ├── icon-road.svg │ ├── icon-setting.svg │ ├── icon-table.svg │ ├── logo.svg │ ├── sidebar-bg1.jpg │ └── user-center.svg ├── index.html ├── logo192.png ├── logo512.png ├── manifest.json └── robots.txt ├── scripts ├── build.js ├── start.js └── test.js ├── src ├── assets │ ├── css │ │ └── material-dashboard-react.css │ ├── img │ │ ├── apple-icon.png │ │ ├── cover.jpeg │ │ ├── defaultAvatar.png │ │ ├── faces │ │ │ └── marc.jpg │ │ ├── favicon.png │ │ ├── mask.png │ │ ├── new_logo.png │ │ ├── reactlogo.png │ │ ├── sidebar-1.jpg │ │ ├── sidebar-2.jpg │ │ ├── sidebar-3.jpg │ │ ├── sidebar-4.jpg │ │ └── tim_80x80.png │ └── jss │ │ ├── material-dashboard-react.js │ │ └── material-dashboard-react │ │ ├── cardImagesStyles.js │ │ ├── checkboxAdnRadioStyle.js │ │ ├── components │ │ ├── buttonStyle.js │ │ ├── cardAvatarStyle.js │ │ ├── cardBodyStyle.js │ │ ├── cardFooterStyle.js │ │ ├── cardHeaderStyle.js │ │ ├── cardIconStyle.js │ │ ├── cardStyle.js │ │ ├── customInputStyle.js │ │ ├── customTabsStyle.js │ │ ├── footerStyle.js │ │ ├── headerLinksStyle.js │ │ ├── headerStyle.js │ │ ├── muiDatepicker.js │ │ ├── rtlHeaderLinksStyle.js │ │ ├── sidebarStyle.js │ │ ├── snackbarContentStyle.js │ │ ├── tableStyle.js │ │ ├── tasksStyle.js │ │ └── typographyStyle.js │ │ ├── dropdownStyle.js │ │ ├── layouts │ │ ├── adminStyle.js │ │ └── rtlStyle.js │ │ ├── tooltipStyle.js │ │ └── views │ │ ├── dashboardStyle.js │ │ ├── iconsStyle.js │ │ └── rtlStyle.js ├── canvas │ ├── CanvasBg.js │ ├── ThreeD.js │ ├── cam.js │ ├── index.js │ └── trans.js ├── components │ ├── Card │ │ ├── Card.jsx │ │ ├── CardAvatar.jsx │ │ ├── CardBody.jsx │ │ ├── CardFooter.jsx │ │ ├── CardHeader.jsx │ │ └── CardIcon.jsx │ ├── CardBasic │ │ └── CardBasic.jsx │ ├── CustomButtons │ │ └── CustomButtons.jsx │ ├── CustomInput │ │ └── CustomInput.jsx │ ├── CustomTabs │ │ ├── CustomTable.jsx │ │ └── CustomTabs.jsx │ ├── Dialog │ │ ├── Dialog.jsx │ │ └── Dialog.module.less │ ├── Footer │ │ ├── Footer.jsx │ │ └── Footer.module.less │ ├── Grid │ │ ├── GridContainer.jsx │ │ └── GridItem.jsx │ ├── HeaderNavbar │ │ ├── DropdownList.jsx │ │ ├── HeaderNavbar.jsx │ │ └── NavbarItem.jsx │ ├── HotelCard │ │ ├── HotelCard.jsx │ │ └── HotelCard.module.less │ ├── HotelList │ │ ├── HotelList.jsx │ │ └── HotelList.module.less │ ├── Loading.jsx │ ├── Login │ │ └── Login.jsx │ ├── MaterialTable │ │ ├── MaterialTable.jsx │ │ └── materialTableConfig.js │ ├── MuiDatepicker │ │ └── MuiDatepicker.jsx │ ├── MuiTimepicker │ │ └── MuiTimepicker.jsx │ ├── NotFound.jsx │ ├── Notifications │ │ └── NoticeMessage.jsx │ ├── PickerWithButton │ │ └── PickerWithButton.jsx │ ├── ScrollToTopMount.jsx │ ├── SideBar.jsx │ ├── SideTool.jsx │ ├── Snackbar │ │ └── Snackbar.jsx │ ├── Table │ │ └── Table.jsx │ ├── TestPlopAutoCreate │ │ ├── TestPlopAutoCreate.jsx │ │ └── TestPlopAutoCreate.module.less │ ├── Typography │ │ └── Danger.jsx │ └── common-style │ │ ├── color.jsx │ │ ├── common.jsx │ │ ├── index.jsx │ │ └── sideBarStyle.jsx ├── dbdata │ ├── charts.js │ ├── create.js │ ├── employeedata.js │ ├── fameStyle.js │ ├── hoteldata.js │ ├── linedata.js │ ├── linedata.json │ ├── memberdata.js │ └── mountainline.js ├── hoc │ ├── HocDragWrap.jsx │ └── HocVerifyLogin.jsx ├── index.js ├── logo.svg ├── routes │ └── index.jsx ├── serviceWorker.js ├── static │ ├── Data.ts │ ├── Shape.ts │ ├── Util.ts │ └── type.ts ├── store │ ├── indexStore.js │ └── modules │ │ ├── account │ │ ├── action.js │ │ ├── reducer.js │ │ ├── saga.js │ │ └── selector.js │ │ ├── common │ │ ├── action.js │ │ ├── reducer.js │ │ ├── saga.js │ │ └── selector.js │ │ └── theme │ │ ├── action.js │ │ ├── reducer.js │ │ ├── saga.js │ │ └── selector.js ├── styles │ ├── colors.scss │ ├── global.less │ └── reset.css ├── utils │ ├── ButtonWaveEffect.js │ ├── cookieStore.js │ ├── drag.js │ ├── getBrowserInfo.js │ ├── index.js │ ├── record.js │ └── sessionStore.js └── views │ ├── ChartPage │ └── ChartPage.jsx │ ├── EmployeeManagement │ ├── EmployeeManagement.jsx │ └── employeeTableConfig.js │ ├── Home.jsx │ ├── HotelPage │ └── HotelPage.jsx │ ├── MemberPage │ ├── MemberPage.jsx │ └── memberTableConfig.js │ ├── PlayLinePage │ └── PlayLinePage.jsx │ └── UserProfile │ ├── UserProfile.jsx │ └── UserProfile.module.less ├── tsconfig.json └── yarn.lock /.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | package-lock.json 6 | 7 | # testing 8 | /coverage 9 | 10 | # production 11 | /build 12 | 13 | # misc 14 | .vscode 15 | .idea 16 | .DS_Store 17 | .env.local 18 | .env.development.local 19 | .env.test.local 20 | .env.production.local 21 | package-lock.json 22 | 23 | npm-debug.log* 24 | yarn-debug.log* 25 | yarn-error.log* -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. 4 | 5 | ### [1.0.1](https://github.com/SimpleRoom/walker-admin/compare/v1.1.0...v1.0.1) (2020-03-29) 6 | 7 | 8 | ### Bug Fixes 9 | 10 | * 🐛 测试releases ([e05207c](https://github.com/SimpleRoom/walker-admin/commit/e05207c5d1e122429a9eaa3c8a8ad7d9abe594ce)) 11 | * 🐛 测试生成releases ([54b936d](https://github.com/SimpleRoom/walker-admin/commit/54b936dba5cd5fc50ed53efb9d369845c6aa5364)) 12 | 13 | ## [1.0.0](https://github.com/SimpleRoom/walker-admin/compare/v1.1.0...v1.0.0) (2020-03-29) 14 | 15 | 16 | ### Bug Fixes 17 | 18 | * 🐛 测试releases ([e05207c](https://github.com/SimpleRoom/walker-admin/commit/e05207c5d1e122429a9eaa3c8a8ad7d9abe594ce)) 19 | * 🐛 测试生成releases ([54b936d](https://github.com/SimpleRoom/walker-admin/commit/54b936dba5cd5fc50ed53efb9d369845c6aa5364)) 20 | 21 | # [1.0.0](https://github.com/SimpleRoom/walker-admin/compare/v1.1.0...v1.0.0) (2020-03-29) 22 | 23 | 24 | 25 | # [1.1.0](https://github.com/SimpleRoom/walker-admin/compare/v1.0.0...v1.1.0) (2020-03-29) 26 | 27 | 28 | ### Features 29 | 30 | * 🎸 add release ([33aac69](https://github.com/SimpleRoom/walker-admin/commit/33aac69638148035e4fd5c4d5ea8e9434a0bf4b3)) 31 | 32 | 33 | 34 | # [1.0.0](https://github.com/SimpleRoom/walker-admin/compare/1a66b4ccc0fc03d68bae22efd5f6db679fb6c350...v1.0.0) (2020-03-29) 35 | 36 | 37 | ### Bug Fixes 38 | 39 | * **github api load error:** github api load error ([0ab4536](https://github.com/SimpleRoom/walker-admin/commit/0ab4536eeb43efdb0b1d9c5443f05370050f9d13)) 40 | * move routeList state ([8806c8a](https://github.com/SimpleRoom/walker-admin/commit/8806c8a61b1cddca66da55b89810e1a1f6a29c7b)) 41 | * set userinfo to account ([a4e603c](https://github.com/SimpleRoom/walker-admin/commit/a4e603caff504342e1221f622258386a644b941f)) 42 | * **loadable-component:** 替换组件懒加载 ([6697b1e](https://github.com/SimpleRoom/walker-admin/commit/6697b1e969c440a736210cd7962017e02893230c)) 43 | 44 | 45 | ### Code Refactoring 46 | 47 | * 💡 update package ([89e53da](https://github.com/SimpleRoom/walker-admin/commit/89e53da2827242dd0ed42c65b57b101269ccde71)) 48 | * 💡 use git-cz ([3ff33f9](https://github.com/SimpleRoom/walker-admin/commit/3ff33f9b049ed2675a181630b92cf81902d231ca)) 49 | 50 | 51 | ### Features 52 | 53 | * 添加commitlint ([3df48be](https://github.com/SimpleRoom/walker-admin/commit/3df48bec9cc063b389d002ea97e2a4f0a94914ac)) 54 | * **commitizen:** 添加commitizen来规范commit msg ([1a66b4c](https://github.com/SimpleRoom/walker-admin/commit/1a66b4ccc0fc03d68bae22efd5f6db679fb6c350)) 55 | * **how to create changelog:** 如何新建一条CHANGELOG信息到changelog.md ([12fc7b2](https://github.com/SimpleRoom/walker-admin/commit/12fc7b279fde5144ac7d30ece8c23cadd7bddfe7)) 56 | * **react-saga异步获取数据:** 获取指定用户的github个人信息 ([39438ff](https://github.com/SimpleRoom/walker-admin/commit/39438ffd77c0f2b963330ad3bdde0188dc114a1b)) 57 | * **reploy:** 如何部署到服务器二级目录下,如:www.xx.com/admin ([ca195ac](https://github.com/SimpleRoom/walker-admin/commit/ca195aca9ca24bbf51563611483b4205acaad2b8)) 58 | * **verify login hoc:** add verify login HOC&account store ([e0af57a](https://github.com/SimpleRoom/walker-admin/commit/e0af57a7f55d6bfe70f594102ba52b818f8da3dd)) 59 | * **添加changelog.md:** 记录日志 ([2806bef](https://github.com/SimpleRoom/walker-admin/commit/2806bef18100886c4b7d5532bb0d564e3c4d4ce0)) 60 | * **添加conventional-changelog到devdep:** 防止conventional-changelog没有全局安装 ([f230d89](https://github.com/SimpleRoom/walker-admin/commit/f230d89a84fd7e1c28faee074f85689f3aa25724)) 61 | * **添加material-ui 资源:** 添加所有关于material-ui的依赖资源 ([047063f](https://github.com/SimpleRoom/walker-admin/commit/047063f3de2fb20ed93ebb579860fb9371a74f41)) 62 | * **添加validate-commit-msg验证包,changelog:** 需要全局安装下conventional-changelog ([aa5b68a](https://github.com/SimpleRoom/walker-admin/commit/aa5b68a961fabea30633f57daf7e4c18be67aac3)) 63 | 64 | 65 | ### Tests 66 | 67 | * 💍 测试release ([9e95ceb](https://github.com/SimpleRoom/walker-admin/commit/9e95cebc1e1c8f1c5b3d017a66ca34336ddf8651)) 68 | * 💍 生成changelog ([af09fc2](https://github.com/SimpleRoom/walker-admin/commit/af09fc22a9e877189901cfa983b6d159c7fa9acd)) 69 | 70 | 71 | ### BREAKING CHANGES 72 | 73 | * 🧨 N 74 | 75 | ✅ Closes: N 76 | * 🧨 N 77 | 78 | ✅ Closes: N 79 | * 🧨 N 80 | 81 | ✅ Closes: N 82 | * 🧨 N 83 | 84 | ✅ Closes: N 85 | * **how to create changelog:** no 86 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | BSD 2-Clause License 2 | 3 | Copyright (c) 2019, SimpleRoom 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | 9 | 1. Redistributions of source code must retain the above copyright notice, this 10 | list of conditions and the following disclaimer. 11 | 12 | 2. Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the documentation 14 | and/or other materials provided with the distribution. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 20 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 22 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 23 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 24 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | -------------------------------------------------------------------------------- /changelog.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | 'disableEmoji': false, 3 | 'list': [ 4 | 'config', 5 | 'feat', 6 | 'fix', 7 | 'chore', 8 | 'docs', 9 | 'refactor', 10 | 'style' 11 | ], 12 | 'maxMessageLength': 64, 13 | 'minMessageLength': 3, 14 | 'questions': [ 15 | 'type', 16 | 'scope', 17 | 'subject', 18 | 'body', 19 | 'breaking', 20 | 'issues', 21 | 'lerna' 22 | ], 23 | 'scopes': [], 24 | 'types': { 25 | 'config': { 26 | 'description': 'core config for package', 27 | 'emoji': '🎡', 28 | 'value': 'config' 29 | }, 30 | 'chore': { 31 | 'description': 'Build process or auxiliary tool changes', 32 | 'emoji': '🤖', 33 | 'value': 'chore' 34 | }, 35 | 'ci': { 36 | 'description': 'CI related changes', 37 | 'emoji': '🎡', 38 | 'value': 'ci' 39 | }, 40 | 'docs': { 41 | 'description': 'Documentation only changes', 42 | 'emoji': '💍', 43 | 'value': 'docs' 44 | }, 45 | 'feat': { 46 | 'description': 'A new feature', 47 | 'emoji': '🎸', 48 | 'value': 'feat' 49 | }, 50 | 'fix': { 51 | 'description': 'A bug fix', 52 | 'emoji': '🐛', 53 | 'value': 'fix' 54 | }, 55 | 'perf': { 56 | 'description': 'A code change that improves performance', 57 | 'emoji': '⚡️', 58 | 'value': 'perf' 59 | }, 60 | 'refactor': { 61 | 'description': 'A code change that neither fixes a bug or adds a feature', 62 | 'emoji': '💡', 63 | 'value': 'refactor' 64 | }, 65 | 'release': { 66 | 'description': 'Create a release commit', 67 | 'emoji': '🏹', 68 | 'value': 'release' 69 | }, 70 | 'style': { 71 | 'description': 'Markup, white-space, formatting, missing semi-colons...', 72 | 'emoji': '💄', 73 | 'value': 'style' 74 | }, 75 | 'test': { 76 | 'description': 'Adding missing tests', 77 | 'emoji': '💍', 78 | 'value': 'test' 79 | } 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /commitlint.config.js: -------------------------------------------------------------------------------- 1 | // https://juejin.im/post/5cf150f1f265da1b7c60ffe3 2 | module.exports = { 3 | // 继承默认配置 4 | extends: [ 5 | "@commitlint/config-angular" 6 | ], 7 | // 自定义规则 8 | rules: { 9 | 'type-enum': [2, 'always', [ 10 | 'config', 11 | 'feat', 12 | 'fix', 13 | 'refactor', 14 | 'docs', 15 | 'chore', 16 | 'style', 17 | 'revert', 18 | ]], 19 | 'header-max-length': [0, 'always', 72] 20 | } 21 | }; -------------------------------------------------------------------------------- /config/env.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const fs = require('fs'); 4 | const path = require('path'); 5 | const paths = require('./paths'); 6 | 7 | // Make sure that including paths.js after env.js will read .env variables. 8 | delete require.cache[require.resolve('./paths')]; 9 | 10 | const NODE_ENV = process.env.NODE_ENV; 11 | if (!NODE_ENV) { 12 | throw new Error( 13 | 'The NODE_ENV environment variable is required but was not specified.' 14 | ); 15 | } 16 | 17 | // https://github.com/bkeepers/dotenv#what-other-env-files-can-i-use 18 | const dotenvFiles = [ 19 | `${paths.dotenv}.${NODE_ENV}.local`, 20 | `${paths.dotenv}.${NODE_ENV}`, 21 | // Don't include `.env.local` for `test` environment 22 | // since normally you expect tests to produce the same 23 | // results for everyone 24 | NODE_ENV !== 'test' && `${paths.dotenv}.local`, 25 | paths.dotenv, 26 | ].filter(Boolean); 27 | 28 | // Load environment variables from .env* files. Suppress warnings using silent 29 | // if this file is missing. dotenv will never modify any environment variables 30 | // that have already been set. Variable expansion is supported in .env files. 31 | // https://github.com/motdotla/dotenv 32 | // https://github.com/motdotla/dotenv-expand 33 | dotenvFiles.forEach(dotenvFile => { 34 | if (fs.existsSync(dotenvFile)) { 35 | require('dotenv-expand')( 36 | require('dotenv').config({ 37 | path: dotenvFile, 38 | }) 39 | ); 40 | } 41 | }); 42 | 43 | // We support resolving modules according to `NODE_PATH`. 44 | // This lets you use absolute paths in imports inside large monorepos: 45 | // https://github.com/facebook/create-react-app/issues/253. 46 | // It works similar to `NODE_PATH` in Node itself: 47 | // https://nodejs.org/api/modules.html#modules_loading_from_the_global_folders 48 | // Note that unlike in Node, only *relative* paths from `NODE_PATH` are honored. 49 | // Otherwise, we risk importing Node.js core modules into an app instead of Webpack shims. 50 | // https://github.com/facebook/create-react-app/issues/1023#issuecomment-265344421 51 | // We also resolve them to make sure all tools using them work consistently. 52 | const appDirectory = fs.realpathSync(process.cwd()); 53 | process.env.NODE_PATH = (process.env.NODE_PATH || '') 54 | .split(path.delimiter) 55 | .filter(folder => folder && !path.isAbsolute(folder)) 56 | .map(folder => path.resolve(appDirectory, folder)) 57 | .join(path.delimiter); 58 | 59 | // Grab NODE_ENV and REACT_APP_* environment variables and prepare them to be 60 | // injected into the application via DefinePlugin in Webpack configuration. 61 | const REACT_APP = /^REACT_APP_/i; 62 | 63 | function getClientEnvironment(publicUrl) { 64 | const raw = Object.keys(process.env) 65 | .filter(key => REACT_APP.test(key)) 66 | .reduce( 67 | (env, key) => { 68 | env[key] = process.env[key]; 69 | return env; 70 | }, 71 | { 72 | // Useful for determining whether we’re running in production mode. 73 | // Most importantly, it switches React into the correct mode. 74 | NODE_ENV: process.env.NODE_ENV || 'development', 75 | // Useful for resolving the correct path to static assets in `public`. 76 | // For example, . 77 | // This should only be used as an escape hatch. Normally you would put 78 | // images into the `src` and `import` them in code to get their paths. 79 | PUBLIC_URL: publicUrl, 80 | } 81 | ); 82 | // Stringify all values so we can feed into Webpack DefinePlugin 83 | const stringified = { 84 | 'process.env': Object.keys(raw).reduce((env, key) => { 85 | env[key] = JSON.stringify(raw[key]); 86 | return env; 87 | }, {}), 88 | }; 89 | 90 | return { raw, stringified }; 91 | } 92 | 93 | module.exports = getClientEnvironment; 94 | -------------------------------------------------------------------------------- /config/jest/cssTransform.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | // This is a custom Jest transformer turning style imports into empty objects. 4 | // http://facebook.github.io/jest/docs/en/webpack.html 5 | 6 | module.exports = { 7 | process() { 8 | return 'module.exports = {};'; 9 | }, 10 | getCacheKey() { 11 | // The output is always the same. 12 | return 'cssTransform'; 13 | }, 14 | }; 15 | -------------------------------------------------------------------------------- /config/jest/fileTransform.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const path = require('path'); 4 | const camelcase = require('camelcase'); 5 | 6 | // This is a custom Jest transformer turning file imports into filenames. 7 | // http://facebook.github.io/jest/docs/en/webpack.html 8 | 9 | module.exports = { 10 | process(src, filename) { 11 | const assetFilename = JSON.stringify(path.basename(filename)); 12 | 13 | if (filename.match(/\.svg$/)) { 14 | // Based on how SVGR generates a component name: 15 | // https://github.com/smooth-code/svgr/blob/01b194cf967347d43d4cbe6b434404731b87cf27/packages/core/src/state.js#L6 16 | const pascalCaseFilename = camelcase(path.parse(filename).name, { 17 | pascalCase: true, 18 | }); 19 | const componentName = `Svg${pascalCaseFilename}`; 20 | return `const React = require('react'); 21 | module.exports = { 22 | __esModule: true, 23 | default: ${assetFilename}, 24 | ReactComponent: React.forwardRef(function ${componentName}(props, ref) { 25 | return { 26 | $$typeof: Symbol.for('react.element'), 27 | type: 'svg', 28 | ref: ref, 29 | key: null, 30 | props: Object.assign({}, props, { 31 | children: ${assetFilename} 32 | }) 33 | }; 34 | }), 35 | };`; 36 | } 37 | 38 | return `module.exports = ${assetFilename};`; 39 | }, 40 | }; 41 | -------------------------------------------------------------------------------- /config/modules.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const fs = require('fs'); 4 | const path = require('path'); 5 | const paths = require('./paths'); 6 | const chalk = require('react-dev-utils/chalk'); 7 | const resolve = require('resolve'); 8 | 9 | /** 10 | * Get additional module paths based on the baseUrl of a compilerOptions object. 11 | * 12 | * @param {Object} options 13 | */ 14 | function getAdditionalModulePaths(options = {}) { 15 | const baseUrl = options.baseUrl; 16 | 17 | // We need to explicitly check for null and undefined (and not a falsy value) because 18 | // TypeScript treats an empty string as `.`. 19 | if (baseUrl == null) { 20 | // If there's no baseUrl set we respect NODE_PATH 21 | // Note that NODE_PATH is deprecated and will be removed 22 | // in the next major release of create-react-app. 23 | 24 | const nodePath = process.env.NODE_PATH || ''; 25 | return nodePath.split(path.delimiter).filter(Boolean); 26 | } 27 | 28 | const baseUrlResolved = path.resolve(paths.appPath, baseUrl); 29 | 30 | // We don't need to do anything if `baseUrl` is set to `node_modules`. This is 31 | // the default behavior. 32 | if (path.relative(paths.appNodeModules, baseUrlResolved) === '') { 33 | return null; 34 | } 35 | 36 | // Allow the user set the `baseUrl` to `appSrc`. 37 | if (path.relative(paths.appSrc, baseUrlResolved) === '') { 38 | return [paths.appSrc]; 39 | } 40 | 41 | // If the path is equal to the root directory we ignore it here. 42 | // We don't want to allow importing from the root directly as source files are 43 | // not transpiled outside of `src`. We do allow importing them with the 44 | // absolute path (e.g. `src/Components/Button.js`) but we set that up with 45 | // an alias. 46 | if (path.relative(paths.appPath, baseUrlResolved) === '') { 47 | return null; 48 | } 49 | 50 | // Otherwise, throw an error. 51 | throw new Error( 52 | chalk.red.bold( 53 | "Your project's `baseUrl` can only be set to `src` or `node_modules`." + 54 | ' Create React App does not support other values at this time.' 55 | ) 56 | ); 57 | } 58 | 59 | /** 60 | * Get webpack aliases based on the baseUrl of a compilerOptions object. 61 | * 62 | * @param {*} options 63 | */ 64 | function getWebpackAliases(options = {}) { 65 | const baseUrl = options.baseUrl; 66 | 67 | if (!baseUrl) { 68 | return {}; 69 | } 70 | 71 | const baseUrlResolved = path.resolve(paths.appPath, baseUrl); 72 | 73 | if (path.relative(paths.appPath, baseUrlResolved) === '') { 74 | return { 75 | src: paths.appSrc, 76 | }; 77 | } 78 | } 79 | 80 | /** 81 | * Get jest aliases based on the baseUrl of a compilerOptions object. 82 | * 83 | * @param {*} options 84 | */ 85 | function getJestAliases(options = {}) { 86 | const baseUrl = options.baseUrl; 87 | 88 | if (!baseUrl) { 89 | return {}; 90 | } 91 | 92 | const baseUrlResolved = path.resolve(paths.appPath, baseUrl); 93 | 94 | if (path.relative(paths.appPath, baseUrlResolved) === '') { 95 | return { 96 | 'src/(.*)$': '/src/$1', 97 | }; 98 | } 99 | } 100 | 101 | function getModules() { 102 | // Check if TypeScript is setup 103 | const hasTsConfig = fs.existsSync(paths.appTsConfig); 104 | const hasJsConfig = fs.existsSync(paths.appJsConfig); 105 | 106 | if (hasTsConfig && hasJsConfig) { 107 | throw new Error( 108 | 'You have both a tsconfig.json and a jsconfig.json. If you are using TypeScript please remove your jsconfig.json file.' 109 | ); 110 | } 111 | 112 | let config; 113 | 114 | // If there's a tsconfig.json we assume it's a 115 | // TypeScript project and set up the config 116 | // based on tsconfig.json 117 | if (hasTsConfig) { 118 | const ts = require(resolve.sync('typescript', { 119 | basedir: paths.appNodeModules, 120 | })); 121 | config = ts.readConfigFile(paths.appTsConfig, ts.sys.readFile).config; 122 | // Otherwise we'll check if there is jsconfig.json 123 | // for non TS projects. 124 | } else if (hasJsConfig) { 125 | config = require(paths.appJsConfig); 126 | } 127 | 128 | config = config || {}; 129 | const options = config.compilerOptions || {}; 130 | 131 | const additionalModulePaths = getAdditionalModulePaths(options); 132 | 133 | return { 134 | additionalModulePaths: additionalModulePaths, 135 | webpackAliases: getWebpackAliases(options), 136 | jestAliases: getJestAliases(options), 137 | hasTsConfig, 138 | }; 139 | } 140 | 141 | module.exports = getModules(); 142 | -------------------------------------------------------------------------------- /config/paths.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const path = require('path'); 4 | const fs = require('fs'); 5 | const url = require('url'); 6 | 7 | // Make sure any symlinks in the project folder are resolved: 8 | // https://github.com/facebook/create-react-app/issues/637 9 | const appDirectory = fs.realpathSync(process.cwd()); 10 | const resolveApp = relativePath => path.resolve(appDirectory, relativePath); 11 | 12 | const envPublicUrl = process.env.PUBLIC_URL; 13 | 14 | function ensureSlash(inputPath, needsSlash) { 15 | const hasSlash = inputPath.endsWith('/'); 16 | if (hasSlash && !needsSlash) { 17 | return inputPath.substr(0, inputPath.length - 1); 18 | } else if (!hasSlash && needsSlash) { 19 | return `${inputPath}/`; 20 | } else { 21 | return inputPath; 22 | } 23 | } 24 | 25 | const getPublicUrl = appPackageJson => 26 | envPublicUrl || require(appPackageJson).homepage; 27 | 28 | // We use `PUBLIC_URL` environment variable or "homepage" field to infer 29 | // "public path" at which the app is served. 30 | // Webpack needs to know it to put the right