@seamlessdocs/payment-modals 1.0.38
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/.babelrc +13 -0
- package/.eslintrc.json +11 -0
- package/.idea/PaymentModals.iml +8 -0
- package/.idea/codeStyles/Project.xml +44 -0
- package/.idea/codeStyles/codeStyleConfig.xml +5 -0
- package/.idea/inspectionProfiles/Project_Default.xml +6 -0
- package/.idea/misc.xml +6 -0
- package/.idea/modules.xml +8 -0
- package/.idea/vcs.xml +6 -0
- package/.prettierrc +4 -0
- package/README.md +1 -0
- package/build/payment-modals.js +52 -0
- package/config/env.js +93 -0
- package/config/jest/cssTransform.js +14 -0
- package/config/jest/fileTransform.js +40 -0
- package/config/modules.js +88 -0
- package/config/paths.js +90 -0
- package/config/pnpTs.js +35 -0
- package/config/webpack.config.js +656 -0
- package/config/webpackDevServer.config.js +104 -0
- package/index.css +11 -0
- package/index.html +137 -0
- package/package.json +58 -0
- package/scripts/build.js +191 -0
- package/scripts/start.js +145 -0
- package/scripts/test.js +53 -0
- package/src/Components/ACHPaymentModal/ACHPaymentModal.module.css +118 -0
- package/src/Components/ACHPaymentModal/Form/FieldContainer/FieldContainer.module.css +40 -0
- package/src/Components/ACHPaymentModal/Form/FieldContainer/index.jsx +60 -0
- package/src/Components/ACHPaymentModal/Form/Form.module.css +81 -0
- package/src/Components/ACHPaymentModal/Form/index.jsx +189 -0
- package/src/Components/ACHPaymentModal/index.jsx +83 -0
- package/src/Components/ChooseModal/ChooseModal.module.css +114 -0
- package/src/Components/ChooseModal/index.jsx +34 -0
- package/src/Components/EmptyModal/index.jsx +7 -0
- package/src/Components/ErrorModal/ErrorModal.module.css +64 -0
- package/src/Components/ErrorModal/index.jsx +35 -0
- package/src/Components/ErrorOptionalModal/index.jsx +9 -0
- package/src/Components/Modal/Modal.module.css +29 -0
- package/src/Components/Modal/index.jsx +13 -0
- package/src/Components/PayNowModal/index.jsx +27 -0
- package/src/Components/ProcessingModal/ProcessingModal.module.css +50 -0
- package/src/Components/ProcessingModal/index.jsx +25 -0
- package/src/Components/SelectPaymentModal/SelectPaymentModal.module.css +212 -0
- package/src/Components/SelectPaymentModal/index.jsx +117 -0
- package/src/Components/SuccessModal/SuccessModal.module.css +34 -0
- package/src/Components/SuccessModal/index.jsx +23 -0
- package/src/OpenViewStyles.css +16 -0
- package/src/assets/img/back.svg +3 -0
- package/src/assets/img/bank-account.svg +7 -0
- package/src/assets/img/credit-card.svg +36 -0
- package/src/assets/img/error-icon.svg +1 -0
- package/src/assets/img/error.svg +3 -0
- package/src/assets/img/loader.svg +3 -0
- package/src/assets/img/lock-icon.svg +3 -0
- package/src/assets/img/logo.svg +6 -0
- package/src/assets/img/processing.gif +0 -0
- package/src/assets/img/success.svg +4 -0
- package/src/assets/img/valid-icon.svg +1 -0
- package/src/index.jsx +93 -0
- package/webpack.config.js +78 -0
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const errorOverlayMiddleware = require('react-dev-utils/errorOverlayMiddleware');
|
|
4
|
+
const evalSourceMapMiddleware = require('react-dev-utils/evalSourceMapMiddleware');
|
|
5
|
+
const noopServiceWorkerMiddleware = require('react-dev-utils/noopServiceWorkerMiddleware');
|
|
6
|
+
const ignoredFiles = require('react-dev-utils/ignoredFiles');
|
|
7
|
+
const paths = require('./paths');
|
|
8
|
+
const fs = require('fs');
|
|
9
|
+
|
|
10
|
+
const protocol = process.env.HTTPS === 'true' ? 'https' : 'http';
|
|
11
|
+
const host = process.env.HOST || '0.0.0.0';
|
|
12
|
+
|
|
13
|
+
module.exports = function(proxy, allowedHost) {
|
|
14
|
+
return {
|
|
15
|
+
// WebpackDevServer 2.4.3 introduced a security fix that prevents remote
|
|
16
|
+
// websites from potentially accessing local content through DNS rebinding:
|
|
17
|
+
// https://github.com/webpack/webpack-dev-server/issues/887
|
|
18
|
+
// https://medium.com/webpack/webpack-dev-server-middleware-security-issues-1489d950874a
|
|
19
|
+
// However, it made several existing use cases such as development in cloud
|
|
20
|
+
// environment or subdomains in development significantly more complicated:
|
|
21
|
+
// https://github.com/facebook/create-react-app/issues/2271
|
|
22
|
+
// https://github.com/facebook/create-react-app/issues/2233
|
|
23
|
+
// While we're investigating better solutions, for now we will take a
|
|
24
|
+
// compromise. Since our WDS configuration only serves files in the `public`
|
|
25
|
+
// folder we won't consider accessing them a vulnerability. However, if you
|
|
26
|
+
// use the `proxy` feature, it gets more dangerous because it can expose
|
|
27
|
+
// remote code execution vulnerabilities in backends like Django and Rails.
|
|
28
|
+
// So we will disable the host check normally, but enable it if you have
|
|
29
|
+
// specified the `proxy` setting. Finally, we let you override it if you
|
|
30
|
+
// really know what you're doing with a special environment variable.
|
|
31
|
+
disableHostCheck:
|
|
32
|
+
!proxy || process.env.DANGEROUSLY_DISABLE_HOST_CHECK === 'true',
|
|
33
|
+
// Enable gzip compression of generated files.
|
|
34
|
+
compress: true,
|
|
35
|
+
// Silence WebpackDevServer's own logs since they're generally not useful.
|
|
36
|
+
// It will still show compile warnings and errors with this setting.
|
|
37
|
+
clientLogLevel: 'none',
|
|
38
|
+
// By default WebpackDevServer serves physical files from current directory
|
|
39
|
+
// in addition to all the virtual build products that it serves from memory.
|
|
40
|
+
// This is confusing because those files won’t automatically be available in
|
|
41
|
+
// production build folder unless we copy them. However, copying the whole
|
|
42
|
+
// project directory is dangerous because we may expose sensitive files.
|
|
43
|
+
// Instead, we establish a convention that only files in `public` directory
|
|
44
|
+
// get served. Our build script will copy `public` into the `build` folder.
|
|
45
|
+
// In `index.html`, you can get URL of `public` folder with %PUBLIC_URL%:
|
|
46
|
+
// <link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico">
|
|
47
|
+
// In JavaScript code, you can access it with `process.env.PUBLIC_URL`.
|
|
48
|
+
// Note that we only recommend to use `public` folder as an escape hatch
|
|
49
|
+
// for files like `favicon.ico`, `manifest.json`, and libraries that are
|
|
50
|
+
// for some reason broken when imported through Webpack. If you just want to
|
|
51
|
+
// use an image, put it in `src` and `import` it from JavaScript instead.
|
|
52
|
+
contentBase: paths.appPublic,
|
|
53
|
+
// By default files from `contentBase` will not trigger a page reload.
|
|
54
|
+
watchContentBase: true,
|
|
55
|
+
// Enable hot reloading server. It will provide /sockjs-node/ endpoint
|
|
56
|
+
// for the WebpackDevServer client so it can learn when the files were
|
|
57
|
+
// updated. The WebpackDevServer client is included as an entry point
|
|
58
|
+
// in the Webpack development configuration. Note that only changes
|
|
59
|
+
// to CSS are currently hot reloaded. JS changes will refresh the browser.
|
|
60
|
+
hot: true,
|
|
61
|
+
// It is important to tell WebpackDevServer to use the same "root" path
|
|
62
|
+
// as we specified in the config. In development, we always serve from /.
|
|
63
|
+
publicPath: '/',
|
|
64
|
+
// WebpackDevServer is noisy by default so we emit custom message instead
|
|
65
|
+
// by listening to the compiler events with `compiler.hooks[...].tap` calls above.
|
|
66
|
+
quiet: true,
|
|
67
|
+
// Reportedly, this avoids CPU overload on some systems.
|
|
68
|
+
// https://github.com/facebook/create-react-app/issues/293
|
|
69
|
+
// src/node_modules is not ignored to support absolute imports
|
|
70
|
+
// https://github.com/facebook/create-react-app/issues/1065
|
|
71
|
+
watchOptions: {
|
|
72
|
+
ignored: ignoredFiles(paths.appSrc),
|
|
73
|
+
},
|
|
74
|
+
// Enable HTTPS if the HTTPS environment variable is set to 'true'
|
|
75
|
+
https: protocol === 'https',
|
|
76
|
+
host,
|
|
77
|
+
overlay: false,
|
|
78
|
+
historyApiFallback: {
|
|
79
|
+
// Paths with dots should still use the history fallback.
|
|
80
|
+
// See https://github.com/facebook/create-react-app/issues/387.
|
|
81
|
+
disableDotRule: true,
|
|
82
|
+
},
|
|
83
|
+
public: allowedHost,
|
|
84
|
+
proxy,
|
|
85
|
+
before(app, server) {
|
|
86
|
+
if (fs.existsSync(paths.proxySetup)) {
|
|
87
|
+
// This registers user provided middleware for proxy reasons
|
|
88
|
+
require(paths.proxySetup)(app);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// This lets us fetch source contents from webpack for the error overlay
|
|
92
|
+
app.use(evalSourceMapMiddleware(server));
|
|
93
|
+
// This lets us open files from the runtime error overlay.
|
|
94
|
+
app.use(errorOverlayMiddleware());
|
|
95
|
+
|
|
96
|
+
// This service worker file is effectively a 'no-op' that will reset any
|
|
97
|
+
// previous service worker registered for the same host:port combination.
|
|
98
|
+
// We do this in development to avoid hitting the production cache if
|
|
99
|
+
// it used the same host and port.
|
|
100
|
+
// https://github.com/facebook/create-react-app/issues/2272#issuecomment-302832432
|
|
101
|
+
app.use(noopServiceWorkerMiddleware());
|
|
102
|
+
},
|
|
103
|
+
};
|
|
104
|
+
};
|
package/index.css
ADDED
package/index.html
ADDED
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8" />
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
6
|
+
<link rel="stylesheet" href="index.css" />
|
|
7
|
+
<title>Payment Modals</title>
|
|
8
|
+
</head>
|
|
9
|
+
<body>
|
|
10
|
+
<div class="links">
|
|
11
|
+
<a href="#" id="chooseModal">Open "Choose" modal</a>
|
|
12
|
+
<a href="#" id="processingModal">Open "Processing Payment" modal</a>
|
|
13
|
+
<a href="#" id="errorModal">Open "Error Processing Payment" modal (Retry)</a>
|
|
14
|
+
<a href="#" id="errorOptionalModal">Open "Error Processing Payment" modal (Skip/Retry)</a>
|
|
15
|
+
<a href="#" id="successModal">Open "Successful Payment" modal</a>
|
|
16
|
+
<a href="#" id="selectPaymentModal">Open "Select Payment" modal</a>
|
|
17
|
+
<a href="#" id="achPaymentModal">Open "ACH Payment" modal</a>
|
|
18
|
+
<a href="#" id="none">Close</a>
|
|
19
|
+
</div>
|
|
20
|
+
<div id="payment-modal"></div>
|
|
21
|
+
<script src="https://core.spreedly.com/iframe/express-2.min.js"></script>
|
|
22
|
+
<script src="./build/payment-modals.js"></script>
|
|
23
|
+
<script>
|
|
24
|
+
const triggers = document.querySelectorAll('.links a');
|
|
25
|
+
const callbacks = {
|
|
26
|
+
withoutPay: () => {
|
|
27
|
+
console.log('withoutPay');
|
|
28
|
+
},
|
|
29
|
+
withPay: () => {
|
|
30
|
+
console.log('withPay');
|
|
31
|
+
},
|
|
32
|
+
close: () => {
|
|
33
|
+
console.log('close');
|
|
34
|
+
},
|
|
35
|
+
skip: () => {
|
|
36
|
+
console.log('skip');
|
|
37
|
+
},
|
|
38
|
+
retry: () => {
|
|
39
|
+
console.log('retry');
|
|
40
|
+
},
|
|
41
|
+
successModalContinue: () => {
|
|
42
|
+
console.log('successModalContinue');
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
triggers[0].addEventListener('click', event => {
|
|
47
|
+
window.handlePaymentModal.chooseModal({
|
|
48
|
+
title: 'Pay now or later',
|
|
49
|
+
description:
|
|
50
|
+
'The cost oFFFFF this submission is <b>$24.24</b> including the processing fee.',
|
|
51
|
+
withPayText: 'Pay Now',
|
|
52
|
+
callbacks: {
|
|
53
|
+
withoutPay: callbacks.withoutPay,
|
|
54
|
+
withPay: callbacks.withPay,
|
|
55
|
+
close: callbacks.close
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
triggers[1].addEventListener('click', event => {
|
|
60
|
+
window.handlePaymentModal.processingModal();
|
|
61
|
+
});
|
|
62
|
+
triggers[2].addEventListener('click', event => {
|
|
63
|
+
window.handlePaymentModal.errorModal({
|
|
64
|
+
isOptional: false,
|
|
65
|
+
callbacks: {
|
|
66
|
+
retry: callbacks.retry,
|
|
67
|
+
close: callbacks.close
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
triggers[3].addEventListener('click', event => {
|
|
72
|
+
window.handlePaymentModal.errorModal({
|
|
73
|
+
isOptional: true,
|
|
74
|
+
errorText: 'error',
|
|
75
|
+
callbacks: {
|
|
76
|
+
skip: callbacks.skip,
|
|
77
|
+
retry: callbacks.retry,
|
|
78
|
+
close: callbacks.close
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
triggers[4].addEventListener('click', event => {
|
|
83
|
+
window.handlePaymentModal.successModal({ description: 'my text' });
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
triggers[5].addEventListener('click', event => {
|
|
87
|
+
window.handlePaymentModal.selectPaymentModal({
|
|
88
|
+
isPaymentRequired: false,
|
|
89
|
+
bankAccountValue: 25,
|
|
90
|
+
bankAccountFeeValue: 0.6,
|
|
91
|
+
creditCardValue: 25,
|
|
92
|
+
creditCardFeeValue: 1.6,
|
|
93
|
+
isCreditCardFeeEnable: true,
|
|
94
|
+
isBankAccountFeeEnable: false,
|
|
95
|
+
callbacks: {
|
|
96
|
+
onPayByBank: () => {
|
|
97
|
+
console.log('pay by bank');
|
|
98
|
+
},
|
|
99
|
+
onPayByCreditCard: () => {
|
|
100
|
+
console.log('pay by credit card');
|
|
101
|
+
},
|
|
102
|
+
onClose: () => {
|
|
103
|
+
console.log('close');
|
|
104
|
+
},
|
|
105
|
+
onSkipPayment: () => {
|
|
106
|
+
console.log('onSkipPayment');
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
triggers[6].addEventListener('click', event => {
|
|
113
|
+
window.handlePaymentModal.achPaymentModal({
|
|
114
|
+
amount: 22,
|
|
115
|
+
totalAmount: 24.24,
|
|
116
|
+
feeAmount: 2.24,
|
|
117
|
+
description: 'Text from the description field in the gateway details modal.',
|
|
118
|
+
feeName: 'ololo',
|
|
119
|
+
callbacks: {
|
|
120
|
+
onPay: (...args) => {
|
|
121
|
+
setTimeout(() => {
|
|
122
|
+
alert(JSON.stringify(args, null, 2));
|
|
123
|
+
}, 400);
|
|
124
|
+
},
|
|
125
|
+
onClose: () => {
|
|
126
|
+
console.log('close');
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
triggers[7].addEventListener('click', event => {
|
|
133
|
+
window.handlePaymentModal.none();
|
|
134
|
+
});
|
|
135
|
+
</script>
|
|
136
|
+
</body>
|
|
137
|
+
</html>
|
package/package.json
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@seamlessdocs/payment-modals",
|
|
3
|
+
"version": "1.0.38",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "build/payment-modals.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"start": "webpack-dev-server --mode development",
|
|
8
|
+
"dev": "webpack --mode development ./src/index.jsx --output ./build/payment-modals.js",
|
|
9
|
+
"build": "webpack --mode production ./src/index.jsx --output ./build/payment-modals.js"
|
|
10
|
+
},
|
|
11
|
+
"devDependencies": {
|
|
12
|
+
"@babel/core": "^7.6.2",
|
|
13
|
+
"@babel/plugin-syntax-class-properties": "^7.2.0",
|
|
14
|
+
"@babel/plugin-transform-runtime": "^7.4.4",
|
|
15
|
+
"@babel/preset-env": "^7.6.2",
|
|
16
|
+
"@babel/preset-react": "^7.0.0",
|
|
17
|
+
"@babel/runtime": "^7.4.5",
|
|
18
|
+
"babel-eslint": "^10.0.1",
|
|
19
|
+
"babel-loader": "^8.0.6",
|
|
20
|
+
"babel-plugin-transform-class-properties": "^6.24.1",
|
|
21
|
+
"css-loader": "^2.1.1",
|
|
22
|
+
"eslint": "^5.16.0",
|
|
23
|
+
"eslint-config-airbnb": "^17.1.0",
|
|
24
|
+
"eslint-config-prettier": "^4.2.0",
|
|
25
|
+
"eslint-plugin-import": "^2.14.0",
|
|
26
|
+
"eslint-plugin-jsx-a11y": "^6.1.1",
|
|
27
|
+
"eslint-plugin-prettier": "^3.0.1",
|
|
28
|
+
"eslint-plugin-react": "^7.13.0",
|
|
29
|
+
"extract-text-webpack-plugin": "^3.0.2",
|
|
30
|
+
"file-loader": "^3.0.1",
|
|
31
|
+
"image-webpack-loader": "^6.0.0",
|
|
32
|
+
"mini-css-extract-plugin": "^0.5.0",
|
|
33
|
+
"node-sass": "^4.11.0",
|
|
34
|
+
"prettier": "^1.17.0",
|
|
35
|
+
"sass-loader": "^7.1.0",
|
|
36
|
+
"style-loader": "^0.23.1",
|
|
37
|
+
"svg-inline-loader": "^0.8.0",
|
|
38
|
+
"url-loader": "^1.1.2",
|
|
39
|
+
"webpack": "^4.41.0",
|
|
40
|
+
"webpack-cli": "^3.3.9",
|
|
41
|
+
"webpack-dev-server": "^3.2.1"
|
|
42
|
+
},
|
|
43
|
+
"dependencies": {
|
|
44
|
+
"babel-plugin-import": "^1.11.0",
|
|
45
|
+
"base64-image-loader": "^1.2.1",
|
|
46
|
+
"classnames": "^2.2.6",
|
|
47
|
+
"download": "^7.1.0",
|
|
48
|
+
"formik": "^2.1.5",
|
|
49
|
+
"postcss-loader": "^3.0.0",
|
|
50
|
+
"postcss-nested": "^4.1.2",
|
|
51
|
+
"prop-types": "^15.7.2",
|
|
52
|
+
"react": "^16.10.1",
|
|
53
|
+
"react-dom": "^16.10.1",
|
|
54
|
+
"react-inlinesvg": "^1.1.7",
|
|
55
|
+
"react-select": "^3.1.0",
|
|
56
|
+
"react-tooltip": "^4.2.9"
|
|
57
|
+
}
|
|
58
|
+
}
|
package/scripts/build.js
ADDED
|
@@ -0,0 +1,191 @@
|
|
|
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 webpack = require('webpack');
|
|
22
|
+
const configFactory = require('../config/webpack.config');
|
|
23
|
+
const paths = require('../config/paths');
|
|
24
|
+
const checkRequiredFiles = require('react-dev-utils/checkRequiredFiles');
|
|
25
|
+
const formatWebpackMessages = require('react-dev-utils/formatWebpackMessages');
|
|
26
|
+
const printHostingInstructions = require('react-dev-utils/printHostingInstructions');
|
|
27
|
+
const FileSizeReporter = require('react-dev-utils/FileSizeReporter');
|
|
28
|
+
const printBuildError = require('react-dev-utils/printBuildError');
|
|
29
|
+
|
|
30
|
+
const measureFileSizesBeforeBuild =
|
|
31
|
+
FileSizeReporter.measureFileSizesBeforeBuild;
|
|
32
|
+
const printFileSizesAfterBuild = FileSizeReporter.printFileSizesAfterBuild;
|
|
33
|
+
const useYarn = fs.existsSync(paths.yarnLockFile);
|
|
34
|
+
|
|
35
|
+
// These sizes are pretty large. We'll warn for bundles exceeding them.
|
|
36
|
+
const WARN_AFTER_BUNDLE_GZIP_SIZE = 512 * 1024;
|
|
37
|
+
const WARN_AFTER_CHUNK_GZIP_SIZE = 1024 * 1024;
|
|
38
|
+
|
|
39
|
+
const isInteractive = process.stdout.isTTY;
|
|
40
|
+
|
|
41
|
+
// Warn and crash if required files are missing
|
|
42
|
+
if (!checkRequiredFiles([paths.appHtml, paths.appIndexJs])) {
|
|
43
|
+
process.exit(1);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// Generate configuration
|
|
47
|
+
const config = configFactory('production');
|
|
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.appBuild);
|
|
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.appBuild);
|
|
62
|
+
// Merge with the public folder
|
|
63
|
+
copyPublicFolder();
|
|
64
|
+
// Start the webpack build
|
|
65
|
+
return build(previousFileSizes);
|
|
66
|
+
})
|
|
67
|
+
.then(
|
|
68
|
+
({ stats, previousFileSizes, warnings }) => {
|
|
69
|
+
if (warnings.length) {
|
|
70
|
+
console.log(chalk.yellow('Compiled with warnings.\n'));
|
|
71
|
+
console.log(warnings.join('\n\n'));
|
|
72
|
+
console.log(
|
|
73
|
+
'\nSearch for the ' +
|
|
74
|
+
chalk.underline(chalk.yellow('keywords')) +
|
|
75
|
+
' to learn more about each warning.'
|
|
76
|
+
);
|
|
77
|
+
console.log(
|
|
78
|
+
'To ignore, add ' +
|
|
79
|
+
chalk.cyan('// eslint-disable-next-line') +
|
|
80
|
+
' to the line before.\n'
|
|
81
|
+
);
|
|
82
|
+
} else {
|
|
83
|
+
console.log(chalk.green('Compiled successfully.\n'));
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
console.log('File sizes after gzip:\n');
|
|
87
|
+
printFileSizesAfterBuild(
|
|
88
|
+
stats,
|
|
89
|
+
previousFileSizes,
|
|
90
|
+
paths.appBuild,
|
|
91
|
+
WARN_AFTER_BUNDLE_GZIP_SIZE,
|
|
92
|
+
WARN_AFTER_CHUNK_GZIP_SIZE
|
|
93
|
+
);
|
|
94
|
+
console.log();
|
|
95
|
+
|
|
96
|
+
const appPackage = require(paths.appPackageJson);
|
|
97
|
+
const publicUrl = paths.publicUrl;
|
|
98
|
+
const publicPath = config.output.publicPath;
|
|
99
|
+
const buildFolder = path.relative(process.cwd(), paths.appBuild);
|
|
100
|
+
printHostingInstructions(
|
|
101
|
+
appPackage,
|
|
102
|
+
publicUrl,
|
|
103
|
+
publicPath,
|
|
104
|
+
buildFolder,
|
|
105
|
+
useYarn
|
|
106
|
+
);
|
|
107
|
+
},
|
|
108
|
+
err => {
|
|
109
|
+
console.log(chalk.red('Failed to compile.\n'));
|
|
110
|
+
printBuildError(err);
|
|
111
|
+
process.exit(1);
|
|
112
|
+
}
|
|
113
|
+
)
|
|
114
|
+
.catch(err => {
|
|
115
|
+
if (err && err.message) {
|
|
116
|
+
console.log(err.message);
|
|
117
|
+
}
|
|
118
|
+
process.exit(1);
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
// Create the production build and print the deployment instructions.
|
|
122
|
+
function build(previousFileSizes) {
|
|
123
|
+
// We used to support resolving modules according to `NODE_PATH`.
|
|
124
|
+
// This now has been deprecated in favor of jsconfig/tsconfig.json
|
|
125
|
+
// This lets you use absolute paths in imports inside large monorepos:
|
|
126
|
+
if (process.env.NODE_PATH) {
|
|
127
|
+
console.log(
|
|
128
|
+
chalk.yellow(
|
|
129
|
+
'Setting NODE_PATH to resolve modules absolutely has been deprecated in favor of setting baseUrl in jsconfig.json (or tsconfig.json if you are using TypeScript) and will be removed in a future major release of create-react-app.'
|
|
130
|
+
)
|
|
131
|
+
);
|
|
132
|
+
console.log();
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
console.log('Creating an optimized production build...');
|
|
136
|
+
|
|
137
|
+
const compiler = webpack(config);
|
|
138
|
+
return new Promise((resolve, reject) => {
|
|
139
|
+
compiler.run((err, stats) => {
|
|
140
|
+
let messages;
|
|
141
|
+
if (err) {
|
|
142
|
+
if (!err.message) {
|
|
143
|
+
return reject(err);
|
|
144
|
+
}
|
|
145
|
+
messages = formatWebpackMessages({
|
|
146
|
+
errors: [err.message],
|
|
147
|
+
warnings: [],
|
|
148
|
+
});
|
|
149
|
+
} else {
|
|
150
|
+
messages = formatWebpackMessages(
|
|
151
|
+
stats.toJson({ all: false, warnings: true, errors: true })
|
|
152
|
+
);
|
|
153
|
+
}
|
|
154
|
+
if (messages.errors.length) {
|
|
155
|
+
// Only keep the first error. Others are often indicative
|
|
156
|
+
// of the same problem, but confuse the reader with noise.
|
|
157
|
+
if (messages.errors.length > 1) {
|
|
158
|
+
messages.errors.length = 1;
|
|
159
|
+
}
|
|
160
|
+
return reject(new Error(messages.errors.join('\n\n')));
|
|
161
|
+
}
|
|
162
|
+
if (
|
|
163
|
+
process.env.CI &&
|
|
164
|
+
(typeof process.env.CI !== 'string' ||
|
|
165
|
+
process.env.CI.toLowerCase() !== 'false') &&
|
|
166
|
+
messages.warnings.length
|
|
167
|
+
) {
|
|
168
|
+
console.log(
|
|
169
|
+
chalk.yellow(
|
|
170
|
+
'\nTreating warnings as errors because process.env.CI = true.\n' +
|
|
171
|
+
'Most CI servers set it automatically.\n'
|
|
172
|
+
)
|
|
173
|
+
);
|
|
174
|
+
return reject(new Error(messages.warnings.join('\n\n')));
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
return resolve({
|
|
178
|
+
stats,
|
|
179
|
+
previousFileSizes,
|
|
180
|
+
warnings: messages.warnings,
|
|
181
|
+
});
|
|
182
|
+
});
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
function copyPublicFolder() {
|
|
187
|
+
fs.copySync(paths.appPublic, paths.appBuild, {
|
|
188
|
+
dereference: true,
|
|
189
|
+
filter: file => file !== paths.appHtml,
|
|
190
|
+
});
|
|
191
|
+
}
|
package/scripts/start.js
ADDED
|
@@ -0,0 +1,145 @@
|
|
|
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 = 'development';
|
|
5
|
+
process.env.NODE_ENV = 'development';
|
|
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 fs = require('fs');
|
|
19
|
+
const chalk = require('react-dev-utils/chalk');
|
|
20
|
+
const webpack = require('webpack');
|
|
21
|
+
const WebpackDevServer = require('webpack-dev-server');
|
|
22
|
+
const clearConsole = require('react-dev-utils/clearConsole');
|
|
23
|
+
const checkRequiredFiles = require('react-dev-utils/checkRequiredFiles');
|
|
24
|
+
const {
|
|
25
|
+
choosePort,
|
|
26
|
+
createCompiler,
|
|
27
|
+
prepareProxy,
|
|
28
|
+
prepareUrls,
|
|
29
|
+
} = require('react-dev-utils/WebpackDevServerUtils');
|
|
30
|
+
const openBrowser = require('react-dev-utils/openBrowser');
|
|
31
|
+
const paths = require('../config/paths');
|
|
32
|
+
const configFactory = require('../config/webpack.config');
|
|
33
|
+
const createDevServerConfig = require('../config/webpackDevServer.config');
|
|
34
|
+
|
|
35
|
+
const useYarn = fs.existsSync(paths.yarnLockFile);
|
|
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
|
+
// Tools like Cloud9 rely on this.
|
|
44
|
+
const DEFAULT_PORT = parseInt(process.env.PORT, 10) || 3000;
|
|
45
|
+
const HOST = process.env.HOST || '0.0.0.0';
|
|
46
|
+
|
|
47
|
+
if (process.env.HOST) {
|
|
48
|
+
console.log(
|
|
49
|
+
chalk.cyan(
|
|
50
|
+
`Attempting to bind to HOST environment variable: ${chalk.yellow(
|
|
51
|
+
chalk.bold(process.env.HOST)
|
|
52
|
+
)}`
|
|
53
|
+
)
|
|
54
|
+
);
|
|
55
|
+
console.log(
|
|
56
|
+
`If this was unintentional, check that you haven't mistakenly set it in your shell.`
|
|
57
|
+
);
|
|
58
|
+
console.log(
|
|
59
|
+
`Learn more here: ${chalk.yellow('https://bit.ly/CRA-advanced-config')}`
|
|
60
|
+
);
|
|
61
|
+
console.log();
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// We require that you explicitly set browsers and do not fall back to
|
|
65
|
+
// browserslist defaults.
|
|
66
|
+
const { checkBrowsers } = require('react-dev-utils/browsersHelper');
|
|
67
|
+
checkBrowsers(paths.appPath, isInteractive)
|
|
68
|
+
.then(() => {
|
|
69
|
+
// We attempt to use the default port but if it is busy, we offer the user to
|
|
70
|
+
// run on a different port. `choosePort()` Promise resolves to the next free port.
|
|
71
|
+
return choosePort(HOST, DEFAULT_PORT);
|
|
72
|
+
})
|
|
73
|
+
.then(port => {
|
|
74
|
+
if (port == null) {
|
|
75
|
+
// We have not found a port.
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
const config = configFactory('development');
|
|
79
|
+
const protocol = process.env.HTTPS === 'true' ? 'https' : 'http';
|
|
80
|
+
const appName = require(paths.appPackageJson).name;
|
|
81
|
+
const useTypeScript = fs.existsSync(paths.appTsConfig);
|
|
82
|
+
const urls = prepareUrls(protocol, HOST, port);
|
|
83
|
+
const devSocket = {
|
|
84
|
+
warnings: warnings =>
|
|
85
|
+
devServer.sockWrite(devServer.sockets, 'warnings', warnings),
|
|
86
|
+
errors: errors =>
|
|
87
|
+
devServer.sockWrite(devServer.sockets, 'errors', errors),
|
|
88
|
+
};
|
|
89
|
+
// Create a webpack compiler that is configured with custom messages.
|
|
90
|
+
const compiler = createCompiler({
|
|
91
|
+
appName,
|
|
92
|
+
config,
|
|
93
|
+
devSocket,
|
|
94
|
+
urls,
|
|
95
|
+
useYarn,
|
|
96
|
+
useTypeScript,
|
|
97
|
+
webpack,
|
|
98
|
+
});
|
|
99
|
+
// Load proxy config
|
|
100
|
+
const proxySetting = require(paths.appPackageJson).proxy;
|
|
101
|
+
const proxyConfig = prepareProxy(proxySetting, paths.appPublic);
|
|
102
|
+
// Serve webpack assets generated by the compiler over a web server.
|
|
103
|
+
const serverConfig = createDevServerConfig(
|
|
104
|
+
proxyConfig,
|
|
105
|
+
urls.lanUrlForConfig
|
|
106
|
+
);
|
|
107
|
+
const devServer = new WebpackDevServer(compiler, serverConfig);
|
|
108
|
+
// Launch WebpackDevServer.
|
|
109
|
+
devServer.listen(port, HOST, err => {
|
|
110
|
+
if (err) {
|
|
111
|
+
return console.log(err);
|
|
112
|
+
}
|
|
113
|
+
if (isInteractive) {
|
|
114
|
+
clearConsole();
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// We used to support resolving modules according to `NODE_PATH`.
|
|
118
|
+
// This now has been deprecated in favor of jsconfig/tsconfig.json
|
|
119
|
+
// This lets you use absolute paths in imports inside large monorepos:
|
|
120
|
+
if (process.env.NODE_PATH) {
|
|
121
|
+
console.log(
|
|
122
|
+
chalk.yellow(
|
|
123
|
+
'Setting NODE_PATH to resolve modules absolutely has been deprecated in favor of setting baseUrl in jsconfig.json (or tsconfig.json if you are using TypeScript) and will be removed in a future major release of create-react-app.'
|
|
124
|
+
)
|
|
125
|
+
);
|
|
126
|
+
console.log();
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
console.log(chalk.cyan('Starting the development server...\n'));
|
|
130
|
+
openBrowser(urls.localUrlForBrowser);
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
['SIGINT', 'SIGTERM'].forEach(function(sig) {
|
|
134
|
+
process.on(sig, function() {
|
|
135
|
+
devServer.close();
|
|
136
|
+
process.exit();
|
|
137
|
+
});
|
|
138
|
+
});
|
|
139
|
+
})
|
|
140
|
+
.catch(err => {
|
|
141
|
+
if (err && err.message) {
|
|
142
|
+
console.log(err.message);
|
|
143
|
+
}
|
|
144
|
+
process.exit(1);
|
|
145
|
+
});
|