{"id":284724,"date":"2017-04-10T16:30:03","date_gmt":"2017-04-10T12:30:03","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=284724"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=284724","title":{"rendered":"\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 npm \u043f\u0430\u043a\u0435\u0442\u0430 React \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u0432 \u043d\u0430 \u0431\u0430\u0437\u0435 create-react-app"},"content":{"rendered":"<p>\u0412 \u0434\u0430\u043d\u043d\u043e\u0439 \u043f\u0443\u0431\u043b\u0438\u043a\u0430\u0446\u0438\u0438 \u043c\u044b \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u043a\u0430\u043a \u0441\u043e\u0437\u0434\u0430\u0442\u044c npm \u043f\u0430\u043a\u0435\u0442 React \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u0432 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f `create-react-app`<\/p>\n<p>  <a name=\"habracut\"><\/a><br \/>  <b>\u0418\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043f\u0440\u043e\u0435\u043a\u0442\u0430<\/b><\/p>\n<pre><code class=\"bash\">create-react-app create-react-app-npm cd create-react-app-npm yarn run eject yarn add -D babel-preset-es2015 babel-preset-stage-0 babel-preset-react <\/code><\/pre>\n<p>  <b>\u0421\u043e\u0437\u0434\u0430\u0442\u044c `.babelrc`<\/b><\/p>\n<pre><code>{   &quot;presets&quot;: [&quot;es2015&quot;, &quot;react&quot;, &quot;stage-0&quot;] } <\/code><\/pre>\n<p>  <b>\u0418\u0437\u043c\u0435\u043d\u0438\u0442\u044c `package.json`<\/b><\/p>\n<pre><code>...   &quot;name&quot;: &quot;create-react-app-npm&quot;,   &quot;version&quot;: &quot;0.0.1&quot;,   &quot;main&quot;: &quot;lib\/index.js&quot;,   &quot;dependencies&quot;: { ...   &quot;scripts&quot;: {     &quot;start&quot;: &quot;node scripts\/start.js&quot;,     &quot;build&quot;: &quot;node scripts\/build.js&quot;,     &quot;lib&quot;: &quot;babel src\/node_modules --out-dir lib --copy-files&quot;,     &quot;test&quot;: &quot;node scripts\/test.js --env=jsdom&quot;   }, ... <\/code><\/pre>\n<p>  <b>\u0414\u043b\u044f \u00ab\u043f\u0440\u0438\u0435\u043c\u043b\u0435\u043c\u043e\u0439\u00bb \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 CSS<\/b><\/p>\n<p>  <b>\u0418\u0437\u043c\u0435\u043d\u0438\u0442\u044c `config\/webpack.config.dev.js`<\/b><\/p>\n<pre><code class=\"javascript\">...       {         test: \/\\.css$\/,         loader: `style!css?importLoaders=1&modules&localIdentName=[name]__[local]___[hash:base64:5]!postcss`       }, ... <\/code><\/pre>\n<p>  <b>\u0418\u0437\u043c\u0435\u043d\u0438\u0442\u044c `config\/webpack.config.prod.js`<\/b><\/p>\n<pre><code class=\"javascript\">...       {         test: \/\\.css$\/,         loader: ExtractTextPlugin.extract(           'style',           'css?importLoaders=1&modules&localIdentName=[name]__[local]___[hash:base64:5]!postcss',           extractTextPluginOptions         )       }, ... <\/code><\/pre>\n<p>  <b>\u0421\u043e\u0437\u0434\u0430\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0443\u044e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 \u043f\u0430\u043f\u043e\u043a:<\/b><\/p>\n<p>  <code>src\/node_modules\/<br \/>  src\/node_modules\/components\/<br \/>  src\/node_modules\/components\/YourComponent\/<br \/>  src\/node_modules\/components\/YourComponent1\/<br \/>  src\/node_modules\/components\/YourComponent2\/<br \/>  ...<br \/>  src\/node_modules\/components\/YourComponentN\/<br \/>  <\/code><\/p>\n<p>  <b>\u0412 \u043a\u0430\u0436\u0434\u043e\u0439 \u043f\u0430\u043f\u043a\u0435 `YourComponent`<\/b><\/p>\n<p>  <b>\u0421\u043e\u0437\u0434\u0430\u0442\u044c `package.json`<\/b><\/p>\n<pre><code>{   &quot;private&quot;: true,   &quot;name&quot;: &quot;YourComponent&quot;,   &quot;main&quot;: &quot;.\/YourComponent.js&quot; } <\/code><\/pre>\n<p>  <b>\u0421\u043e\u0437\u0434\u0430\u0442\u044c `YourComponent.css` (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440)<\/b><\/p>\n<pre><code class=\"css\">.root {   background: linear-gradient(to top,#fed835 20px,#ffeb3c 20px);   font-size: 30px;   color: white;   line-height: 35px;   text-align: center; } <\/code><\/pre>\n<p>  <b>\u0421\u043e\u0437\u0434\u0430\u0442\u044c `YourComponent.js`<\/b><\/p>\n<pre><code class=\"javascript\">import React                from 'react'  import s                    from '.\/YourComponent.css'  class YourComponent extends React.Component {   render() {     return (       &lt;div className={ s.root }&gt;         { this.props.children }       &lt;\/div&gt;     )   } }  export default YourComponent <\/code><\/pre>\n<p>  <b>\u0421\u043e\u0437\u0434\u0430\u0442\u044c `src\/node_modules\/index.js`<\/b><\/p>\n<pre><code class=\"javascript\">export { default as YourComponent } from '.\/components\/YourComponent' <\/code><\/pre>\n<p>  <b>\u0414\u043b\u044f \u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0430\u0446\u0438\u0438 \u0440\u0430\u0431\u043e\u0442\u044b \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c `src\/App.js`<\/b><\/p>\n<pre><code class=\"javascript\">import React                from 'react'  import YourComponent        from 'components\/YourComponent'  class App extends React.Component {   render() {     return (       &lt;YourComponent&gt;         1       &lt;\/YourComponent&gt;     )   } }  export default App <\/code><\/pre>\n<p>  <b>\u0422\u0435\u043f\u0435\u0440\u044c \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0432 `yarn run start` \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0443\u0432\u0438\u0434\u0435\u0442\u044c, \u0447\u0442\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c<\/b><\/p>\n<p>  <b>\u0414\u043e\u0431\u0430\u0432\u044c\u0442\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u043f\u0443\u0442\u0438 \u0432 `.gitignore` (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440)<\/b><\/p>\n<p>  <code>\/node_modules<br \/>  \/coverage<br \/>  \/build<\/p>\n<p>  .DS_Store<br \/>  .env<br \/>  npm-debug.log*<br \/>  yarn-debug.log*<br \/>  yarn-error.log*<br \/>  yarn.lock<\/p>\n<p>  .idea<br \/>  <\/code><\/p>\n<p>  <b>\u0421\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u0443\u0439\u0442\u0435 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443<\/b><\/p>\n<pre><code class=\"bash\">yarn run lib <\/code><\/pre>\n<p>  <b>\u0421\u043e\u0437\u0434\u0430\u0439\u0442\u0435 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0439 \u043d\u0430 github<\/b><\/p>\n<p>  <b>\u041f\u0440\u0438\u0432\u044f\u0436\u0438\u0442\u0435 \u043f\u0440\u043e\u0435\u043a\u0442 \u043a \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u043e\u043c\u0443 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u044e<\/b><\/p>\n<pre><code class=\"bash\">git init git remote add origin https:\/\/github.com\/lokhmakov\/create-react-app-npm.git <\/code><\/pre>\n<p>  <b>\u0414\u043e\u0431\u0430\u0432\u044c\u0442\u0435 \u0444\u0430\u0439\u043b\u044b, \u0441\u0434\u0435\u043b\u0430\u0439\u0442\u0435 commit \u0438 \u043e\u043f\u0443\u0431\u043b\u0438\u043a\u0443\u0439\u0442\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442<\/b><\/p>\n<pre><code class=\"bash\">git add . git commit -m &quot;init&quot; git push -u origin master npm publish <\/code><\/pre>\n<p>  <b>\u0412\u044b \u0437\u0430\u043a\u043e\u043d\u0447\u0438\u043b\u0438. \u0422\u0435\u043f\u0435\u0440\u044c \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432\u0430\u0448\u0443 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c<\/b><\/p>\n<pre><code class=\"bash\">yarn add create-react-app-npm <\/code><\/pre>\n<pre><code class=\"javascript\">import { YourComponent } from 'create-react-app-npm' <\/code><\/pre>\n<p>  <a href=\"https:\/\/github.com\/lokhmakov\/create-react-app-npm\">https:\/\/github.com\/lokhmakov\/create-react-app-npm<\/a><\/p>\n<p>  <a href=\"https:\/\/medium.com\/@lokhmakov\/best-way-to-create-npm-packages-with-create-react-app-b24dd449c354\">https:\/\/medium.com\/@lokhmakov\/best-way-to-create-npm-packages-with-create-react-app-b24dd449c354<\/a><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habrahabr.ru\/post\/326090\/\"> https:\/\/habrahabr.ru\/post\/326090\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u0412 \u0434\u0430\u043d\u043d\u043e\u0439 \u043f\u0443\u0431\u043b\u0438\u043a\u0430\u0446\u0438\u0438 \u043c\u044b \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u043a\u0430\u043a \u0441\u043e\u0437\u0434\u0430\u0442\u044c npm \u043f\u0430\u043a\u0435\u0442 React \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u0432 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f `create-react-app`<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-284724","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/284724","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=284724"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/284724\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=284724"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=284724"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=284724"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}