@authing/react-ui-components 3.0.2-beta.9 → 3.1.1-rc.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintignore +6 -0
- package/.eslintrc.js +7 -0
- package/.prettierrc +5 -0
- package/.vscode/settings.json +31 -0
- package/LICENSE +21 -0
- package/config/antdReplacer.js +51 -0
- package/config/env.js +106 -0
- package/config/getHttpsConfig.js +66 -0
- package/config/jest/cssTransform.js +14 -0
- package/config/jest/fileTransform.js +40 -0
- package/config/modules.js +134 -0
- package/config/paths.js +71 -0
- package/config/pnpTs.js +35 -0
- package/config/webpack.config.js +857 -0
- package/config/webpackDevServer.config.js +130 -0
- package/lib/index.d.ts +211 -1669
- package/lib/index.min.css +1 -2
- package/lib/index.min.js +1 -1
- package/lib/index.min.js.LICENSE.txt +0 -32
- package/package.json +18 -42
- package/public/favicon.ico +0 -0
- package/public/index.html +43 -0
- package/public/logo192.png +0 -0
- package/public/logo512.png +0 -0
- package/public/manifest.json +25 -0
- package/public/robots.txt +3 -0
- package/scripts/build.js +212 -0
- package/scripts/lib.js +200 -0
- package/scripts/start.js +166 -0
- package/scripts/test.js +53 -0
- package/src/common/AuthingDropdown/index.tsx +52 -0
- package/src/common/AuthingDropdown/style.less +43 -0
- package/src/common/AuthingTabs/index.tsx +98 -0
- package/src/common/AuthingTabs/style.less +135 -0
- package/src/common/CopyAbleText/index.tsx +54 -0
- package/src/common/CopyAbleText/style.less +13 -0
- package/src/common/VerifyCodeInput/index.tsx +76 -0
- package/src/common/VerifyCodeInput/style.less +24 -0
- package/src/components/AuthingGuard/AppMFALayout/index.tsx +74 -0
- package/src/components/AuthingGuard/AppMFALayout/style.less +12 -0
- package/src/components/AuthingGuard/CompleteUserInfoLayout/index.tsx +29 -0
- package/src/components/AuthingGuard/CompleteUserInfoLayout/style.less +8 -0
- package/src/components/AuthingGuard/Forms/ADLoginForm/index.tsx +117 -0
- package/src/components/AuthingGuard/Forms/Agreements/index.tsx +81 -0
- package/src/components/AuthingGuard/Forms/Agreements/style.less +44 -0
- package/src/components/AuthingGuard/Forms/CompleteUserInfoForm/index.tsx +139 -0
- package/src/components/AuthingGuard/Forms/EmailMfaVerifyForm/CheckEmailForm.tsx +86 -0
- package/src/components/AuthingGuard/Forms/EmailMfaVerifyForm/VerifyCodeForm.tsx +116 -0
- package/src/components/AuthingGuard/Forms/EmailMfaVerifyForm/index.tsx +40 -0
- package/src/components/AuthingGuard/Forms/EmailMfaVerifyForm/style.less +0 -0
- package/src/components/AuthingGuard/Forms/EmailRegisterForm/index.tsx +181 -0
- package/src/components/AuthingGuard/Forms/EmailRegisterForm/style.less +0 -0
- package/src/components/AuthingGuard/Forms/LdapLoginForm/index.tsx +161 -0
- package/src/components/AuthingGuard/Forms/LdapLoginForm/style.less +0 -0
- package/src/components/AuthingGuard/Forms/LoginFormFooter/index.tsx +76 -0
- package/src/components/AuthingGuard/Forms/LoginFormFooter/style.less +6 -0
- package/src/components/AuthingGuard/Forms/MfaResetCodeForm/Step1.tsx +86 -0
- package/src/components/AuthingGuard/Forms/MfaResetCodeForm/Step2.tsx +53 -0
- package/src/components/AuthingGuard/Forms/MfaResetCodeForm/index.tsx +65 -0
- package/src/components/AuthingGuard/Forms/MfaResetCodeForm/style.less +20 -0
- package/src/components/AuthingGuard/Forms/MfaVerifyForm/index.tsx +105 -0
- package/src/components/AuthingGuard/Forms/MfaVerifyForm/style.less +12 -0
- package/src/components/AuthingGuard/Forms/PasswordLoginForm/index.tsx +261 -0
- package/src/components/AuthingGuard/Forms/PhoneCodeLoginForm/index.tsx +133 -0
- package/src/components/AuthingGuard/Forms/PhoneRegisterForm/index.tsx +202 -0
- package/src/components/AuthingGuard/Forms/QrCodeLoginForm/index.tsx +61 -0
- package/src/components/AuthingGuard/Forms/QrCodeLoginForm/style.less +14 -0
- package/src/components/AuthingGuard/Forms/RegisterFormFooter/index.tsx +56 -0
- package/src/components/AuthingGuard/Forms/RegisterFormFooter/style.less +0 -0
- package/src/components/AuthingGuard/Forms/ResetPwdForm/Footer.tsx +21 -0
- package/src/components/AuthingGuard/Forms/ResetPwdForm/Step1.tsx +86 -0
- package/src/components/AuthingGuard/Forms/ResetPwdForm/Step2.tsx +127 -0
- package/src/components/AuthingGuard/Forms/ResetPwdForm/Step3.tsx +141 -0
- package/src/components/AuthingGuard/Forms/ResetPwdForm/Step4.tsx +51 -0
- package/src/components/AuthingGuard/Forms/ResetPwdForm/index.tsx +96 -0
- package/src/components/AuthingGuard/Forms/ResetPwdForm/style.less +3 -0
- package/src/components/AuthingGuard/Forms/SendPhoneCode/SendCodeBtn.tsx +88 -0
- package/src/components/AuthingGuard/Forms/SendPhoneCode/index.tsx +50 -0
- package/src/components/AuthingGuard/Forms/SendPhoneCode/style.less +26 -0
- package/src/components/AuthingGuard/Forms/SmsMfaVerifyForm/CheckPhoneForm.tsx +86 -0
- package/src/components/AuthingGuard/Forms/SmsMfaVerifyForm/VerifyCodeForm.tsx +113 -0
- package/src/components/AuthingGuard/Forms/SmsMfaVerifyForm/index.tsx +40 -0
- package/src/components/AuthingGuard/Forms/SmsMfaVerifyForm/style.less +3 -0
- package/src/components/AuthingGuard/Forms/SocialAndIdpLogin/index.tsx +325 -0
- package/src/components/AuthingGuard/Forms/SocialAndIdpLogin/style.less +75 -0
- package/src/components/AuthingGuard/Forms/UploadImage/index.tsx +70 -0
- package/src/components/AuthingGuard/Forms/index.ts +13 -0
- package/src/components/AuthingGuard/GuardLayout/index.tsx +488 -0
- package/src/components/AuthingGuard/GuardLayout/style.less +111 -0
- package/src/components/AuthingGuard/Header/index.tsx +28 -0
- package/src/components/AuthingGuard/Header/style.less +71 -0
- package/src/components/AuthingGuard/IconFont/iconfont.js +74 -0
- package/src/components/AuthingGuard/IconFont/index.tsx +19 -0
- package/src/components/AuthingGuard/IconFont/style.less +6 -0
- package/src/components/AuthingGuard/IconFont/svg.js +2 -0
- package/src/components/AuthingGuard/LoginLayout/index.tsx +205 -0
- package/src/components/AuthingGuard/LoginLayout/style.less +0 -0
- package/src/components/AuthingGuard/MfaLayout/Steps.ts +4 -0
- package/src/components/AuthingGuard/MfaLayout/index.tsx +49 -0
- package/src/components/AuthingGuard/MfaLayout/style.less +3 -0
- package/src/components/AuthingGuard/RegisterLayout/index.tsx +89 -0
- package/src/components/AuthingGuard/RegisterLayout/style.less +0 -0
- package/src/components/AuthingGuard/ResetPwdLayout/index.tsx +20 -0
- package/src/components/AuthingGuard/ToggleLang/index.tsx +51 -0
- package/src/components/AuthingGuard/api/appConfig.ts +154 -0
- package/src/components/AuthingGuard/api/http.ts +88 -0
- package/src/components/AuthingGuard/api/index.ts +3 -0
- package/src/components/AuthingGuard/api/sso.ts +29 -0
- package/src/components/AuthingGuard/api/userPoolConfig.ts +112 -0
- package/src/components/AuthingGuard/constants.ts +107 -0
- package/src/components/AuthingGuard/hooks/index.tsx +70 -0
- package/src/components/AuthingGuard/hooks/useScreenSize.tsx +68 -0
- package/src/components/AuthingGuard/index.tsx +134 -0
- package/src/components/AuthingGuard/locales/en/common.json +185 -0
- package/src/components/AuthingGuard/locales/en/index.ts +6 -0
- package/src/components/AuthingGuard/locales/en/login.json +94 -0
- package/src/components/AuthingGuard/locales/en/map.json +4 -0
- package/src/components/AuthingGuard/locales/en/user.json +81 -0
- package/src/components/AuthingGuard/locales/index.ts +45 -0
- package/src/components/AuthingGuard/locales/zh/common.json +185 -0
- package/src/components/AuthingGuard/locales/zh/index.ts +6 -0
- package/src/components/AuthingGuard/locales/zh/login.json +94 -0
- package/src/components/AuthingGuard/locales/zh/map.json +4 -0
- package/src/components/AuthingGuard/locales/zh/user.json +81 -0
- package/src/components/AuthingGuard/style.less +108 -0
- package/src/components/AuthingGuard/types/Forms.ts +95 -0
- package/src/components/AuthingGuard/types/GuardConfig.ts +424 -0
- package/src/components/AuthingGuard/types/GuardState.ts +7 -0
- package/src/components/AuthingGuard/types/Locales.ts +12 -0
- package/src/components/AuthingGuard/types/index.ts +4 -0
- package/src/components/index.ts +7 -0
- package/src/context/base.tsx +28 -0
- package/src/context/global/context.tsx +39 -0
- package/src/context/global/reducer.tsx +56 -0
- package/src/index.tsx +142 -0
- package/src/logo.svg +7 -0
- package/src/react-app-env.d.ts +71 -0
- package/src/reportWebVitals.ts +15 -0
- package/src/setupTests.ts +5 -0
- package/src/utils/clipboard.ts +27 -0
- package/src/utils/index.ts +180 -0
- package/src/utils/popupCenter.ts +48 -0
- package/tsconfig.json +24 -0
- package/lib/static/media/loading.4a67a5f3.svg +0 -29
|
@@ -4,38 +4,6 @@
|
|
|
4
4
|
http://jedwatson.github.io/classnames
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
/*! *****************************************************************************
|
|
8
|
-
Copyright (c) Microsoft Corporation.
|
|
9
|
-
|
|
10
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
|
11
|
-
purpose with or without fee is hereby granted.
|
|
12
|
-
|
|
13
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
14
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
15
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
16
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
17
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
18
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
19
|
-
PERFORMANCE OF THIS SOFTWARE.
|
|
20
|
-
***************************************************************************** */
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* @license
|
|
24
|
-
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
25
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
26
|
-
* you may not use this file except in compliance with the License.
|
|
27
|
-
* You may obtain a copy of the License at
|
|
28
|
-
*
|
|
29
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
30
|
-
*
|
|
31
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
32
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
33
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
34
|
-
* See the License for the specific language governing permissions and
|
|
35
|
-
* limitations under the License.
|
|
36
|
-
* =============================================================================
|
|
37
|
-
*/
|
|
38
|
-
|
|
39
7
|
/**
|
|
40
8
|
* @license
|
|
41
9
|
* Lodash <https://lodash.com/>
|
package/package.json
CHANGED
|
@@ -1,42 +1,23 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@authing/react-ui-components",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.1.1-rc.6",
|
|
4
4
|
"private": false,
|
|
5
5
|
"main": "lib/index.min.js",
|
|
6
6
|
"typings": "lib/index.d.ts",
|
|
7
|
-
"types": "react-app-env.d.ts",
|
|
8
|
-
"files": [
|
|
9
|
-
"dist",
|
|
10
|
-
"lib"
|
|
11
|
-
],
|
|
12
7
|
"dependencies": {
|
|
13
8
|
"antd": "^4.8.0",
|
|
14
|
-
"authing-js-sdk": "4.
|
|
15
|
-
"
|
|
16
|
-
"global": "^4.4.0",
|
|
17
|
-
"qs": "^6.9.4",
|
|
18
|
-
"react-use": "^17.3.1"
|
|
9
|
+
"authing-js-sdk": "4.23.1",
|
|
10
|
+
"qs": "^6.9.4"
|
|
19
11
|
},
|
|
20
12
|
"peerDependencies": {
|
|
21
|
-
"react": "16.
|
|
22
|
-
"react-dom": "16.
|
|
13
|
+
"react": "^15.0.1 || ^16.0.0 || ^17.0.0",
|
|
14
|
+
"react-dom": "^15.0.1 || ^16.0.0 || ^17.0.0"
|
|
23
15
|
},
|
|
24
16
|
"scripts": {
|
|
25
|
-
"
|
|
26
|
-
"build
|
|
27
|
-
"
|
|
28
|
-
"
|
|
29
|
-
"clear:lib": "rm -rf lib",
|
|
30
|
-
"log-tag": "node ./scripts/tag.js",
|
|
31
|
-
"pretty-quick": "pretty-quick",
|
|
32
|
-
"prepublishOnly": "node ./scripts/pre-publish.js",
|
|
33
|
-
"prestart": "npm run log-tag && npm run vegcrsion",
|
|
34
|
-
"preinstall": "npm run log-tag && npm run version",
|
|
35
|
-
"prebuild:lib": "npm run log-tag && npm run version",
|
|
36
|
-
"prepare": "cd ../.. && husky install packages/react-components/.husky",
|
|
37
|
-
"pub": "cross-env npm_guard_publish='true' node ./scripts/publish.js",
|
|
38
|
-
"start": "PORT=3006 node ./scripts/start.js",
|
|
39
|
-
"version": "node ./scripts/generate-version"
|
|
17
|
+
"start": "PORT=3006 node scripts/start.js",
|
|
18
|
+
"build": "node scripts/build.js",
|
|
19
|
+
"build:lib": "node scripts/lib.js",
|
|
20
|
+
"test": "node scripts/test.js"
|
|
40
21
|
},
|
|
41
22
|
"publishConfig": {
|
|
42
23
|
"access": "public",
|
|
@@ -62,21 +43,21 @@
|
|
|
62
43
|
},
|
|
63
44
|
"jest": {
|
|
64
45
|
"roots": [
|
|
65
|
-
"<rootDir>/
|
|
46
|
+
"<rootDir>/src"
|
|
66
47
|
],
|
|
67
48
|
"collectCoverageFrom": [
|
|
68
|
-
"
|
|
69
|
-
"!
|
|
49
|
+
"src/**/*.{js,jsx,ts,tsx}",
|
|
50
|
+
"!src/**/*.d.ts"
|
|
70
51
|
],
|
|
71
52
|
"setupFiles": [
|
|
72
53
|
"react-app-polyfill/jsdom"
|
|
73
54
|
],
|
|
74
55
|
"setupFilesAfterEnv": [
|
|
75
|
-
"<rootDir>/
|
|
56
|
+
"<rootDir>/src/setupTests.ts"
|
|
76
57
|
],
|
|
77
58
|
"testMatch": [
|
|
78
|
-
"<rootDir>/
|
|
79
|
-
"<rootDir>/
|
|
59
|
+
"<rootDir>/src/**/__tests__/**/*.{js,jsx,ts,tsx}",
|
|
60
|
+
"<rootDir>/src/**/*.{spec,test}.{js,jsx,ts,tsx}"
|
|
80
61
|
],
|
|
81
62
|
"testEnvironment": "jsdom",
|
|
82
63
|
"testRunner": "/Users/lixpng/workspace/authing/ui-components/packages/react-components/node_modules/jest-circus/runner.js",
|
|
@@ -126,7 +107,6 @@
|
|
|
126
107
|
"@testing-library/react": "^11.1.0",
|
|
127
108
|
"@testing-library/user-event": "^12.1.10",
|
|
128
109
|
"@types/jest": "^26.0.15",
|
|
129
|
-
"@types/lodash": "^4.14.175",
|
|
130
110
|
"@types/node": "^12.0.0",
|
|
131
111
|
"@types/qs": "^6.9.5",
|
|
132
112
|
"@types/react": "^16.9.53",
|
|
@@ -143,8 +123,6 @@
|
|
|
143
123
|
"bfj": "^7.0.2",
|
|
144
124
|
"camelcase": "^6.1.0",
|
|
145
125
|
"case-sensitive-paths-webpack-plugin": "2.3.0",
|
|
146
|
-
"chalk": "^4.1.2",
|
|
147
|
-
"cross-env": "^7.0.3",
|
|
148
126
|
"css-loader": "4.3.0",
|
|
149
127
|
"dotenv": "8.2.0",
|
|
150
128
|
"dotenv-expand": "5.1.0",
|
|
@@ -163,7 +141,6 @@
|
|
|
163
141
|
"file-loader": "6.1.1",
|
|
164
142
|
"fs-extra": "^9.0.1",
|
|
165
143
|
"html-webpack-plugin": "4.5.0",
|
|
166
|
-
"husky": "^7.0.4",
|
|
167
144
|
"i18next": "^20.1.0",
|
|
168
145
|
"i18next-browser-languagedetector": "^6.1.0",
|
|
169
146
|
"identity-obj-proxy": "3.0.0",
|
|
@@ -184,7 +161,6 @@
|
|
|
184
161
|
"postcss-rename-selector": "^0.1.1",
|
|
185
162
|
"postcss-safe-parser": "5.0.2",
|
|
186
163
|
"prettier": "^2.1.2",
|
|
187
|
-
"pretty-quick": "^3.0.0",
|
|
188
164
|
"query-string": "^7.0.0",
|
|
189
165
|
"react": "16.14.0",
|
|
190
166
|
"react-app-polyfill": "^2.0.0",
|
|
@@ -196,7 +172,6 @@
|
|
|
196
172
|
"resolve-url-loader": "^3.1.2",
|
|
197
173
|
"sass-loader": "8.0.2",
|
|
198
174
|
"semver": "7.3.2",
|
|
199
|
-
"shelljs": "^0.8.4",
|
|
200
175
|
"shortid": "^2.2.16",
|
|
201
176
|
"style-loader": "1.3.0",
|
|
202
177
|
"terser-webpack-plugin": "4.2.3",
|
|
@@ -209,5 +184,6 @@
|
|
|
209
184
|
"webpack-dev-server": "3.11.0",
|
|
210
185
|
"webpack-manifest-plugin": "2.2.0",
|
|
211
186
|
"workbox-webpack-plugin": "5.1.4"
|
|
212
|
-
}
|
|
213
|
-
|
|
187
|
+
},
|
|
188
|
+
"gitHead": "d88fabb91ebb5b5333598dcb10b88ceab7d9271e"
|
|
189
|
+
}
|
|
Binary file
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8" />
|
|
5
|
+
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
|
|
6
|
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
7
|
+
<meta name="theme-color" content="#000000" />
|
|
8
|
+
<meta
|
|
9
|
+
name="description"
|
|
10
|
+
content="Web site created using create-react-app"
|
|
11
|
+
/>
|
|
12
|
+
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
|
|
13
|
+
<!--
|
|
14
|
+
manifest.json provides metadata used when your web app is installed on a
|
|
15
|
+
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
|
|
16
|
+
-->
|
|
17
|
+
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
|
|
18
|
+
<!--
|
|
19
|
+
Notice the use of %PUBLIC_URL% in the tags above.
|
|
20
|
+
It will be replaced with the URL of the `public` folder during the build.
|
|
21
|
+
Only files inside the `public` folder can be referenced from the HTML.
|
|
22
|
+
|
|
23
|
+
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
|
|
24
|
+
work correctly both with client-side routing and a non-root public URL.
|
|
25
|
+
Learn how to configure a non-root public URL by running `npm run build`.
|
|
26
|
+
-->
|
|
27
|
+
<title>React App</title>
|
|
28
|
+
</head>
|
|
29
|
+
<body>
|
|
30
|
+
<noscript>You need to enable JavaScript to run this app.</noscript>
|
|
31
|
+
<div id="root"></div>
|
|
32
|
+
<!--
|
|
33
|
+
This HTML file is a template.
|
|
34
|
+
If you open it directly in the browser, you will see an empty page.
|
|
35
|
+
|
|
36
|
+
You can add webfonts, meta tags, or analytics to this file.
|
|
37
|
+
The build step will place the bundled scripts into the <body> tag.
|
|
38
|
+
|
|
39
|
+
To begin the development, run `npm start` or `yarn start`.
|
|
40
|
+
To create a production bundle, use `npm run build` or `yarn build`.
|
|
41
|
+
-->
|
|
42
|
+
</body>
|
|
43
|
+
</html>
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"short_name": "React App",
|
|
3
|
+
"name": "Create React App Sample",
|
|
4
|
+
"icons": [
|
|
5
|
+
{
|
|
6
|
+
"src": "favicon.ico",
|
|
7
|
+
"sizes": "64x64 32x32 24x24 16x16",
|
|
8
|
+
"type": "image/x-icon"
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
"src": "logo192.png",
|
|
12
|
+
"type": "image/png",
|
|
13
|
+
"sizes": "192x192"
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
"src": "logo512.png",
|
|
17
|
+
"type": "image/png",
|
|
18
|
+
"sizes": "512x512"
|
|
19
|
+
}
|
|
20
|
+
],
|
|
21
|
+
"start_url": ".",
|
|
22
|
+
"display": "standalone",
|
|
23
|
+
"theme_color": "#000000",
|
|
24
|
+
"background_color": "#ffffff"
|
|
25
|
+
}
|
package/scripts/build.js
ADDED
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// Do this as the first thing so that any code reading it knows the right env.
|
|
4
|
+
process.env.BABEL_ENV = 'production';
|
|
5
|
+
process.env.NODE_ENV = 'production';
|
|
6
|
+
|
|
7
|
+
// Makes the script crash on unhandled rejections instead of silently
|
|
8
|
+
// ignoring them. In the future, promise rejections that are not handled will
|
|
9
|
+
// terminate the Node.js process with a non-zero exit code.
|
|
10
|
+
process.on('unhandledRejection', err => {
|
|
11
|
+
throw err;
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
// Ensure environment variables are read.
|
|
15
|
+
require('../config/env');
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
const path = require('path');
|
|
19
|
+
const chalk = require('react-dev-utils/chalk');
|
|
20
|
+
const fs = require('fs-extra');
|
|
21
|
+
const bfj = require('bfj');
|
|
22
|
+
const webpack = require('webpack');
|
|
23
|
+
const configFactory = require('../config/webpack.config');
|
|
24
|
+
const paths = require('../config/paths');
|
|
25
|
+
const checkRequiredFiles = require('react-dev-utils/checkRequiredFiles');
|
|
26
|
+
const formatWebpackMessages = require('react-dev-utils/formatWebpackMessages');
|
|
27
|
+
const printHostingInstructions = require('react-dev-utils/printHostingInstructions');
|
|
28
|
+
const FileSizeReporter = require('react-dev-utils/FileSizeReporter');
|
|
29
|
+
const printBuildError = require('react-dev-utils/printBuildError');
|
|
30
|
+
|
|
31
|
+
const measureFileSizesBeforeBuild =
|
|
32
|
+
FileSizeReporter.measureFileSizesBeforeBuild;
|
|
33
|
+
const printFileSizesAfterBuild = FileSizeReporter.printFileSizesAfterBuild;
|
|
34
|
+
const useYarn = fs.existsSync(paths.yarnLockFile);
|
|
35
|
+
|
|
36
|
+
// These sizes are pretty large. We'll warn for bundles exceeding them.
|
|
37
|
+
const WARN_AFTER_BUNDLE_GZIP_SIZE = 512 * 1024;
|
|
38
|
+
const WARN_AFTER_CHUNK_GZIP_SIZE = 1024 * 1024;
|
|
39
|
+
|
|
40
|
+
const isInteractive = process.stdout.isTTY;
|
|
41
|
+
|
|
42
|
+
// Warn and crash if required files are missing
|
|
43
|
+
if (!checkRequiredFiles([paths.appHtml, paths.appIndexJs])) {
|
|
44
|
+
process.exit(1);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const argv = process.argv.slice(2);
|
|
48
|
+
const writeStatsJson = argv.indexOf('--stats') !== -1;
|
|
49
|
+
|
|
50
|
+
// Generate configuration
|
|
51
|
+
const config = configFactory('production');
|
|
52
|
+
|
|
53
|
+
// We require that you explicitly set browsers and do not fall back to
|
|
54
|
+
// browserslist defaults.
|
|
55
|
+
const { checkBrowsers } = require('react-dev-utils/browsersHelper');
|
|
56
|
+
checkBrowsers(paths.appPath, isInteractive)
|
|
57
|
+
.then(() => {
|
|
58
|
+
// First, read the current file sizes in build directory.
|
|
59
|
+
// This lets us display how much they changed later.
|
|
60
|
+
return measureFileSizesBeforeBuild(paths.appBuild);
|
|
61
|
+
})
|
|
62
|
+
.then(previousFileSizes => {
|
|
63
|
+
// Remove all content but keep the directory so that
|
|
64
|
+
// if you're in it, you don't end up in Trash
|
|
65
|
+
fs.emptyDirSync(paths.appBuild);
|
|
66
|
+
// Merge with the public folder
|
|
67
|
+
copyPublicFolder();
|
|
68
|
+
// Start the webpack build
|
|
69
|
+
return build(previousFileSizes);
|
|
70
|
+
})
|
|
71
|
+
.then(
|
|
72
|
+
({ stats, previousFileSizes, warnings }) => {
|
|
73
|
+
if (warnings.length) {
|
|
74
|
+
console.log(chalk.yellow('Compiled with warnings.\n'));
|
|
75
|
+
console.log(warnings.join('\n\n'));
|
|
76
|
+
console.log(
|
|
77
|
+
'\nSearch for the ' +
|
|
78
|
+
chalk.underline(chalk.yellow('keywords')) +
|
|
79
|
+
' to learn more about each warning.'
|
|
80
|
+
);
|
|
81
|
+
console.log(
|
|
82
|
+
'To ignore, add ' +
|
|
83
|
+
chalk.cyan('// eslint-disable-next-line') +
|
|
84
|
+
' to the line before.\n'
|
|
85
|
+
);
|
|
86
|
+
} else {
|
|
87
|
+
console.log(chalk.green('Compiled successfully.\n'));
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
console.log('File sizes after gzip:\n');
|
|
91
|
+
printFileSizesAfterBuild(
|
|
92
|
+
stats,
|
|
93
|
+
previousFileSizes,
|
|
94
|
+
paths.appBuild,
|
|
95
|
+
WARN_AFTER_BUNDLE_GZIP_SIZE,
|
|
96
|
+
WARN_AFTER_CHUNK_GZIP_SIZE
|
|
97
|
+
);
|
|
98
|
+
console.log();
|
|
99
|
+
|
|
100
|
+
const appPackage = require(paths.appPackageJson);
|
|
101
|
+
const publicUrl = paths.publicUrlOrPath;
|
|
102
|
+
const publicPath = config.output.publicPath;
|
|
103
|
+
const buildFolder = path.relative(process.cwd(), paths.appBuild);
|
|
104
|
+
printHostingInstructions(
|
|
105
|
+
appPackage,
|
|
106
|
+
publicUrl,
|
|
107
|
+
publicPath,
|
|
108
|
+
buildFolder,
|
|
109
|
+
useYarn
|
|
110
|
+
);
|
|
111
|
+
},
|
|
112
|
+
err => {
|
|
113
|
+
const tscCompileOnError = process.env.TSC_COMPILE_ON_ERROR === 'true';
|
|
114
|
+
if (tscCompileOnError) {
|
|
115
|
+
console.log(
|
|
116
|
+
chalk.yellow(
|
|
117
|
+
'Compiled with the following type errors (you may want to check these before deploying your app):\n'
|
|
118
|
+
)
|
|
119
|
+
);
|
|
120
|
+
printBuildError(err);
|
|
121
|
+
} else {
|
|
122
|
+
console.log(chalk.red('Failed to compile.\n'));
|
|
123
|
+
printBuildError(err);
|
|
124
|
+
process.exit(1);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
)
|
|
128
|
+
.catch(err => {
|
|
129
|
+
if (err && err.message) {
|
|
130
|
+
console.log(err.message);
|
|
131
|
+
}
|
|
132
|
+
process.exit(1);
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
// Create the production build and print the deployment instructions.
|
|
136
|
+
function build(previousFileSizes) {
|
|
137
|
+
console.log('Creating an optimized production build...');
|
|
138
|
+
|
|
139
|
+
const compiler = webpack(config);
|
|
140
|
+
return new Promise((resolve, reject) => {
|
|
141
|
+
compiler.run((err, stats) => {
|
|
142
|
+
let messages;
|
|
143
|
+
if (err) {
|
|
144
|
+
if (!err.message) {
|
|
145
|
+
return reject(err);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
let errMessage = err.message;
|
|
149
|
+
|
|
150
|
+
// Add additional information for postcss errors
|
|
151
|
+
if (Object.prototype.hasOwnProperty.call(err, 'postcssNode')) {
|
|
152
|
+
errMessage +=
|
|
153
|
+
'\nCompileError: Begins at CSS selector ' +
|
|
154
|
+
err['postcssNode'].selector;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
messages = formatWebpackMessages({
|
|
158
|
+
errors: [errMessage],
|
|
159
|
+
warnings: [],
|
|
160
|
+
});
|
|
161
|
+
} else {
|
|
162
|
+
messages = formatWebpackMessages(
|
|
163
|
+
stats.toJson({ all: false, warnings: true, errors: true })
|
|
164
|
+
);
|
|
165
|
+
}
|
|
166
|
+
if (messages.errors.length) {
|
|
167
|
+
// Only keep the first error. Others are often indicative
|
|
168
|
+
// of the same problem, but confuse the reader with noise.
|
|
169
|
+
if (messages.errors.length > 1) {
|
|
170
|
+
messages.errors.length = 1;
|
|
171
|
+
}
|
|
172
|
+
return reject(new Error(messages.errors.join('\n\n')));
|
|
173
|
+
}
|
|
174
|
+
if (
|
|
175
|
+
process.env.CI &&
|
|
176
|
+
(typeof process.env.CI !== 'string' ||
|
|
177
|
+
process.env.CI.toLowerCase() !== 'false') &&
|
|
178
|
+
messages.warnings.length
|
|
179
|
+
) {
|
|
180
|
+
console.log(
|
|
181
|
+
chalk.yellow(
|
|
182
|
+
'\nTreating warnings as errors because process.env.CI = true.\n' +
|
|
183
|
+
'Most CI servers set it automatically.\n'
|
|
184
|
+
)
|
|
185
|
+
);
|
|
186
|
+
return reject(new Error(messages.warnings.join('\n\n')));
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
const resolveArgs = {
|
|
190
|
+
stats,
|
|
191
|
+
previousFileSizes,
|
|
192
|
+
warnings: messages.warnings,
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
if (writeStatsJson) {
|
|
196
|
+
return bfj
|
|
197
|
+
.write(paths.appBuild + '/bundle-stats.json', stats.toJson())
|
|
198
|
+
.then(() => resolve(resolveArgs))
|
|
199
|
+
.catch(error => reject(new Error(error)));
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
return resolve(resolveArgs);
|
|
203
|
+
});
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
function copyPublicFolder() {
|
|
208
|
+
fs.copySync(paths.appPublic, paths.appBuild, {
|
|
209
|
+
dereference: true,
|
|
210
|
+
filter: file => file !== paths.appHtml,
|
|
211
|
+
});
|
|
212
|
+
}
|
package/scripts/lib.js
ADDED
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
// Do this as the first thing so that any code reading it knows the right env.
|
|
2
|
+
process.env.BABEL_ENV = 'production'
|
|
3
|
+
process.env.NODE_ENV = 'production'
|
|
4
|
+
|
|
5
|
+
// Makes the script crash on unhandled rejections instead of silently
|
|
6
|
+
// ignoring them. In the future, promise rejections that are not handled will
|
|
7
|
+
// terminate the Node.js process with a non-zero exit code.
|
|
8
|
+
process.on('unhandledRejection', (err) => {
|
|
9
|
+
throw err
|
|
10
|
+
})
|
|
11
|
+
|
|
12
|
+
// Ensure environment variables are read.
|
|
13
|
+
require('../config/env')
|
|
14
|
+
|
|
15
|
+
const path = require('path')
|
|
16
|
+
const chalk = require('react-dev-utils/chalk')
|
|
17
|
+
const fs = require('fs-extra')
|
|
18
|
+
const bfj = require('bfj')
|
|
19
|
+
const webpack = require('webpack')
|
|
20
|
+
const configFactory = require('../config/webpack.config')
|
|
21
|
+
const paths = require('../config/paths')
|
|
22
|
+
const checkRequiredFiles = require('react-dev-utils/checkRequiredFiles')
|
|
23
|
+
const formatWebpackMessages = require('react-dev-utils/formatWebpackMessages')
|
|
24
|
+
const printHostingInstructions = require('react-dev-utils/printHostingInstructions')
|
|
25
|
+
const FileSizeReporter = require('react-dev-utils/FileSizeReporter')
|
|
26
|
+
const printBuildError = require('react-dev-utils/printBuildError')
|
|
27
|
+
|
|
28
|
+
const measureFileSizesBeforeBuild = FileSizeReporter.measureFileSizesBeforeBuild
|
|
29
|
+
const printFileSizesAfterBuild = FileSizeReporter.printFileSizesAfterBuild
|
|
30
|
+
const useYarn = fs.existsSync(paths.yarnLockFile)
|
|
31
|
+
|
|
32
|
+
// These sizes are pretty large. We'll warn for bundles exceeding them.
|
|
33
|
+
const WARN_AFTER_BUNDLE_GZIP_SIZE = 512 * 1024
|
|
34
|
+
const WARN_AFTER_CHUNK_GZIP_SIZE = 1024 * 1024
|
|
35
|
+
|
|
36
|
+
const isInteractive = process.stdout.isTTY
|
|
37
|
+
|
|
38
|
+
// Warn and crash if required files are missing
|
|
39
|
+
if (!checkRequiredFiles([paths.appHtml, paths.appIndexJs])) {
|
|
40
|
+
process.exit(1)
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const argv = process.argv.slice(2)
|
|
44
|
+
const writeStatsJson = argv.indexOf('--stats') !== -1
|
|
45
|
+
|
|
46
|
+
// Generate configuration
|
|
47
|
+
const config = configFactory('lib')
|
|
48
|
+
|
|
49
|
+
// We require that you explicitly set browsers and do not fall back to
|
|
50
|
+
// browserslist defaults.
|
|
51
|
+
const { checkBrowsers } = require('react-dev-utils/browsersHelper')
|
|
52
|
+
checkBrowsers(paths.appPath, isInteractive)
|
|
53
|
+
.then(() => {
|
|
54
|
+
// First, read the current file sizes in build directory.
|
|
55
|
+
// This lets us display how much they changed later.
|
|
56
|
+
return measureFileSizesBeforeBuild(paths.libBuild)
|
|
57
|
+
})
|
|
58
|
+
.then((previousFileSizes) => {
|
|
59
|
+
// Remove all content but keep the directory so that
|
|
60
|
+
// if you're in it, you don't end up in Trash
|
|
61
|
+
fs.emptyDirSync(paths.libBuild)
|
|
62
|
+
// Merge with the public folder
|
|
63
|
+
// Start the webpack build
|
|
64
|
+
return build(previousFileSizes)
|
|
65
|
+
})
|
|
66
|
+
.then(
|
|
67
|
+
({ stats, previousFileSizes, warnings }) => {
|
|
68
|
+
if (warnings.length) {
|
|
69
|
+
console.log(chalk.yellow('Compiled with warnings.\n'))
|
|
70
|
+
console.log(warnings.join('\n\n'))
|
|
71
|
+
console.log(
|
|
72
|
+
'\nSearch for the ' +
|
|
73
|
+
chalk.underline(chalk.yellow('keywords')) +
|
|
74
|
+
' to learn more about each warning.'
|
|
75
|
+
)
|
|
76
|
+
console.log(
|
|
77
|
+
'To ignore, add ' +
|
|
78
|
+
chalk.cyan('// eslint-disable-next-line') +
|
|
79
|
+
' to the line before.\n'
|
|
80
|
+
)
|
|
81
|
+
} else {
|
|
82
|
+
console.log(chalk.green('Compiled successfully.\n'))
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
console.log('File sizes after gzip:\n')
|
|
86
|
+
printFileSizesAfterBuild(
|
|
87
|
+
stats,
|
|
88
|
+
previousFileSizes,
|
|
89
|
+
paths.libBuild,
|
|
90
|
+
WARN_AFTER_BUNDLE_GZIP_SIZE,
|
|
91
|
+
WARN_AFTER_CHUNK_GZIP_SIZE
|
|
92
|
+
)
|
|
93
|
+
console.log()
|
|
94
|
+
|
|
95
|
+
const appPackage = require(paths.appPackageJson)
|
|
96
|
+
const publicUrl = paths.publicUrlOrPath
|
|
97
|
+
const publicPath = config.output.publicPath
|
|
98
|
+
const buildFolder = path.relative(process.cwd(), paths.libBuild)
|
|
99
|
+
printHostingInstructions(
|
|
100
|
+
appPackage,
|
|
101
|
+
publicUrl,
|
|
102
|
+
publicPath,
|
|
103
|
+
buildFolder,
|
|
104
|
+
useYarn
|
|
105
|
+
)
|
|
106
|
+
},
|
|
107
|
+
(err) => {
|
|
108
|
+
const tscCompileOnError = process.env.TSC_COMPILE_ON_ERROR === 'true'
|
|
109
|
+
if (tscCompileOnError) {
|
|
110
|
+
console.log(
|
|
111
|
+
chalk.yellow(
|
|
112
|
+
'Compiled with the following type errors (you may want to check these before deploying your app):\n'
|
|
113
|
+
)
|
|
114
|
+
)
|
|
115
|
+
printBuildError(err)
|
|
116
|
+
} else {
|
|
117
|
+
console.log(chalk.red('Failed to compile.\n'))
|
|
118
|
+
printBuildError(err)
|
|
119
|
+
process.exit(1)
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
)
|
|
123
|
+
.catch((err) => {
|
|
124
|
+
if (err && err.message) {
|
|
125
|
+
console.log(err.message)
|
|
126
|
+
}
|
|
127
|
+
process.exit(1)
|
|
128
|
+
})
|
|
129
|
+
|
|
130
|
+
// Create the production build and print the deployment instructions.
|
|
131
|
+
function build(previousFileSizes) {
|
|
132
|
+
console.log('Creating an optimized production build...')
|
|
133
|
+
|
|
134
|
+
const compiler = webpack(config)
|
|
135
|
+
return new Promise((resolve, reject) => {
|
|
136
|
+
compiler.run((err, stats) => {
|
|
137
|
+
let messages
|
|
138
|
+
if (err) {
|
|
139
|
+
if (!err.message) {
|
|
140
|
+
return reject(err)
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
let errMessage = err.message
|
|
144
|
+
|
|
145
|
+
// Add additional information for postcss errors
|
|
146
|
+
if (Object.prototype.hasOwnProperty.call(err, 'postcssNode')) {
|
|
147
|
+
errMessage +=
|
|
148
|
+
'\nCompileError: Begins at CSS selector ' +
|
|
149
|
+
err['postcssNode'].selector
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
messages = formatWebpackMessages({
|
|
153
|
+
errors: [errMessage],
|
|
154
|
+
warnings: [],
|
|
155
|
+
})
|
|
156
|
+
} else {
|
|
157
|
+
messages = formatWebpackMessages(
|
|
158
|
+
stats.toJson({ all: false, warnings: true, errors: true })
|
|
159
|
+
)
|
|
160
|
+
}
|
|
161
|
+
if (messages.errors.length) {
|
|
162
|
+
// Only keep the first error. Others are often indicative
|
|
163
|
+
// of the same problem, but confuse the reader with noise.
|
|
164
|
+
if (messages.errors.length > 1) {
|
|
165
|
+
messages.errors.length = 1
|
|
166
|
+
}
|
|
167
|
+
return reject(new Error(messages.errors.join('\n\n')))
|
|
168
|
+
}
|
|
169
|
+
if (
|
|
170
|
+
process.env.CI &&
|
|
171
|
+
(typeof process.env.CI !== 'string' ||
|
|
172
|
+
process.env.CI.toLowerCase() !== 'false') &&
|
|
173
|
+
messages.warnings.length
|
|
174
|
+
) {
|
|
175
|
+
console.log(
|
|
176
|
+
chalk.yellow(
|
|
177
|
+
'\nTreating warnings as errors because process.env.CI = true.\n' +
|
|
178
|
+
'Most CI servers set it automatically.\n'
|
|
179
|
+
)
|
|
180
|
+
)
|
|
181
|
+
return reject(new Error(messages.warnings.join('\n\n')))
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
const resolveArgs = {
|
|
185
|
+
stats,
|
|
186
|
+
previousFileSizes,
|
|
187
|
+
warnings: messages.warnings,
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
if (writeStatsJson) {
|
|
191
|
+
return bfj
|
|
192
|
+
.write(paths.libBuild + '/bundle-stats.json', stats.toJson())
|
|
193
|
+
.then(() => resolve(resolveArgs))
|
|
194
|
+
.catch((error) => reject(new Error(error)))
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
return resolve(resolveArgs)
|
|
198
|
+
})
|
|
199
|
+
})
|
|
200
|
+
}
|