Commit ef2c151e authored by sunyihao's avatar sunyihao

项目初始化05

parent 2207e28b
'use strict'; const fs = require("fs");
const evalSourceMapMiddleware = require("react-dev-utils/evalSourceMapMiddleware");
const noopServiceWorkerMiddleware = require("react-dev-utils/noopServiceWorkerMiddleware");
const ignoredFiles = require("react-dev-utils/ignoredFiles");
const redirectServedPath = require("react-dev-utils/redirectServedPathMiddleware");
const paths = require("./paths");
const getHttpsConfig = require("./getHttpsConfig");
const fs = require('fs'); const host = process.env.HOST || "0.0.0.0";
const evalSourceMapMiddleware = require('react-dev-utils/evalSourceMapMiddleware');
const noopServiceWorkerMiddleware = require('react-dev-utils/noopServiceWorkerMiddleware');
const ignoredFiles = require('react-dev-utils/ignoredFiles');
const redirectServedPath = require('react-dev-utils/redirectServedPathMiddleware');
const paths = require('./paths');
const getHttpsConfig = require('./getHttpsConfig');
const host = process.env.HOST || '0.0.0.0';
const sockHost = process.env.WDS_SOCKET_HOST; const sockHost = process.env.WDS_SOCKET_HOST;
const sockPath = process.env.WDS_SOCKET_PATH; // default: '/ws' const sockPath = process.env.WDS_SOCKET_PATH; // default: '/ws'
const sockPort = process.env.WDS_SOCKET_PORT; const sockPort = process.env.WDS_SOCKET_PORT;
module.exports = function (proxy, allowedHost) { module.exports = function (proxy, allowedHost) {
const disableFirewall = const disableFirewall =
!proxy || process.env.DANGEROUSLY_DISABLE_HOST_CHECK === 'true'; !proxy || process.env.DANGEROUSLY_DISABLE_HOST_CHECK === "true";
return { return {
// WebpackDevServer 2.4.3 introduced a security fix that prevents remote // WebpackDevServer 2.4.3 introduced a security fix that prevents remote
// websites from potentially accessing local content through DNS rebinding: // websites from potentially accessing local content through DNS rebinding:
...@@ -35,11 +33,11 @@ module.exports = function (proxy, allowedHost) { ...@@ -35,11 +33,11 @@ module.exports = function (proxy, allowedHost) {
// really know what you're doing with a special environment variable. // really know what you're doing with a special environment variable.
// Note: ["localhost", ".localhost"] will support subdomains - but we might // Note: ["localhost", ".localhost"] will support subdomains - but we might
// want to allow setting the allowedHosts manually for more complex setups // want to allow setting the allowedHosts manually for more complex setups
allowedHosts: disableFirewall ? 'all' : [allowedHost], allowedHosts: disableFirewall ? "all" : [allowedHost],
headers: { headers: {
'Access-Control-Allow-Origin': '*', "Access-Control-Allow-Origin": "*",
'Access-Control-Allow-Methods': '*', "Access-Control-Allow-Methods": "*",
'Access-Control-Allow-Headers': '*', "Access-Control-Allow-Headers": "*",
}, },
// Enable gzip compression of generated files. // Enable gzip compression of generated files.
compress: true, compress: true,
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
"name": "bkunyun-demo", "name": "bkunyun-demo",
"version": "0.1.0", "version": "0.1.0",
"private": true, "private": true,
"proxy": "",
"dependencies": { "dependencies": {
"@babel/core": "^7.16.0", "@babel/core": "^7.16.0",
"@emotion/react": "^11.9.0", "@emotion/react": "^11.9.0",
...@@ -77,6 +78,9 @@ ...@@ -77,6 +78,9 @@
"workbox-webpack-plugin": "^6.4.1" "workbox-webpack-plugin": "^6.4.1"
}, },
"scripts": { "scripts": {
"dev": "set \"REACT_APP_PROXY=http://47.57.4.97\" && npm start",
"relrese-cn": "set \"REACT_APP_PROXY=http://47.75.104.171\" && npm start",
"relrese-en": "set \"REACT_APP_PROXY=http://47.57.235.86\" && npm start",
"start": "node scripts/start.js", "start": "node scripts/start.js",
"build": "node scripts/build.js", "build": "node scripts/build.js",
"test": "node scripts/test.js" "test": "node scripts/test.js"
......
'use strict';
// Do this as the first thing so that any code reading it knows the right env. // Do this as the first thing so that any code reading it knows the right env.
process.env.BABEL_ENV = 'development'; process.env.BABEL_ENV = "development";
process.env.NODE_ENV = 'development'; process.env.NODE_ENV = "development";
// Makes the script crash on unhandled rejections instead of silently // Makes the script crash on unhandled rejections instead of silently
// ignoring them. In the future, promise rejections that are not handled will // ignoring them. In the future, promise rejections that are not handled will
// terminate the Node.js process with a non-zero exit code. // terminate the Node.js process with a non-zero exit code.
process.on('unhandledRejection', err => { process.on("unhandledRejection", (err) => {
throw err; throw err;
}); });
// Ensure environment variables are read. // Ensure environment variables are read.
require('../config/env'); require("../config/env");
const fs = require('fs'); const fs = require("fs");
const chalk = require('react-dev-utils/chalk'); const chalk = require("react-dev-utils/chalk");
const webpack = require('webpack'); const webpack = require("webpack");
const WebpackDevServer = require('webpack-dev-server'); const WebpackDevServer = require("webpack-dev-server");
const clearConsole = require('react-dev-utils/clearConsole'); const clearConsole = require("react-dev-utils/clearConsole");
const checkRequiredFiles = require('react-dev-utils/checkRequiredFiles'); const checkRequiredFiles = require("react-dev-utils/checkRequiredFiles");
const { const {
choosePort, choosePort,
createCompiler, createCompiler,
prepareProxy, prepareProxy,
prepareUrls, prepareUrls,
} = require('react-dev-utils/WebpackDevServerUtils'); } = require("react-dev-utils/WebpackDevServerUtils");
const openBrowser = require('react-dev-utils/openBrowser'); const openBrowser = require("react-dev-utils/openBrowser");
const semver = require('semver'); const semver = require("semver");
const paths = require('../config/paths'); const paths = require("../config/paths");
const configFactory = require('../config/webpack.config'); const configFactory = require("../config/webpack.config");
const createDevServerConfig = require('../config/webpackDevServer.config'); const createDevServerConfig = require("../config/webpackDevServer.config");
const getClientEnvironment = require('../config/env'); const getClientEnvironment = require("../config/env");
const react = require(require.resolve('react', { paths: [paths.appPath] })); const react = require(require.resolve("react", { paths: [paths.appPath] }));
const env = getClientEnvironment(paths.publicUrlOrPath.slice(0, -1)); const env = getClientEnvironment(paths.publicUrlOrPath.slice(0, -1));
const useYarn = fs.existsSync(paths.yarnLockFile); const useYarn = fs.existsSync(paths.yarnLockFile);
...@@ -45,7 +43,7 @@ if (!checkRequiredFiles([paths.appHtml, paths.appIndexJs])) { ...@@ -45,7 +43,7 @@ if (!checkRequiredFiles([paths.appHtml, paths.appIndexJs])) {
// Tools like Cloud9 rely on this. // Tools like Cloud9 rely on this.
const DEFAULT_PORT = parseInt(process.env.PORT, 10) || 3000; const DEFAULT_PORT = parseInt(process.env.PORT, 10) || 3000;
const HOST = process.env.HOST || '0.0.0.0'; const HOST = process.env.HOST || "0.0.0.0";
if (process.env.HOST) { if (process.env.HOST) {
console.log( console.log(
...@@ -59,28 +57,28 @@ if (process.env.HOST) { ...@@ -59,28 +57,28 @@ if (process.env.HOST) {
`If this was unintentional, check that you haven't mistakenly set it in your shell.` `If this was unintentional, check that you haven't mistakenly set it in your shell.`
); );
console.log( console.log(
`Learn more here: ${chalk.yellow('https://cra.link/advanced-config')}` `Learn more here: ${chalk.yellow("https://cra.link/advanced-config")}`
); );
console.log(); console.log();
} }
// We require that you explicitly set browsers and do not fall back to // We require that you explicitly set browsers and do not fall back to
// browserslist defaults. // browserslist defaults.
const { checkBrowsers } = require('react-dev-utils/browsersHelper'); const { checkBrowsers } = require("react-dev-utils/browsersHelper");
checkBrowsers(paths.appPath, isInteractive) checkBrowsers(paths.appPath, isInteractive)
.then(() => { .then(() => {
// We attempt to use the default port but if it is busy, we offer the user to // We attempt to use the default port but if it is busy, we offer the user to
// run on a different port. `choosePort()` Promise resolves to the next free port. // run on a different port. `choosePort()` Promise resolves to the next free port.
return choosePort(HOST, DEFAULT_PORT); return choosePort(HOST, DEFAULT_PORT);
}) })
.then(port => { .then((port) => {
if (port == null) { if (port == null) {
// We have not found a port. // We have not found a port.
return; return;
} }
const config = configFactory('development'); const config = configFactory("development");
const protocol = process.env.HTTPS === 'true' ? 'https' : 'http'; const protocol = process.env.HTTPS === "true" ? "https" : "http";
const appName = require(paths.appPackageJson).name; const appName = require(paths.appPackageJson).name;
const useTypeScript = fs.existsSync(paths.appTsConfig); const useTypeScript = fs.existsSync(paths.appTsConfig);
...@@ -100,7 +98,9 @@ checkBrowsers(paths.appPath, isInteractive) ...@@ -100,7 +98,9 @@ checkBrowsers(paths.appPath, isInteractive)
webpack, webpack,
}); });
// Load proxy config // Load proxy config
const proxySetting = require(paths.appPackageJson).proxy; // const proxySetting = require(paths.appPackageJson).proxy;
const proxySetting =
require(paths.appPackageJson).proxy || process.env.REACT_APP_PROXY;
const proxyConfig = prepareProxy( const proxyConfig = prepareProxy(
proxySetting, proxySetting,
paths.appPublic, paths.appPublic,
...@@ -119,7 +119,7 @@ checkBrowsers(paths.appPath, isInteractive) ...@@ -119,7 +119,7 @@ checkBrowsers(paths.appPath, isInteractive)
clearConsole(); clearConsole();
} }
if (env.raw.FAST_REFRESH && semver.lt(react.version, '16.10.0')) { if (env.raw.FAST_REFRESH && semver.lt(react.version, "16.10.0")) {
console.log( console.log(
chalk.yellow( chalk.yellow(
`Fast Refresh requires React 16.10 or higher. You are using React ${react.version}.` `Fast Refresh requires React 16.10 or higher. You are using React ${react.version}.`
...@@ -127,26 +127,26 @@ checkBrowsers(paths.appPath, isInteractive) ...@@ -127,26 +127,26 @@ checkBrowsers(paths.appPath, isInteractive)
); );
} }
console.log(chalk.cyan('Starting the development server...\n')); console.log(chalk.cyan("Starting the development server...\n"));
openBrowser(urls.localUrlForBrowser); openBrowser(urls.localUrlForBrowser);
}); });
['SIGINT', 'SIGTERM'].forEach(function (sig) { ["SIGINT", "SIGTERM"].forEach(function (sig) {
process.on(sig, function () { process.on(sig, function () {
devServer.close(); devServer.close();
process.exit(); process.exit();
}); });
}); });
if (process.env.CI !== 'true') { if (process.env.CI !== "true") {
// Gracefully exit when stdin ends // Gracefully exit when stdin ends
process.stdin.on('end', function () { process.stdin.on("end", function () {
devServer.close(); devServer.close();
process.exit(); process.exit();
}); });
} }
}) })
.catch(err => { .catch((err) => {
if (err && err.message) { if (err && err.message) {
console.log(err.message); console.log(err.message);
} }
......
...@@ -2,7 +2,7 @@ import request from "@/utils/axios/service"; ...@@ -2,7 +2,7 @@ import request from "@/utils/axios/service";
function current() { function current() {
return request({ return request({
url: "/accounts/current-mock", url: "/accounts/current",
method: "get", method: "get",
}); });
} }
......
...@@ -23,6 +23,7 @@ const Demo = ({ ...@@ -23,6 +23,7 @@ const Demo = ({
return ( return (
<Box> <Box>
<Box>{JSON.stringify(childrenRoutes)}</Box> <Box>{JSON.stringify(childrenRoutes)}</Box>
<Box>{JSON.stringify(process.env.NODE_ENV)}</Box>
<Button onClick={() => message.success("测试测试")}>message测试</Button> <Button onClick={() => message.success("测试测试")}>message测试</Button>
</Box> </Box>
); );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment