{"id":2594,"date":"2020-04-08T18:49:23","date_gmt":"2020-04-08T10:49:23","guid":{"rendered":"http:\/\/www.yuguoxy.com\/geekhome\/?p=2594"},"modified":"2026-08-18T12:35:27","modified_gmt":"2026-08-18T04:35:27","slug":"reactjs%e5%bc%80%e5%8f%91%e7%8e%af%e5%a2%83%e5%85%a5%e9%97%a8%e9%85%8d%e7%bd%ae","status":"publish","type":"post","link":"https:\/\/ai.zhousir.top\/?p=2594","title":{"rendered":"Reactjs\u5f00\u53d1\u73af\u5883\u5165\u95e8\u914d\u7f6e"},"content":{"rendered":"<section id=\"wenyan\" style=\"font-family: system-ui, 'Apple Color Emoji', 'Segoe UI', 'Segoe UI Symbol', 'Noto Sans', Roboto, sans-serif; line-height: 1.75; font-size: 16px; color: #000000; caret-color: #000000;\" data-provider=\"WenYan\">\n<p style=\"margin: 1em 0px;\"><strong style=\"color: #4870ac;\">Create React App<\/strong> \u662f\u5b66\u4e60 React \u7684\u8212\u9002\u73af\u5883\uff0c\u4e5f\u662f\u7528 React \u521b\u5efa\u65b0\u7684<a href=\"https:\/\/zh-hans.reactjs.org\/docs\/glossary.html#single-page-application\">\u5355\u9875\u5e94\u7528<\/a>\u7684\u5e38\u7528\u65b9\u5f0f\u3002\u5b83\u4f1a\u914d\u597d\u5f00\u53d1\u73af\u5883\uff0c\u8ba9\u4f60\u7528\u4e0a\u8f83\u65b0\u7684 JavaScript \u7279\u6027\uff0c\u5e76\u7ed9\u751f\u4ea7\u6784\u5efa\u505a\u4f18\u5316\u3002\u673a\u5668\u4e0a\u9700\u8981 <a href=\"https:\/\/nodejs.org\/en\/\">Node &gt;= 8.10 \u548c npm &gt;= 5.6<\/a>\u3002\u811a\u624b\u67b6\u4ed3\u5e93\uff1a<a href=\"https:\/\/github.com\/facebookincubator\/create-react-app\">create-react-app<\/a>\u3002<\/p>\n<p style=\"margin: 1em 0px;\">\u53e6\u4e00\u6761\u8def\u662f\u81ea\u5df1\u7528 webpack \u642d\uff1a\u88c5 loader\u3001Babel 7\u3001html-webpack-plugin\uff0c\u518d\u5199 webpack.config.js\u3002\u672c\u6587\u6309\u539f\u6587\u4e24\u6761\u8def\u5f84\u8d70\u4e00\u904d\u3002<\/p>\n<h2 style=\"padding: 1px 12.5px; color: #ffffff; margin: 1.2em 0px 1em; border-radius: 4px; display: inline-block; background-color: #4870ac; font-size: 1.3em;\">\u4e00\u3001\u5b98\u65b9\u811a\u624b\u67b6\u521b\u5efa\u9879\u76ee<\/h2>\n<p style=\"margin: 1em 0px;\"><a href=\"https:\/\/ai.zhousir.top\/wp-content\/uploads\/2024\/05\/image.png\" rel=\"fancybox\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-3498\" src=\"https:\/\/ai.zhousir.top\/wp-content\/uploads\/2024\/05\/image.png\" alt=\"\" width=\"2151\" height=\"1105\" srcset=\"https:\/\/ai.zhousir.top\/wp-content\/uploads\/2024\/05\/image.png 2151w, https:\/\/ai.zhousir.top\/wp-content\/uploads\/2024\/05\/image-768x395.png 768w, https:\/\/ai.zhousir.top\/wp-content\/uploads\/2024\/05\/image-1536x789.png 1536w, https:\/\/ai.zhousir.top\/wp-content\/uploads\/2024\/05\/image-2048x1052.png 2048w\" sizes=\"(max-width: 2151px) 100vw, 2151px\" \/><\/a><\/p>\n<p style=\"margin: 1em 0px;\">\u521b\u5efa\u5e76\u542f\u52a8\uff1a<\/p>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 12px; background: #002b36; max-width: 100%; overflow-wrap: normal;\"><code class=\"hljs\" style=\"word-break: normal; white-space: nowrap; tab-size: 2; font-size: 12px; font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; display: block; overflow-x: auto; margin: 0.5em; padding: 3px 5px; color: #93a1a1; background: #002b36; overflow-wrap: normal;\">npx create-react-app my-app\ncd my-app\nnpm start<\/code><\/pre>\n<p style=\"margin: 1em 0px;\">\u7b2c\u4e00\u884c\u7684 <code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; color: #4870ac; font-size: 0.9em; font-weight: normal; overflow-wrap: break-word; padding: 2px 4px; border-radius: 3px; margin: 2px; background-color: #f6f8fa; word-break: break-all;\">npx<\/code> \u4e0d\u662f\u62fc\u5199\u9519\u8bef\u2014\u2014\u5b83\u662f <a href=\"https:\/\/medium.com\/@maybekatz\/introducing-npx-an-npm-package-runner-55f7d4bd282b\">npm 5.2+ \u9644\u5e26\u7684 package \u8fd0\u884c\u5de5\u5177<\/a>\u3002<\/p>\n<ul style=\"padding-left: 1rem; margin-left: 1rem; font-size: 0.9rem; list-style-type: disc;\">\n<li>\n<section>create-react-app \u521b\u5efa\u9879\u76ee\u65f6 node_modules \u5f88\u5927\u3001\u5f88\u6162\u3002\u82e5\u8981\u5efa\u591a\u4e2a\u6d4b\u8bd5\u9879\u76ee\uff0c\u5efa\u8bae\u628a node_modules \u79fb\u5230\u4e0a\u7ea7\u76ee\u5f55\uff0c\u540e\u7eed\u9879\u76ee\u53ef\u4ee5\u5171\u4eab\u3002<\/section>\n<\/li>\n<\/ul>\n<p style=\"margin: 1em 0px;\">\u82e5\u8981\u987a\u5229\u542f\u52a8\uff0c\u539f\u6587\u8fd8\u63d0\u5230\u9700\u8981\u5168\u5c40\u5b89\u88c5 <code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; color: #4870ac; font-size: 0.9em; font-weight: normal; overflow-wrap: break-word; padding: 2px 4px; border-radius: 3px; margin: 2px; background-color: #f6f8fa; word-break: break-all;\">react-scripts<\/code>\uff1a<\/p>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 12px; background: #002b36; max-width: 100%; overflow-wrap: normal;\"><code class=\"hljs\" style=\"word-break: normal; white-space: nowrap; tab-size: 2; font-size: 12px; font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; display: block; overflow-x: auto; margin: 0.5em; padding: 3px 5px; color: #93a1a1; background: #002b36; overflow-wrap: normal;\">npm install -g react-scripts<\/code><\/pre>\n<p style=\"margin: 1em 0px;\">package.json \u91cc\u7684 scripts\uff1a<\/p>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 12px; background: #002b36; max-width: 100%; overflow-wrap: normal;\"><code class=\"hljs\" style=\"word-break: normal; white-space: nowrap; tab-size: 2; font-size: 12px; font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; display: block; overflow-x: auto; margin: 0.5em; padding: 3px 5px; color: #93a1a1; background: #002b36; overflow-wrap: normal;\"> \"scripts\": {\n  \"start\": \"react-scripts start\",\n  \"build\": \"react-scripts build\",\n  \"test\": \"react-scripts test\",\n  \"eject\": \"react-scripts eject\"\n },<\/code><\/pre>\n<p style=\"margin: 1em 0px;\">\u7f51\u7edc\u8bf7\u6c42\u9047\u5230\u8de8\u57df\uff0c\u53ef\u5728 package.json \u91cc\u914d proxy\uff1a<\/p>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 12px; background: #002b36; max-width: 100%; overflow-wrap: normal;\"><code class=\"hljs\" style=\"word-break: normal; white-space: nowrap; tab-size: 2; font-size: 12px; font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; display: block; overflow-x: auto; margin: 0.5em; padding: 3px 5px; color: #93a1a1; background: #002b36; overflow-wrap: normal;\">\/\/package.json\n{\n  \"name\": \"reactapp\",\n  \"version\": \"0.1.0\",\n  \"dependencies\": {\n    \"react\": \"^16.13.1\",\n    \"react-dom\": \"^16.13.1\",\n    \"react-scripts\": \"3.4.1\"\n  },\n    \n  \"scripts\": {\n    \"start\": \"react-scripts start\",\n    \"build\": \"react-scripts build\",\n    \"test\": \"react-scripts test\",\n    \"eject\": \"react-scripts eject\"\n  },\n  \"proxy\":\"http:\/\/192.168.0.100\"  \/\/\u4ee3\u7406\u914d\u7f6e\n}<\/code><\/pre>\n<table style=\"display: table; text-align: left; overflow: auto; border-collapse: collapse; margin: 1.4em auto; max-width: 100%; table-layout: fixed; overflow-wrap: break-word; word-break: break-all;\" width=\"800\">\n<thead>\n<tr>\n<th style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top; text-align: center; font-weight: bold; color: #4870ac; background: #f7f7f7;\">\u65b9\u5f0f<\/th>\n<th style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top; text-align: center; font-weight: bold; color: #4870ac; background: #f7f7f7;\">\u547d\u4ee4 \/ \u914d\u7f6e<\/th>\n<th style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top; text-align: center; font-weight: bold; color: #4870ac; background: #f7f7f7;\">\u6ce8\u610f<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">\u811a\u624b\u67b6<\/td>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\"><code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; color: #4870ac; font-size: 0.9em; font-weight: normal; overflow-wrap: break-word; padding: 2px 4px; border-radius: 3px; margin: 2px; background-color: #f6f8fa; word-break: break-all;\">npx create-react-app my-app<\/code><\/td>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">\u4f9d\u8d56 Node\u22658.10\u3001npm\u22655.6<\/td>\n<\/tr>\n<tr>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">\u542f\u52a8<\/td>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\"><code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; color: #4870ac; font-size: 0.9em; font-weight: normal; overflow-wrap: break-word; padding: 2px 4px; border-radius: 3px; margin: 2px; background-color: #f6f8fa; word-break: break-all;\">npm start<\/code><\/td>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">scripts \u8d70 react-scripts<\/td>\n<\/tr>\n<tr>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">\u8de8\u57df<\/td>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">package.json \u7684 &#8220;proxy&#8221;<\/td>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">\u5f00\u53d1\u670d\u52a1\u5668\u8f6c\u53d1<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2 style=\"padding: 1px 12.5px; color: #ffffff; margin: 1.2em 0px 1em; border-radius: 4px; display: inline-block; background-color: #4870ac; font-size: 1.3em;\">\u4e8c\u3001webpack \u624b\u52a8\u6784\u5efa<\/h2>\n<p style=\"margin: 1em 0px;\">\u9879\u76ee\u76ee\u5f55\u7ed3\u6784\u5982\u4e0b\uff1a<\/p>\n<p style=\"margin: 1em 0px;\"><img decoding=\"async\" src=\"media\/\u9879\u76ee\u76ee\u5f55\u7ed3\u6784.png\" alt=\"\" \/><\/p>\n<h3 style=\"padding: 0px; color: #4870ac; margin: 1.2em 0px 1em; font-size: 1.3em;\">\u5b89\u88c5\u4f9d\u8d56<\/h3>\n<p style=\"margin: 1em 0px;\">webpack \u76f8\u5173\u5305\u672c\u5730\u5b89\u88c5\uff1a<\/p>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 12px; background: #002b36; max-width: 100%; overflow-wrap: normal;\"><code class=\"hljs\" style=\"word-break: normal; white-space: nowrap; tab-size: 2; font-size: 12px; font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; display: block; overflow-x: auto; margin: 0.5em; padding: 3px 5px; color: #93a1a1; background: #002b36; overflow-wrap: normal;\">npm i -D webpack webpack-cli  webpack-dev-server<\/code><\/pre>\n<p style=\"margin: 1em 0px;\">reactjs \u76f8\u5173\u5305\uff1a<\/p>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 12px; background: #002b36; max-width: 100%; overflow-wrap: normal;\"><code class=\"hljs\" style=\"word-break: normal; white-space: nowrap; tab-size: 2; font-size: 12px; font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; display: block; overflow-x: auto; margin: 0.5em; padding: 3px 5px; color: #93a1a1; background: #002b36; overflow-wrap: normal;\">npm i -D react react-dom<\/code><\/pre>\n<p style=\"margin: 1em 0px;\">babel \u89e3\u6790\u5305\uff08\u8fd9\u91cc\u7528 7.0\uff09\uff1a<\/p>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 12px; background: #002b36; max-width: 100%; overflow-wrap: normal;\"><code class=\"hljs\" style=\"word-break: normal; white-space: nowrap; tab-size: 2; font-size: 12px; font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; display: block; overflow-x: auto; margin: 0.5em; padding: 3px 5px; color: #93a1a1; background: #002b36; overflow-wrap: normal;\">npm install -S babel-loader @babel\/core <\/code><\/pre>\n<p style=\"margin: 1em 0px;\">\u89e3\u6790 ES6 \u548c JSX \u7684\u63d2\u4ef6\uff1a<\/p>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 12px; background: #002b36; max-width: 100%; overflow-wrap: normal;\"><code class=\"hljs\" style=\"word-break: normal; white-space: nowrap; tab-size: 2; font-size: 12px; font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; display: block; overflow-x: auto; margin: 0.5em; padding: 3px 5px; color: #93a1a1; background: #002b36; overflow-wrap: normal;\">npm install -S @babel\/preset-react  @babel\/preset-env<\/code><\/pre>\n<p style=\"margin: 1em 0px;\">\u6ce8\uff1a\u4ee5\u524d\u7f16\u8bd1 ES6 \u4ee5\u4e0a\u8bed\u6cd5\u7528\u7684\u662f babel-preset-es2015\u3002<code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; color: #4870ac; font-size: 0.9em; font-weight: normal; overflow-wrap: break-word; padding: 2px 4px; border-radius: 3px; margin: 2px; background-color: #f6f8fa; word-break: break-all;\">babel-preset-env<\/code> \u66f4\u53ef\u5b9a\u5236\uff1a\u6307\u5b9a\u8981\u517c\u5bb9\u7684\u6d4f\u89c8\u5668\u7248\u672c\uff0cBabel \u53ea\u7f16\u8bd1\u8be5\u7248\u672c\u4e0d\u652f\u6301\u7684\u8bed\u6cd5\uff0c\u800c\u4e0d\u662f\u5168\u90e8\u6253\u6210\u65e7\u8bed\u6cd5\u3002<\/p>\n<p style=\"margin: 1em 0px;\">html-webpack-plugin \u628a\u6253\u5305\u540e\u7684 bundle.js \u81ea\u52a8\u5199\u8fdb index.html \u6a21\u677f\uff1a<\/p>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 12px; background: #002b36; max-width: 100%; overflow-wrap: normal;\"><code class=\"hljs\" style=\"word-break: normal; white-space: nowrap; tab-size: 2; font-size: 12px; font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; display: block; overflow-x: auto; margin: 0.5em; padding: 3px 5px; color: #93a1a1; background: #002b36; overflow-wrap: normal;\">npm i  -D html-webpack-plugin<\/code><\/pre>\n<p style=\"margin: 1em 0px;\">\u5176\u5b83\u76f8\u5173\u5305\uff1a<\/p>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 12px; background: #002b36; max-width: 100%; overflow-wrap: normal;\"><code class=\"hljs\" style=\"word-break: normal; white-space: nowrap; tab-size: 2; font-size: 12px; font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; display: block; overflow-x: auto; margin: 0.5em; padding: 3px 5px; color: #93a1a1; background: #002b36; overflow-wrap: normal;\">npm install file-loader url-loader --save \/\/\u52a0\u8f7d\u56fe\u7247\u8d44\u6e90\n\nnpm install style-loader css-loader --save  \/\/css-loader\u7528\u4e8e\u5c06css\u8f6c\u6362\u6210\u5bf9\u8c61\uff0c\u800cstyle-loader\u5219\u5c06\u89e3\u6790\u540e\u7684\u6837\u5f0f\u5d4c\u5165js\u4ee3\u7801\n\nnpm install postcss-loader --save \/\/\u68c0\u67e5CSS\uff08\u50cfeslint\u68c0\u67e5js\u90a3\u6837\uff09\u3001\u6dfb\u52a0\u6d4f\u89c8\u5668\u524d\u7f00\uff08\u8be5\u5e73\u53f0\u76ee\u524d\u6700\u706b\u7684\u63d2\u4ef6\uff09\n\u4f7f\u7528\u672a\u6765\u7684CSS\u8bed\u6cd5\uff08\u5927\u6982\u5c31\u50cf\u73b0\u5728\u7684\u82b1\u5457\uff1f\uff1f\uff09\u3001\u51fd\u6570\u5f0f\u8bed\u6cd5\uff08\u7c7b\u4f3cSass\u8bed\u6cd5\uff09\u7b49\u7b49\n\nnpm install autoprefixer precss postcss-flexbugs-fixes --save \/\/\u6ce8\uff1aautoprefixer\u662f\u81ea\u52a8\u6dfb\u52a0\u6d4f\u89c8\u5668\u524d\u7f00\u7684\u63d2\u4ef6\uff0cprecss\u662f\u7c7b\u4f3cSass\u8bed\u6cd5\u7684css\u63d2\u4ef6\uff0cpostcss-flexbugs-fixes\u662f\u4fee\u590d\u4e86flex\u5e03\u5c40bug\u7684\u63d2\u4ef6<\/code><\/pre>\n<h3 style=\"padding: 0px; color: #4870ac; margin: 1.2em 0px 1em; font-size: 1.3em;\">webpack.config.js \u53c2\u8003<\/h3>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 12px; background: #002b36; max-width: 100%; overflow-wrap: normal;\"><code class=\"hljs\" style=\"word-break: normal; white-space: nowrap; tab-size: 2; font-size: 12px; font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; display: block; overflow-x: auto; margin: 0.5em; padding: 3px 5px; color: #93a1a1; background: #002b36; overflow-wrap: normal;\">const path = require('path'); \/\/nodejs\u5185\u7f6e\u6a21\u5757\nconst HtmlWebpackPlugin = require('html-webpack-plugin');\n\nmodule.exports = {\n    \/\/\u672c\u5730\u670d\u52a1\n    devServer: {\n        contentBase: path.join(__dirname, \"public\"),\n        compress: true,\n        port: 9000,\n        historyApiFallback: true, \/\/\u4e0d\u8df3\u8f6c\n        inline: true \/\/\u5b9e\u65f6\u5237\u65b0\n    },\n    \/\/\u5165\u53e3\n    entry: '.\/src\/index.js',\n    \/\/\u51fa\u53e3\n    output: {\n        path: path.resolve(__dirname, 'public'),\n        filename: 'bundle.js' \/\/ d:\/\/webpakc\/dist\/bundle.js\n    },\n    \/\/loaders\n    module: {\n        rules: [{\n            test: \/\\.js$\/, \/\/\u914d\u7f6e\u8981\u5904\u7406\u7684\u6587\u4ef6\u683c\u5f0f\uff0c\u4e00\u822c\u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u5339\u914d\n            exclude: \/node_modules\/,\n            loader: 'babel-loader', \/\/\u4f7f\u7528\u7684\u52a0\u8f7d\u5668\u540d\u79f0\n            query: { \/\/babel\u7684\u914d\u7f6e\u53c2\u6570\uff0c\u53ef\u4ee5\u5199\u5728.babelrc\u6587\u4ef6\u91cc\u4e5f\u53ef\u4ee5\u5199\u5728\u8fd9\u91cc\n                presets: ['@babel\/preset-env', '@babel\/preset-react']\n            }\n        }]\n    },\n    \/\/\u63d2\u4ef6\n    plugins: [\n        new HtmlWebpackPlugin({\n            filename: 'index.html',\n            template: __dirname + \"\/index.html\"\n        }),\n    ]\n}<\/code><\/pre>\n<h3 style=\"padding: 0px; color: #4870ac; margin: 1.2em 0px 1em; font-size: 1.3em;\">package.json \u53c2\u8003<\/h3>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 12px; background: #002b36; max-width: 100%; overflow-wrap: normal;\"><code class=\"hljs\" style=\"word-break: normal; white-space: nowrap; tab-size: 2; font-size: 12px; font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; display: block; overflow-x: auto; margin: 0.5em; padding: 3px 5px; color: #93a1a1; background: #002b36; overflow-wrap: normal;\">{\n  \"name\": \"03webpack-react-demo1\",\n  \"version\": \"1.0.0\",\n  \"description\": \"\",\n  \"main\": \"webpack.config.js\",\n  \"scripts\": {\n    \"test\": \"echo \\\"Error: no test specified\\\" &amp;&amp; exit 1\",\n    \"build\": \"node_modules\\\\.bin\\\\webpack --mode development\",\n    \"start\": \"node_modules\\\\.bin\\\\webpack-dev-server\"\n  },\n  \"keywords\": [],\n  \"author\": \"\",\n  \"license\": \"ISC\",\n  \"devDependencies\": {\n    \"html-webpack-plugin\": \"^4.0.4\",\n    \"react\": \"^16.13.1\",\n    \"react-dom\": \"^16.13.1\",\n    \"webpack\": \"^4.42.1\",\n    \"webpack-cli\": \"^3.3.11\",\n    \"webpack-dev-server\": \"^3.10.3\"\n  },\n  \"dependencies\": {\n    \"@babel\/core\": \"^7.9.0\",\n    \"@babel\/preset-env\": \"^7.9.5\",\n    \"@babel\/preset-react\": \"^7.9.4\",\n    \"babel-loader\": \"^8.1.0\"<\/code><\/pre>\n<blockquote style=\"display: block; font-size: 0.9em; border-left: 3px solid #4870ac; padding: 0.5em 1em; margin: 0px; background: #f6f8fa; color: #40464f;\">\n<p style=\"margin: 1em 0px;\"><strong style=\"color: #4870ac;\">\u4e00\u53e5\u8bdd\u603b\u7ed3\uff1a\u5165\u95e8\u7528 create-react-app\uff08npx + react-scripts\uff0c\u8de8\u57df\u914d proxy\uff09\uff1b\u8981\u638c\u63a7\u6784\u5efa\u94fe\u5c31\u672c\u5730\u88c5 webpack\/Babel 7\/html-webpack-plugin\uff0c\u6309\u539f\u6587\u5199\u597d entry\u3001loader \u548c scripts\u3002<\/strong><\/p>\n<\/blockquote>\n<\/section>\n","protected":false},"excerpt":{"rendered":"<p>Create React App \u662f\u5b66\u4e60 React \u7684\u8212\u9002\u73af\u5883\uff0c\u4e5f\u662f\u7528 React \u521b\u5efa\u65b0\u7684\u5355\u9875\u5e94\u7528\u7684\u5e38\u7528\u65b9 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[125,105],"tags":[143],"_links":{"self":[{"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts\/2594"}],"collection":[{"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2594"}],"version-history":[{"count":3,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts\/2594\/revisions"}],"predecessor-version":[{"id":3530,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts\/2594\/revisions\/3530"}],"wp:attachment":[{"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2594"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2594"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2594"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}