{"id":323010,"date":"2021-05-12T21:00:44","date_gmt":"2021-05-12T21:00:44","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=323010"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=323010","title":{"rendered":"Path aliases in React"},"content":{"rendered":"\n<div class=\"post__text post__text_v2\" id=\"post-content-body\">\n<p>\u042d\u0442\u043e\u0442 \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b \u043f\u043e\u043c\u043e\u0436\u0435\u0442 \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u0442\u044c path aliases  \u0434\u043b\u044f \u0432\u0430\u0448\u0435\u0433\u043e cretae-react-app.<\/p>\n<details class=\"spoiler\">\n<summary>\u0421\u043e\u0434\u0435\u0440\u0436\u0430\u043d\u0438\u0435<\/summary>\n<div class=\"spoiler__content\">\n<ul>\n<li>\n<p><code>&lt;a href=\"#Intro\"&gt;Introduction &lt;\/a&gt;<\/code><\/p>\n<\/li>\n<li>\n<p><code>&lt;a href=\"#Craco\"&gt;Import Craco &lt;\/a&gt;<\/code><\/p>\n<\/li>\n<li>\n<p><code>&lt;a href=\"#Eject\"&gt;React-scripts eject&lt;\/a&gt;<\/code><\/p>\n<\/li>\n<\/ul>\n<\/div>\n<\/details>\n<h2>\u0412\u0432\u0435\u0434\u0435\u043d\u0438\u0435<\/h2>\n<p><a class=\"anchor\" name=\"Intro\" id=\"Intro\"><\/a><\/p>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043d\u0430\u0447\u043d\u0435\u043c \u0441 \u0442\u043e\u0433\u043e, \u0437\u0430\u0447\u0435\u043c \u0432\u043e\u043e\u0431\u0449\u0435 \u044d\u0442\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e.<\/p>\n<p>\u041f\u043e \u043c\u0435\u0440\u0435 \u0440\u043e\u0441\u0442\u0430 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u0432 \u0438 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u0441\u0435\u0440\u0432\u0438\u0441\u043e\u0432 \u0432 \u0432\u0430\u0448\u0435\u043c \u043f\u0440\u043e\u0435\u043a\u0442\u0435, \u0432\u0441\u0435 \u0447\u0430\u0449\u0435 \u043d\u0430\u0447\u0438\u043d\u0430\u044e\u0442 \u043f\u043e\u044f\u0432\u043b\u044f\u0442\u044c\u0441\u044f \u0442\u0430\u043a\u0438\u0435 \u0438\u043c\u043f\u043e\u0440\u0442\u044b:<\/p>\n<figure class=\"bordered full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/99c\/a52\/d6e\/99ca52d6e9c4662f8aef1f9d55b6efd1.png\" alt=\"\u0412\u044b \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u0442\u0435 \u043d\u0430 \u044d\u0442\u0438\u0445 \u043a\u0440\u043e\u043a\u043e\u0434\u0438\u043b\u043e\u0432 !\" title=\"\u0412\u044b \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u0442\u0435 \u043d\u0430 \u044d\u0442\u0438\u0445 \u043a\u0440\u043e\u043a\u043e\u0434\u0438\u043b\u043e\u0432 !\" width=\"528\" height=\"120\"><figcaption>\u0412\u044b \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u0442\u0435 \u043d\u0430 \u044d\u0442\u0438\u0445 \u043a\u0440\u043e\u043a\u043e\u0434\u0438\u043b\u043e\u0432 !<\/figcaption><\/figure>\n<p>\u0425\u043e\u0447\u0435\u0442\u0441\u044f \u0437\u0430\u043c\u0435\u043d\u0438\u0442\u044c \u044d\u0442\u0438 \u043f\u0443\u0442\u0438 \u043d\u0430 \u0447\u0442\u043e-\u0442\u043e \u043f\u043e\u0434\u043e\u0431\u043d\u043e\u0435:<\/p>\n<figure class=\"bordered full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/f46\/6c2\/2dd\/f466c22ddb3ab168b4bf91468bae0d92.png\" alt=\"\u041d\u0443 \u043a\u0440\u0430\u0441\u043e\u0442\u0430 \u0436\u0435 !\" title=\"\u041d\u0443 \u043a\u0440\u0430\u0441\u043e\u0442\u0430 \u0436\u0435 !\" width=\"557\" height=\"117\"><figcaption>\u041d\u0443 \u043a\u0440\u0430\u0441\u043e\u0442\u0430 \u0436\u0435 !<\/figcaption><\/figure>\n<p>\u041d\u0438\u0436\u0435 \u044f \u043f\u0440\u0438\u0432\u0435\u043b 2 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0430 \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u043e\u0439 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b.<\/p>\n<h2>Import craco<\/h2>\n<p><a class=\"anchor\" name=\"Craco\" id=\"Craco\"><\/a><\/p>\n<p>\u0421\u0430\u043c\u044b\u0439 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 &#8212; \u044d\u0442\u043e \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f <a href=\"https:\/\/www.npmjs.com\/package\/@craco\/craco\" rel=\"noopener noreferrer nofollow\">craco<\/a>. \u0423\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0432 \u043f\u0430\u043a\u0435\u0442 \u0438 \u0437\u0430\u043c\u0435\u043d\u0438\u0432 \u0441\u043a\u0440\u0438\u043f\u0442\u044b, \u043a\u0430\u043a \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043e \u0432 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438, \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u0440\u0438\u0441\u0442\u0443\u043f\u0438\u0442\u044c \u043a \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044e path aliases \u0432 \u0444\u0430\u0439\u043b\u0435 craco.config.js.<\/p>\n<pre><code class=\"javascript\">const path = require('path');  const resolvePath = p =&gt; path.join(path.resolve(__dirname, p))  module.exports = {     \/\/ ...     webpack: {         alias: {             '@components': resolvePath('.\/src\/components'),             '@assets': resolvePath('.\/src\/assets'),             '@services': resolvePath('.\/src\/services')         }     },   \/\/ ... }<\/code><\/pre>\n<h2>React-scripts eject<\/h2>\n<p><a class=\"anchor\" name=\"Eject\" id=\"Eject\"><\/a><\/p>\n<p>\u0412 \u044d\u0442\u043e\u043c \u043c\u0435\u0442\u043e\u0434\u0435 \u044f \u0445\u043e\u0447\u0443 \u0441\u0430\u043c \u043f\u043e\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u0435 \u0444\u0430\u0439\u043b\u044b, \u0430 \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043c\u043d\u0435 \u043d\u0443\u0436\u0435\u043d \u043a \u043d\u0438\u043c \u0434\u043e\u0441\u0442\u0443\u043f. \u041d\u043e, \u0431\u0443\u0434\u044c\u0442\u0435 \u0430\u043a\u043a\u0443\u0440\u0430\u0442\u043d\u044b, \u0432\u0435\u0434\u044c \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u044d\u0442\u043e\u0433\u043e \u0441\u043a\u0440\u0438\u043f\u0442\u0430 <strong>\u041d\u0415\u041e\u0422\u0412\u0420\u0410\u0422\u0418\u041c\u042b<\/strong>!<\/p>\n<pre><code class=\"bash\">npm react-scripts eject<\/code><\/pre>\n<p>\u041f\u043e\u0441\u043b\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0441\u043a\u0440\u0438\u043f\u0442\u0430 \u0443 \u0432\u0430\u0441 \u043f\u043e\u044f\u0432\u044f\u0442\u0441\u044f \u0442\u0430\u043a\u0438\u0435 \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u0438 \u0438 \u0444\u0430\u0439\u043b\u044b \u043a\u0430\u043a :<\/p>\n<ul>\n<li>\n<p>\u0414\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u044f config\/<\/p>\n<\/li>\n<li>\n<p>\u0414\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u044f  scripts\/<\/p>\n<\/li>\n<li>\n<p>\u0424\u0430\u0439\u043b tsconfig.json (\u0438\u043b\u0438 jsconfig.json)<\/p>\n<\/li>\n<\/ul>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/68e\/1ee\/609\/68e1ee609be4f0f76a940ccc12298543.png\" width=\"501\" height=\"255\"><figcaption><\/figcaption><\/figure>\n<p>\u0418\u0437\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e \u043d\u0443\u0436\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043d\u0430\u0448\u0438 path aliases \u0432 tsconfig.json (\u0438\u043b\u0438 jsconfig.json). \u0414\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431 \u043f\u0440\u0438 \u0441\u0431\u043e\u0440\u043a\u0435 \u043d\u0430\u0448\u0438 \u0441\u043a\u0440\u0438\u043f\u0442\u044b \u0432 \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u0438 config\/ \u043f\u043e\u0434\u0442\u044f\u043d\u0443\u043b\u0438 \u0438\u0445 \u0434\u043b\u044f webpack \u0438 \u0434\u043b\u044f jest.<\/p>\n<pre><code class=\"javascript\">{   \"compilerOptions\": {     \/\/ ...     \"baseUrl\": \".\",     \"paths\": {       \"@components\/*\": [\"src\/components\/*\"],       \"@styled\/*\": [\"src\/components\/styled\/*\"],       \"@pages\/*\": [\"src\/pages\/*\"],       \"@assets\/*\": [\"src\/assets\/*\"],       \"@services\/*\": [\"src\/services\/*\"]     },     \/\/ ...   },   \/\/ ... } <\/code><\/pre>\n<p>\u0414\u0430\u043b\u0435\u0435 \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u043e\u0432\u0435\u0441\u0442\u0438 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u0438\u0435 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0432 \u0444\u0430\u0439\u043b\u0435 modules.js, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442 \u0444\u0430\u0439\u043b \u0438\u0441\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u0439 \u0440\u0430\u043d\u0435\u0435.<\/p>\n<pre><code class=\"javascript\">'use strict'  const fs = require('fs') const path = require('path') const paths = require('.\/paths') const chalk = require('react-dev-utils\/chalk') const resolve = require('resolve')  const slicePath = p =&gt; p.slice(0, p.indexOf('*') - 1)  \/\/ ...  function getWebpackAliases(options = {}) {     const baseUrl = options.baseUrl      if (!baseUrl) {         return {}     }      let resultAlias = {src: paths.appSrc}          return Object.assign({}, resultAlias,             Object.keys(options.paths).reduce(                 (obj, x) =&gt; {                     obj[slicePath(x)] = options.paths[x].map(slicePath)[0]                     return obj                 }, {}             )         ) }  \/\/ ...  function getJestAliases(options = {}) {     const baseUrl = options.baseUrl      if (!baseUrl) {         return {}     }      let resultAlias = {'^src\/(.*)$': '&lt;rootDir&gt;\/src\/$1'}          return Object.assign({}, resultAlias,             Object.keys(options.paths).reduce(                 (obj, x) =&gt; {                     obj[`^${slicePath(x)}(.*)$`] = options.paths[x].map(x =&gt; `&lt;rootDir&gt;\/src\/${slicePath(x)}\/$1`)                     return obj                 }, {}             )         ) }  \/\/ ...<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043d\u0430\u0448 \u043f\u0440\u043e\u0435\u043a\u0442 \u0443\u0441\u043f\u0435\u0448\u043d\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0441 \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u043d\u0430\u043c\u0438 path aliases.<\/p>\n<p>\u041f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435\u0441\u044c \u043d\u0430 \u0437\u0434\u043e\u0440\u043e\u0432\u044c\u0435!<\/p>\n<\/div>\n<p> \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:\/\/habr.com\/ru\/post\/557076\/\"> https:\/\/habr.com\/ru\/post\/557076\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text_v2\" id=\"post-content-body\">\n<p>\u042d\u0442\u043e\u0442 \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b \u043f\u043e\u043c\u043e\u0436\u0435\u0442 \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u0442\u044c path aliases  \u0434\u043b\u044f \u0432\u0430\u0448\u0435\u0433\u043e cretae-react-app.<\/p>\n<details class=\"spoiler\">\n<summary>\u0421\u043e\u0434\u0435\u0440\u0436\u0430\u043d\u0438\u0435<\/summary>\n<div class=\"spoiler__content\">\n<ul>\n<li>\n<p><code>&lt;a href=\"#Intro\"&gt;Introduction &lt;\/a&gt;<\/code><\/p>\n<\/li>\n<li>\n<p><code>&lt;a href=\"#Craco\"&gt;Import Craco &lt;\/a&gt;<\/code><\/p>\n<\/li>\n<li>\n<p><code>&lt;a href=\"#Eject\"&gt;React-scripts eject&lt;\/a&gt;<\/code><\/p>\n<\/li>\n<\/ul>\n<\/div>\n<\/details>\n<h2>\u0412\u0432\u0435\u0434\u0435\u043d\u0438\u0435<\/h2>\n<p><a class=\"anchor\" name=\"Intro\" id=\"Intro\"><\/a><\/p>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043d\u0430\u0447\u043d\u0435\u043c \u0441 \u0442\u043e\u0433\u043e, \u0437\u0430\u0447\u0435\u043c \u0432\u043e\u043e\u0431\u0449\u0435 \u044d\u0442\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e.<\/p>\n<p>\u041f\u043e \u043c\u0435\u0440\u0435 \u0440\u043e\u0441\u0442\u0430 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u0432 \u0438 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u0441\u0435\u0440\u0432\u0438\u0441\u043e\u0432 \u0432 \u0432\u0430\u0448\u0435\u043c \u043f\u0440\u043e\u0435\u043a\u0442\u0435, \u0432\u0441\u0435 \u0447\u0430\u0449\u0435 \u043d\u0430\u0447\u0438\u043d\u0430\u044e\u0442 \u043f\u043e\u044f\u0432\u043b\u044f\u0442\u044c\u0441\u044f \u0442\u0430\u043a\u0438\u0435 \u0438\u043c\u043f\u043e\u0440\u0442\u044b:<\/p>\n<figure class=\"bordered full-width\"><figcaption>\u0412\u044b \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u0442\u0435 \u043d\u0430 \u044d\u0442\u0438\u0445 \u043a\u0440\u043e\u043a\u043e\u0434\u0438\u043b\u043e\u0432 !<\/figcaption><\/figure>\n<p>\u0425\u043e\u0447\u0435\u0442\u0441\u044f \u0437\u0430\u043c\u0435\u043d\u0438\u0442\u044c \u044d\u0442\u0438 \u043f\u0443\u0442\u0438 \u043d\u0430 \u0447\u0442\u043e-\u0442\u043e \u043f\u043e\u0434\u043e\u0431\u043d\u043e\u0435:<\/p>\n<figure class=\"bordered full-width\"><figcaption>\u041d\u0443 \u043a\u0440\u0430\u0441\u043e\u0442\u0430 \u0436\u0435 !<\/figcaption><\/figure>\n<p>\u041d\u0438\u0436\u0435 \u044f \u043f\u0440\u0438\u0432\u0435\u043b 2 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0430 \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u043e\u0439 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b.<\/p>\n<h2>Import craco<\/h2>\n<p><a class=\"anchor\" name=\"Craco\" id=\"Craco\"><\/a><\/p>\n<p>\u0421\u0430\u043c\u044b\u0439 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 &#8212; \u044d\u0442\u043e \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f <a href=\"https:\/\/www.npmjs.com\/package\/@craco\/craco\" rel=\"noopener noreferrer nofollow\">craco<\/a>. \u0423\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0432 \u043f\u0430\u043a\u0435\u0442 \u0438 \u0437\u0430\u043c\u0435\u043d\u0438\u0432 \u0441\u043a\u0440\u0438\u043f\u0442\u044b, \u043a\u0430\u043a \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043e \u0432 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438, \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u0440\u0438\u0441\u0442\u0443\u043f\u0438\u0442\u044c \u043a \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044e path aliases \u0432 \u0444\u0430\u0439\u043b\u0435 craco.config.js.<\/p>\n<pre><code class=\"javascript\">const path = require('path');  const resolvePath = p =&gt; path.join(path.resolve(__dirname, p))  module.exports = {     \/\/ ...     webpack: {         alias: {             '@components': resolvePath('.\/src\/components'),             '@assets': resolvePath('.\/src\/assets'),             '@services': resolvePath('.\/src\/services')         }     },   \/\/ ... }<\/code><\/pre>\n<h2>React-scripts eject<\/h2>\n<p><a class=\"anchor\" name=\"Eject\" id=\"Eject\"><\/a><\/p>\n<p>\u0412 \u044d\u0442\u043e\u043c \u043c\u0435\u0442\u043e\u0434\u0435 \u044f \u0445\u043e\u0447\u0443 \u0441\u0430\u043c \u043f\u043e\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u0435 \u0444\u0430\u0439\u043b\u044b, \u0430 \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043c\u043d\u0435 \u043d\u0443\u0436\u0435\u043d \u043a \u043d\u0438\u043c \u0434\u043e\u0441\u0442\u0443\u043f. \u041d\u043e, \u0431\u0443\u0434\u044c\u0442\u0435 \u0430\u043a\u043a\u0443\u0440\u0430\u0442\u043d\u044b, \u0432\u0435\u0434\u044c \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u044d\u0442\u043e\u0433\u043e \u0441\u043a\u0440\u0438\u043f\u0442\u0430 <strong>\u041d\u0415\u041e\u0422\u0412\u0420\u0410\u0422\u0418\u041c\u042b<\/strong>!<\/p>\n<pre><code class=\"bash\">npm react-scripts eject<\/code><\/pre>\n<p>\u041f\u043e\u0441\u043b\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0441\u043a\u0440\u0438\u043f\u0442\u0430 \u0443 \u0432\u0430\u0441 \u043f\u043e\u044f\u0432\u044f\u0442\u0441\u044f \u0442\u0430\u043a\u0438\u0435 \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u0438 \u0438 \u0444\u0430\u0439\u043b\u044b \u043a\u0430\u043a :<\/p>\n<ul>\n<li>\n<p>\u0414\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u044f config\/<\/p>\n<\/li>\n<li>\n<p>\u0414\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u044f  scripts\/<\/p>\n<\/li>\n<li>\n<p>\u0424\u0430\u0439\u043b tsconfig.json (\u0438\u043b\u0438 jsconfig.json)<\/p>\n<\/li>\n<\/ul>\n<figure class=\"\"><figcaption><\/figcaption><\/figure>\n<p>\u0418\u0437\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e \u043d\u0443\u0436\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043d\u0430\u0448\u0438 path aliases \u0432 tsconfig.json (\u0438\u043b\u0438 jsconfig.json). \u0414\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431 \u043f\u0440\u0438 \u0441\u0431\u043e\u0440\u043a\u0435 \u043d\u0430\u0448\u0438 \u0441\u043a\u0440\u0438\u043f\u0442\u044b \u0432 \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u0438 config\/ \u043f\u043e\u0434\u0442\u044f\u043d\u0443\u043b\u0438 \u0438\u0445 \u0434\u043b\u044f webpack \u0438 \u0434\u043b\u044f jest.<\/p>\n<pre><code class=\"javascript\">{   \"compilerOptions\": {     \/\/ ...     \"baseUrl\": \".\",     \"paths\": {       \"@components\/*\": [\"src\/components\/*\"],       \"@styled\/*\": [\"src\/components\/styled\/*\"],       \"@pages\/*\": [\"src\/pages\/*\"],       \"@assets\/*\": [\"src\/assets\/*\"],       \"@services\/*\": [\"src\/services\/*\"]     },     \/\/ ...   },   \/\/ ... } <\/code><\/pre>\n<p>\u0414\u0430\u043b\u0435\u0435 \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u043e\u0432\u0435\u0441\u0442\u0438 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u0438\u0435 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0432 \u0444\u0430\u0439\u043b\u0435 modules.js, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442 \u0444\u0430\u0439\u043b \u0438\u0441\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u0439 \u0440\u0430\u043d\u0435\u0435.<\/p>\n<pre><code class=\"javascript\">'use strict'  const fs = require('fs') const path = require('path') const paths = require('.\/paths') const chalk = require('react-dev-utils\/chalk') const resolve = require('resolve')  const slicePath = p =&gt; p.slice(0, p.indexOf('*') - 1)  \/\/ ...  function getWebpackAliases(options = {}) {     const baseUrl = options.baseUrl      if (!baseUrl) {         return {}     }      let resultAlias = {src: paths.appSrc}          return Object.assign({}, resultAlias,             Object.keys(options.paths).reduce(                 (obj, x) =&gt; {                     obj[slicePath(x)] = options.paths[x].map(slicePath)[0]                     return obj                 }, {}             )         ) }  \/\/ ...  function getJestAliases(options = {}) {     const baseUrl = options.baseUrl      if (!baseUrl) {         return {}     }      let resultAlias = {'^src\/(.*)$': '&lt;rootDir&gt;\/src\/$1'}          return Object.assign({}, resultAlias,             Object.keys(options.paths).reduce(                 (obj, x) =&gt; {                     obj[`^${slicePath(x)}(.*)$`] = options.paths[x].map(x =&gt; `&lt;rootDir&gt;\/src\/${slicePath(x)}\/$1`)                     return obj                 }, {}             )         ) }  \/\/ ...<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043d\u0430\u0448 \u043f\u0440\u043e\u0435\u043a\u0442 \u0443\u0441\u043f\u0435\u0448\u043d\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0441 \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u043d\u0430\u043c\u0438 path aliases.<\/p>\n<p>\u041f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435\u0441\u044c \u043d\u0430 \u0437\u0434\u043e\u0440\u043e\u0432\u044c\u0435!<\/p>\n<\/div>\n<p> \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:\/\/habr.com\/ru\/post\/557076\/\"> https:\/\/habr.com\/ru\/post\/557076\/<\/a><br \/><\/br><\/br><\/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-323010","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/323010","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=323010"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/323010\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=323010"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=323010"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=323010"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}