{"id":307920,"date":"2020-08-03T15:01:18","date_gmt":"2020-08-03T15:01:18","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=307920"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=307920","title":{"rendered":"\u041a\u0430\u043a \u044f \u0432\u044b\u043a\u0438\u043d\u0443\u043b webpack \u0438 \u043d\u0430\u043f\u0438\u0441\u0430\u043b babel-plugin \u0434\u043b\u044f \u0442\u0440\u0430\u043d\u0441\u043f\u0438\u043b\u0430 scss\/sass"},"content":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/post\/513564\/\">\n<h3>\u041f\u0440\u0435\u0434\u044b\u0441\u0442\u043e\u0440\u0438\u044f<\/h3>\n<p>  \u041a\u0430\u043a-\u0442\u043e \u0441\u0443\u0431\u0431\u043e\u0442\u043d\u0438\u043c \u0432\u0435\u0447\u0435\u0440\u043e\u043c \u044f \u0441\u0438\u0434\u0435\u043b \u0438 \u0438\u0441\u043a\u0430\u043b \u0441\u043f\u043e\u0441\u043e\u0431\u044b \u0441\u0431\u043e\u0440\u043a\u0438 UI-Kit \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e webpack. \u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0434\u0435\u043c\u043e UI-kit \u044f \u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0441\u044c styleguidst. \u041a\u043e\u043d\u0435\u0447\u043d\u043e \u0436\u0435, webpack \u0443\u043c\u043d\u044b\u0439 \u0438 \u0432\u0441\u0435 \u0444\u0430\u0439\u043b\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0435\u0441\u0442\u044c \u0432 \u0440\u0430\u0431\u043e\u0447\u0435\u043c \u043a\u0430\u0442\u0430\u043b\u043e\u0433\u0435 \u043e\u043d \u0437\u0430\u043f\u0438\u0445\u0438\u0432\u0430\u0435\u0442 \u0432 \u043e\u0434\u0438\u043d \u0431\u0430\u043d\u0434\u043b \u0438 \u043e\u0442\u0442\u0443\u0434\u0430 \u0432\u0441\u0451 \u043a\u0440\u0443\u0442\u0438\u0442\u0441\u044f \u0438 \u0432\u0435\u0440\u0442\u0438\u0442\u0441\u044f.<\/p>\n<p>  \u042f \u0441\u043e\u0437\u0434\u0430\u043b \u0444\u0430\u0439\u043b entry.js, \u0438\u043c\u043f\u043e\u0440\u0442\u043d\u0443\u043b \u0442\u0443\u0434\u0430 \u0432\u0441\u0435 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b, \u0437\u0430\u0442\u0435\u043c \u043e\u0442\u0442\u0443\u0434\u0430 \u0436\u0435 \u044d\u043a\u0441\u043f\u043e\u0440\u0442\u043d\u0443\u043b. \u0412\u0440\u043e\u0434\u0435 \u0432\u0441\u0451 \u043e\u043a.<\/p>\n<pre><code class=\"javascript\">import Button from 'components\/Button' import Dropdown from 'components\/Dropdown '  export {   Button,   Dropdown  } <\/code><\/pre>\n<p>  \u0418 \u043f\u043e\u0441\u043b\u0435 \u0441\u0431\u043e\u0440\u043a\u0438 \u0432\u0441\u0435\u0433\u043e \u044d\u0442\u043e\u0433\u043e, \u044f \u043f\u043e\u043b\u0443\u0447\u0438\u043b \u043d\u0430 \u0432\u044b\u0445\u043e\u0434\u0435 output.js, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043a\u0430\u043a \u0438 \u043e\u0436\u0438\u0434\u0430\u043b\u043e\u0441\u044c \u0431\u044b\u043b\u043e \u0432\u0441\u0451 \u2014 \u0432\u0441\u0435 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b \u0432 \u043a\u0443\u0447\u0435 \u0432 \u043e\u0434\u043d\u043e\u043c \u0444\u0430\u0439\u043b\u0435. \u0422\u0443\u0442 \u0432\u043e\u0437\u043d\u0438\u043a \u0432\u043e\u043f\u0440\u043e\u0441:  <\/p>\n<blockquote><p>\u0410 \u043a\u0430\u043a \u043c\u043d\u0435 \u0441\u043e\u0431\u0440\u0430\u0442\u044c \u0432\u0441\u0435 \u043a\u043d\u043e\u043f\u043e\u0447\u043a\u0438, \u0434\u0440\u043e\u043f\u0434\u0430\u0443\u043d\u044b \u0438 \u043f\u0440\u043e\u0447\u0435\u0435 \u043f\u043e \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438, \u0447\u0442\u043e \u0431\u044b \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432 \u0434\u0440\u0443\u0433\u0438\u0445 \u043f\u0440\u043e\u0435\u043a\u0442\u0430\u0445?   <\/p><\/blockquote>\n<p>\u0410 \u044f \u0432\u0435\u0434\u044c \u0445\u043e\u0447\u0443 \u044d\u0442\u043e \u0435\u0449\u0451 \u0438 \u0432 npm \u0437\u0430\u043b\u0438\u0442\u044c \u043a\u0430\u043a \u043f\u0430\u043a\u0435\u0442.<\/p>\n<p>  \u0425\u043c\u2026 \u041f\u043e\u0435\u0445\u0430\u043b\u0438 \u043f\u043e \u043f\u043e\u0440\u044f\u0434\u043a\u0443.<br \/>  <a name=\"habracut\"><\/a>  <\/p>\n<h3>Multiple entries<\/h3>\n<p>  \u041a\u043e\u043d\u0435\u0447\u043d\u043e, \u043f\u0435\u0440\u0432\u0430\u044f \u0438\u0434\u0435\u044f, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0438\u0439\u0442\u0438 \u0432 \u0433\u043e\u043b\u043e\u0432\u0443 \u2014 \u0441\u043f\u0430\u0440\u0441\u0438\u0442\u044c \u0432\u0441\u0435 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b \u0432 \u0440\u0430\u0431\u043e\u0447\u0435\u043c \u043a\u0430\u0442\u0430\u043b\u043e\u0433\u0435. \u041f\u0440\u0438\u0448\u043b\u043e\u0441\u044c \u043d\u0435\u043c\u043d\u043e\u0436\u043a\u043e \u043f\u043e\u0433\u0443\u0433\u043b\u0438\u0442\u044c \u043f\u0440\u043e \u043f\u0430\u0440\u0441\u0438\u043d\u0433 \u0444\u0430\u0439\u043b\u043e\u0432, \u0442.\u043a \u0441 NodeJS \u044f \u0440\u0430\u0431\u043e\u0442\u0430\u044e \u043e\u0447\u0435\u043d\u044c \u0440\u0435\u0434\u043a\u043e. \u041d\u0430\u0448\u0451\u043b \u0442\u0430\u043a\u0443\u044e \u0448\u0442\u0443\u043a\u0443, \u043a\u0430\u043a <b>glob<\/b>.<\/p>\n<p>  \u041f\u043e\u0433\u043d\u0430\u043b\u0438 \u043f\u0438\u0441\u0430\u0442\u044c multiple entries.<\/p>\n<pre><code class=\"javascript\">const { basename, join, resolve } = require(&quot;path&quot;); const glob = require(&quot;glob&quot;);  const componentFileRegEx = \/\\.(j|t)s(x)?$\/; const sassFileRegEx = \/\\s[ac]ss$\/;  const getComponentsEntries = (pattern) =&gt; {   const entries = {};   glob.sync(pattern).forEach(file =&gt; {     const outFile = basename (file);     const entryName = outFile.replace(componentFileRegEx, &quot;&quot;);     entries[entryName] = join(__dirname, file);   })   return entries; }  module.exports = {   entry: getComponentsEntries(&quot;.\/components\/**\/*.tsx&quot;),   output: {     filename: &quot;[name].js&quot;,     path: resolve(__dirname, &quot;build&quot;)   },   module: {     rules: [       {         test: componentFileRegEx,         loader: &quot;babel-loader&quot;,         exclude: \/node_modules\/       },       {         test: sassFileRegEx,         use: [&quot;style-loader&quot;, &quot;css-loader&quot;, &quot;sass-loader&quot;]       }     ]   }   resolve: {     extensions: [&quot;.js&quot;, &quot;.ts&quot;, &quot;.tsx&quot;, &quot;.jsx&quot;],     alias: {       components: resolve(__dirname, &quot;components&quot;)     }   } } <\/code><\/pre>\n<p>  \u0413\u043e\u0442\u043e\u0432\u043e. \u0421\u043e\u0431\u0438\u0440\u0430\u0435\u043c.<\/p>\n<p>  \u041f\u043e\u0441\u043b\u0435 \u0441\u0431\u043e\u0440\u043a\u0438 \u0432 \u043a\u0430\u0442\u0430\u043b\u043e\u0433 build \u0443\u043f\u0430\u043b\u043e 2 \u0444\u0430\u0439\u043b\u0430 Button.js, Dropdown.js \u2014 \u0437\u0430\u0433\u043b\u044f\u0434\u044b\u0432\u0430\u0435\u043c \u0432\u043d\u0443\u0442\u0440\u044c. \u0412\u043d\u0443\u0442\u0440\u0438 \u043b\u0438\u0446\u0435\u043d\u0437\u0438\u0438 react.production.min.js, \u0442\u044f\u0436\u0435\u043b\u043e\u0447\u0438\u0442\u0430\u0435\u043c\u044b\u0439 \u043c\u0438\u043d\u0438\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043a\u043e\u0434, \u0438 \u043a\u0443\u0447\u0430 \u0432\u0441\u044f\u043a\u043e\u0439 \u0444\u0438\u0433\u043d\u0438. \u041e\u043a\u0435\u0439, \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043a\u043d\u043e\u043f\u043a\u0443.<\/p>\n<p>  \u0412 \u0434\u0435\u043c\u043e \u0444\u0430\u0439\u043b\u0435 \u043a\u043d\u043e\u043f\u043a\u0438 \u043c\u0435\u043d\u044f\u0435\u043c \u0438\u043c\u043f\u043e\u0440\u0442 \u043d\u0430 \u0438\u043c\u043f\u043e\u0440\u0442 \u0438\u0437 \u043a\u0430\u0442\u0430\u043b\u043e\u0433\u0430 build.<\/p>\n<p>  \u0412\u043e\u0442 \u0442\u0430\u043a \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u043f\u0440\u043e\u0441\u0442\u0430\u044f \u0434\u0435\u043c\u043a\u0430 \u043a\u043d\u043e\u043f\u043a\u0438 \u0432 styleguidist \u2014 Button.md<\/p>\n<pre><code class=\"markdown\">```javascript import Button from '..\/..\/build\/Button' &lt;Button&gt;\u041a\u043d\u043e\u043f\u043a\u0430&lt;\/Button&gt; ``` <\/code><\/pre>\n<p>  \u0417\u0430\u0445\u043e\u0434\u0438\u043c \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043d\u0430 \u043a\u043d\u043e\u043f\u043e\u0447\u043a\u0443 \u0438\u0438\u0438\u2026<\/p>\n<p>  <code><font color=\"#f52c2c\">Error: Element type is invalid: expected a string (for built-in components) or a class\/function (for composite components) but got: object.<\/font><br \/>  <\/code><\/p>\n<p>  \u041d\u0430 \u044d\u0442\u043e\u043c \u044d\u0442\u0430\u043f\u0435 \u0443\u0436\u0435 \u043e\u0442\u043f\u0430\u043b\u0438 \u0438\u0434\u0435\u044f \u0438 \u0436\u0435\u043b\u0430\u043d\u0438\u0435 \u0441\u043e\u0431\u0438\u0440\u0430\u0442\u044c \u0447\u0435\u0440\u0435\u0437 webpack.<\/p>\n<h3>\u0418\u0449\u0435\u043c \u0434\u0440\u0443\u0433\u043e\u0439 \u043f\u0443\u0442\u044c \u0441\u0431\u043e\u0440\u043a\u0438 \u0431\u0435\u0437 webpack<\/h3>\n<p>  \u0418\u0434\u0451\u043c \u0437\u0430 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a \u0431\u0430\u0431\u0435\u043b\u044e \u0431\u0435\u0437 \u0432\u0435\u0431\u043f\u0430\u043a\u0430. \u041f\u0438\u0448\u0435\u043c \u0441\u043a\u0440\u0438\u043f\u0442 \u0432 package.json, \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c \u0444\u0430\u0439\u043b \u043a\u043e\u043d\u0444\u0438\u0433\u0430, \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u044f, \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u044e \u0433\u0434\u0435 \u043b\u0435\u0436\u0430\u0442 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b, \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u044e \u043a\u0443\u0434\u0430 \u0441\u043e\u0431\u0440\u0430\u0442\u044c:<\/p>\n<pre><code class=\"json\">{   \/\/...package.json \u0432\u0441\u044f\u043a\u0438\u0435 \u0448\u0442\u0443\u043a\u0438-\u0434\u0440\u044e\u043a\u0438 \u043e \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043e\u0431\u044b\u0447\u043d\u043e \u043d\u0435 \u043f\u0430\u0440\u0438\u043c\u0441\u044f   scripts: {     &quot;build&quot;: &quot;babel --config-file .\/.babelrc --extensions '.jsx, .tsx' .\/components --out-dir .\/build&quot;   } } <\/code><\/pre>\n<p>  \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c:<\/p>\n<pre><code class=\"powershell\">npm run build<\/code><\/pre>\n<p>  \u0412\u0443\u0430\u043b\u044f, \u0443 \u043d\u0430\u0441 \u0432 \u043a\u0430\u0442\u0430\u043b\u043e\u0433\u0435 build \u043f\u043e\u044f\u0432\u0438\u043b\u0438\u0441\u044c 2 \u0444\u0430\u0439\u043b\u0430 Button.js, Dropdown.js, \u0432\u043d\u0443\u0442\u0440\u0438 \u0444\u0430\u0439\u043b\u043e\u0432 \u043a\u0440\u0430\u0441\u0438\u0432\u043e \u043e\u0444\u043e\u0440\u043c\u043b\u0435\u043d\u043d\u044b\u0439 \u0432\u0430\u043d\u0438\u043b\u044c\u043d\u044b\u0439 js + \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u043b\u0438\u0444\u0438\u043b\u044b \u0438 \u043e\u0434\u0438\u043d\u043e\u043a\u0438\u0439 <i>requre(\u00abstyles.scss\u00bb)<\/i>. \u042f\u0432\u043d\u043e \u044d\u0442\u043e \u043d\u0435 \u0441\u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0432 \u0434\u0435\u043c\u043a\u0435, \u0443\u0434\u0430\u043b\u044f\u0435\u043c \u0438\u043c\u043f\u043e\u0440\u0442 \u0441\u0442\u0438\u043b\u0435\u0439(\u0432 \u044d\u0442\u043e\u0442 \u043c\u043e\u043c\u0435\u043d\u0442 \u043c\u0435\u043d\u044f \u0433\u043b\u043e\u0436\u0438\u043b\u0430 \u043d\u0430\u0434\u0435\u0436\u0434\u0430, \u0447\u0442\u043e \u044f \u043d\u0430\u0439\u0434\u0443 \u043f\u043b\u0430\u0433\u0438\u043d \u0434\u043b\u044f \u0442\u0440\u0430\u043d\u0441\u043f\u0438\u043b\u0430 scss), \u0441\u043e\u0431\u0438\u0440\u0430\u0435\u043c \u0435\u0449\u0451 \u0440\u0430\u0437.<\/p>\n<p>  \u041f\u043e\u0441\u043b\u0435 \u0441\u0431\u043e\u0440\u043a\u0438 \u0443 \u043d\u0430\u0441 \u043e\u0441\u0442\u0430\u043b\u0441\u044f \u0447\u0438\u0442\u0441\u044b\u0439 JS. \u041f\u043e\u0432\u0442\u043e\u0440\u044f\u0435\u043c \u043f\u043e\u043f\u044b\u0442\u043a\u0443 \u0438\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u0438 \u0441\u043e\u0431\u0440\u0430\u043d\u043d\u043e\u0433\u043e \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430 \u0432 styleguidist:<\/p>\n<pre><code class=\"markdown\">```javascript import Button from '..\/..\/build\/Button' &lt;Button&gt;\u041a\u043d\u043e\u043f\u043a\u0430&lt;\/Button&gt; ``` <\/code><\/pre>\n<p>  \u0421\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u043b\u043e\u0441\u044c \u2014 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442. \u0422\u043e\u043b\u044c\u043a\u043e \u043a\u043d\u043e\u043f\u043e\u0447\u043a\u0430 \u0431\u0435\u0437 \u0441\u0442\u0438\u043b\u0435\u0439.<\/p>\n<h3>\u0418\u0449\u0435\u043c \u043f\u043b\u0430\u0433\u0438\u043d \u0434\u043b\u044f \u0442\u0440\u0430\u043d\u0441\u043f\u0438\u043b\u0430 scss\/sass<\/h3>\n<p>  \u0414\u0430, \u0441\u0431\u043e\u0440\u043a\u0430 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u0432 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442, \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0442, \u043c\u043e\u0436\u043d\u043e \u0441\u043e\u0431\u0438\u0440\u0430\u0442\u044c, \u043f\u0430\u0431\u043b\u0438\u0448\u0438\u0442\u044c \u0432 npm \u0438\u043b\u0438 \u0441\u0432\u043e\u0439 \u0440\u0430\u0431\u043e\u0447\u0438\u0439 \u043d\u0435\u0445\u0443\u0441(nexus). \u0415\u0449\u0451 \u0431\u044b \u0442\u043e\u043b\u044c\u043a\u043e \u0441\u0442\u0438\u043b\u0438 \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u0442\u044c\u2026 \u041e\u043a\u0435\u0439, \u0441\u043d\u043e\u0432\u0430 \u0433\u0443\u0433\u043b \u043d\u0430\u043c \u043f\u043e\u043c\u043e\u0436\u0435\u0442 (\u043d\u0435\u0442).<\/p>\n<p>  \u0413\u0443\u0433\u043b\u0435\u043d\u0438\u044f \u043f\u043b\u0430\u0433\u0438\u043d\u043e\u0432 \u043d\u0435 \u043f\u0440\u0438\u043d\u0435\u0441\u043b\u0438 \u043c\u043d\u0435 \u043a\u0430\u043a\u0438\u0445-\u0442\u043e \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432. \u041e\u0434\u0438\u043d \u043f\u043b\u0430\u0433\u0438\u043d \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442 \u0441\u0442\u0440\u043e\u043a\u0443 \u0438\u0437 \u0441\u0442\u0438\u043b\u0435\u0439, \u0434\u0440\u0443\u0433\u043e\u0439 \u0432\u043e\u043e\u0431\u0449\u0435 \u043d\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0434\u0430 \u0435\u0449\u0451 \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u0438\u043c\u043f\u043e\u0440\u0442\u0430 \u0432\u0438\u0434\u0430:<i>import styles from \u00abstyles.scss\u00bb<\/i><\/p>\n<p>  \u0415\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u0430\u044f \u043d\u0430\u0434\u0435\u0436\u0434\u0430 \u0431\u044b\u043b\u0430 \u043d\u0430 \u044d\u0442\u043e\u0442 \u043f\u043b\u0430\u0433\u0438\u043d: <i>babel-plugin-transform-scss-import-to-string<\/i>, \u043d\u043e \u043e\u043d \u043f\u0440\u043e\u0441\u0442\u043e \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442 \u0441\u0442\u0440\u043e\u043a\u0443 \u0438\u0437 \u0441\u0442\u0438\u043b\u0435\u0439 (\u0430\u2026 \u044f \u0443\u0436\u0435 \u0433\u043e\u0432\u043e\u0440\u0438\u043b \u0432\u044b\u0448\u0435. \u0411\u043b\u0438\u043d&#8230;). \u0414\u0430\u043b\u044c\u0448\u0435 \u0432\u0441\u0451 \u0441\u0442\u0430\u043b\u043e \u0435\u0449\u0451 \u0445\u0443\u0436\u0435, \u044f \u0434\u043e\u0448\u0435\u043b \u0434\u043e 6 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b \u0432 \u0433\u0443\u0433\u043b\u0435 (\u0430 \u043d\u0430 \u0447\u0430\u0441\u0430\u0445 \u0443\u0436\u0435 3 \u0443\u0442\u0440\u0430). \u0414\u0430 \u0438 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u043e\u0432 \u043e\u0441\u043e\u0431\u043e \u0443\u0436\u0435 \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u0447\u0442\u043e-\u0442\u043e \u043d\u0430\u0439\u0442\u0438. \u0414\u0430 \u0438 \u0434\u0443\u043c\u0430\u0442\u044c \u0442\u043e \u043d\u0435\u0447\u0435\u0433\u043e \u2014 \u043b\u0438\u0431\u043e webpack + sass-loader, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0445\u0440\u0435\u043d\u043e\u0432\u043e \u044d\u0442\u043e \u0434\u0435\u043b\u0430\u044e\u0442 \u0438 \u043d\u0435 \u0434\u043b\u044f \u043c\u043e\u0435\u0433\u043e \u0441\u043b\u0443\u0447\u0430\u044f, \u043b\u0438\u0431\u043e \u0428\u0422\u041e-\u0422\u041e \u0414\u0420\u0423\u0413\u041e\u0415. \u041d\u0435\u0440\u0432\u044b\u2026 \u042f \u0440\u0435\u0448\u0438\u043b \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043f\u0435\u0440\u0435\u0434\u043e\u0445\u043d\u0443\u0442\u044c, \u043f\u043e\u043f\u0438\u0442\u044c \u0447\u0430\u0439, \u0441\u043f\u0430\u0442\u044c \u0432\u0441\u0451 \u0440\u0430\u0432\u043d\u043e \u043d\u0435 \u0445\u043e\u0447\u0435\u0442\u0441\u044f. \u041f\u043e\u043a\u0430 \u0434\u0435\u043b\u0430\u043b \u0447\u0430\u0439, \u0438\u0434\u0435\u044f \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043f\u043b\u0430\u0433\u0438\u043d \u0434\u043b\u044f \u0442\u0440\u0430\u043d\u0441\u043f\u0438\u043b\u0430 scss\/sass \u0432\u0441\u0435 \u0431\u043e\u043b\u044c\u0448\u0435 \u0438 \u0431\u043e\u043b\u044c\u0448\u0435 \u0432\u043b\u0435\u0442\u0430\u043b\u0430 \u0432 \u043c\u043e\u044e \u0433\u043e\u043b\u043e\u0432\u0443. \u041f\u043e\u043a\u0430 \u043c\u0435\u0448\u0430\u043b \u0441\u0430\u0445\u0430\u0440\u043e\u0447\u0435\u043a, \u0440\u0435\u0434\u043a\u0438\u0435 \u0437\u0432\u043e\u043d\u044b \u043b\u043e\u0436\u043a\u0438 \u0432 \u043c\u043e\u0435\u0439 \u0433\u043e\u043b\u043e\u0432\u0435 \u043e\u0442\u0434\u0430\u0432\u0430\u043b\u0438\u0441\u044c \u044d\u0445\u043e\u043c: \u00ab\u041f\u0438\u0448\u0438 \u043f\u043b\u0430\u0430\u0430\u0433\u0438\u043d\u00bb. \u041e\u043a, \u0440\u0435\u0448\u0435\u043d\u043e, \u0431\u0443\u0434\u0443 \u043f\u0438\u0441\u0430\u0442\u044c \u043f\u043b\u0430\u0433\u0438\u043d. <\/p>\n<h3>\u041f\u043b\u0430\u0433\u0438\u043d \u043d\u0435 \u043d\u0430\u0439\u0434\u0435\u043d. \u041f\u0438\u0448\u0435\u043c \u0441\u0430\u043c\u0438<\/h3>\n<p>  \u0417\u0430 \u043e\u0441\u043d\u043e\u0432\u0443 \u0441\u0432\u043e\u0435\u0433\u043e \u043f\u043b\u0430\u0433\u0438\u043d\u0430 \u044f \u0432\u0437\u044f\u043b <i>babel-plugin-transform-scss-import-to-string<\/i>, \u0443\u043f\u043e\u043c\u044f\u043d\u0443\u0442\u044b\u0439 \u0432\u044b\u0448\u0435. \u042f \u043f\u0440\u0435\u043a\u0440\u0430\u0441\u043d\u043e \u043f\u043e\u043d\u0438\u043c\u0430\u043b, \u0447\u0442\u043e \u0441\u0435\u0439\u0447\u0430\u0441 \u0431\u0443\u0434\u0435\u0442 \u0433\u0435\u043c\u043e\u0440\u0440\u043e\u0439 \u0441 AST \u0434\u0435\u0440\u0435\u0432\u043e\u043c, \u0438 \u043f\u0440\u043e\u0447\u0438\u043c\u0438 \u0445\u0438\u0442\u0440\u043e\u0441\u0442\u044f\u043c\u0438. \u041b\u0430\u0434\u043d\u043e, \u043f\u043e\u0435\u0445\u0430\u043b\u0438. <\/p>\n<p>  \u0414\u0435\u043b\u0430\u0435\u043c \u043f\u0440\u0435\u0434\u0432\u0430\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043e\u0447\u043a\u0438. \u041d\u0430\u043c \u043d\u0443\u0436\u043d\u044b node-sass \u0438 path, \u0430 \u0442\u0430\u043a \u0436\u0435 \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043e\u0447\u043a\u0438 \u0434\u043b\u044f \u0444\u0430\u0439\u043b\u043e\u0432 \u0438 \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u0439. \u0418\u0434\u0435\u044f \u0442\u0430\u043a\u0430\u044f: <\/p>\n<ul>\n<li>\u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0438\u0437 \u0441\u0442\u0440\u043e\u043a\u0438 \u0438\u043c\u043f\u043e\u0440\u0442\u0430 \u043f\u0443\u0442\u044c \u0434\u043e \u0444\u0430\u0439\u043b\u0430 \u0441\u043e \u0441\u0442\u0438\u043b\u044f\u043c\u0438 <\/li>\n<li>\u041f\u0430\u0440\u0441\u0438\u043c \u0447\u0435\u0440\u0435\u0437 node-sass \u0441\u0442\u0438\u043b\u0438 \u0432 \u0441\u0442\u0440\u043e\u043a\u0443 (\u0441\u043f\u0430\u0441\u0438\u0431\u043e babel-plugin-transform-scss-import-to-string)<\/li>\n<li>\u0421\u043e\u0437\u0434\u0430\u0435\u043c style \u0442\u0435\u0433\u0438 \u043f\u043e \u043a\u0430\u0436\u0434\u043e\u043c\u0443 \u0438\u0437 \u0438\u043c\u043f\u043e\u0440\u0442\u043e\u0432 (\u043f\u043b\u0430\u0433\u0438\u043d \u0431\u0430\u0431\u0435\u043b\u044f \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442\u0441\u044f \u043d\u0430 \u043a\u0430\u0436\u0434\u043e\u043c \u0438\u043c\u043f\u043e\u0440\u0442\u0435)<\/li>\n<li>\u041d\u0430\u0434\u043e \u043a\u0430\u043a-\u0442\u043e \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u0446\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0439 \u0441\u0442\u0438\u043b\u044c, \u0447\u0442\u043e \u0431\u044b \u043d\u0435 \u043d\u0430\u043a\u0438\u0434\u044b\u0432\u0430\u0442\u044c \u043e\u0434\u043d\u043e \u0438 \u0442\u043e \u0436\u0435 \u043d\u0430 \u043a\u0430\u0436\u0434\u044b\u0439 \u0447\u0438\u0445 hot-reload. \u0412\u043f\u0438\u0445\u043d\u0435\u043c \u0435\u043c\u0443 \u043a\u0430\u043a\u043e\u0439-\u043d\u0438\u0431\u0443\u0434\u044c \u0430\u0442\u0442\u0440\u0438\u0431\u0443\u0442 (data-sass-component) \u0441\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c \u0442\u0435\u043a\u0443\u0449\u0435\u0433\u043e \u0444\u0430\u0439\u043b\u0430 \u0438 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435\u043c \u0444\u0430\u0439\u043b\u0430 \u0441\u0442\u0438\u043b\u0435\u0439. \u0411\u0443\u0434\u0435\u0442 \u0447\u0442\u043e-\u0442\u043e \u0432\u0440\u043e\u0434\u0435 \u044d\u0442\u043e\u0433\u043e:\n<pre><code class=\"xml\">      &lt;style data-sass-component=&quot;Button_style&quot;&gt;          .button {             display: flex;          }       &lt;\/style&gt; <\/code><\/pre>\n<\/li>\n<\/ul>\n<p>  \u0412 \u0446\u0435\u043b\u044f\u0445 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043f\u043b\u0430\u0433\u0438\u043d\u0430 \u0438 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043d\u0430 \u043f\u0440\u043e\u0435\u043a\u0442\u0435, \u043d\u0430 \u0443\u0440\u043e\u0432\u043d\u0435 \u0441 \u043a\u0430\u0442\u0430\u043b\u043e\u0433\u043e\u043c components \u044f \u0441\u043e\u0437\u0434\u0430\u043b babel-plugin-transform-scss \u043a\u0430\u0442\u0430\u043b\u043e\u0433, \u0437\u0430\u043f\u0438\u0445\u043d\u0443\u043b \u0442\u0443\u0434\u0430 package.json \u0438 \u0437\u0430\u043f\u0438\u0445\u043d\u0443\u043b \u0442\u0443\u0434\u0430 \u043a\u0430\u0442\u0430\u043b\u043e\u0433 lib, \u0430 \u0432 \u043d\u0435\u0433\u043e \u0443\u0436\u0435 \u0437\u0430\u043a\u0438\u043d\u0443\u043b index.js.   <\/p>\n<blockquote><p>\u0427\u0442\u043e \u0431\u044b \u0432\u044b \u0431\u044b\u043b\u0438 \u0432\u043a\u0443\u0440\u0441\u0435 \u2014 \u043a\u043e\u043d\u0444\u0438\u0433 \u0431\u0430\u0431\u0435\u043b\u044f \u043b\u0435\u0437\u0435\u0442 \u0437\u0430 \u043f\u043b\u0430\u0433\u0438\u043d\u043e\u043c, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0443\u043a\u0430\u0437\u0430\u043d \u0432 \u0434\u0438\u0440\u0435\u043a\u0442\u0438\u0432\u0435 main \u0432 package.json, \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043f\u0440\u0438\u0448\u043b\u043e\u0441\u044c \u0435\u0433\u043e \u0437\u0430\u043f\u0438\u0445\u0430\u0442\u044c.<\/p><\/blockquote>\n<p> \u0423\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c:<\/p>\n<pre><code class=\"json\">{   \/\/...package.json \u043e\u043f\u044f\u0442\u044c \u0432\u0441\u044f\u043a\u0438\u0435 \u0448\u0442\u0443\u043a\u0438-\u0434\u0440\u044e\u043a\u0438 \u043e \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043e\u0431\u044b\u0447\u043d\u043e \u043d\u0435 \u043f\u0430\u0440\u0438\u043c\u0441\u044f, \u0434\u0430 \u0438 \u043a\u0440\u043e\u043c\u0435 main \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435\u0442\u0443   main: &quot;lib\/index.js&quot; } <\/code><\/pre>\n<p>  \u0417\u0430\u0442\u0435\u043c, \u043f\u0438\u0445\u0430\u0435\u043c \u0432 \u043a\u043e\u043d\u0444\u0438\u0433 \u0431\u0430\u0431\u0435\u043b\u044f (.babelrc) \u043f\u0443\u0442\u044c \u0434\u043e \u043f\u043b\u0430\u0433\u0438\u043d\u0430:<\/p>\n<pre><code class=\"json\">{   \/\/\u0422\u0443\u0442 \u0432\u0441\u044f\u043a\u0438\u0435 \u043f\u0440\u0435\u0441\u0435\u0442\u044b   plugins: [     &quot;.\/babel-plugin-transform-scss&quot;     \/\/\u0442\u0443\u0442 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u043f\u043b\u0430\u0433\u0438\u043d\u044b \u0434\u043b\u044f \u0441\u0431\u043e\u0440\u043a\u0438   ] } <\/code><\/pre>\n<p>  \u0410 \u0442\u0435\u043f\u0435\u0440\u044c \u043d\u0430\u043f\u0438\u0445\u0438\u0432\u0430\u0435\u043c \u0432 index.js \u043c\u0430\u0433\u0438\u044e.<\/p>\n<p>  \u041f\u0435\u0440\u0432\u044b\u0439 \u044d\u0442\u0430\u043f \u2014 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u043d\u0430 \u0438\u043c\u043f\u043e\u0440\u0442 \u0438\u043c\u0435\u043d\u043d\u043e scss \u0438\u043b\u0438 sass \u0444\u0430\u0439\u043b\u0430, \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0438\u043c\u0435\u043d\u0438 \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c\u044b\u0445 \u0444\u0430\u0439\u043b\u043e\u0432, \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0438\u043c\u0435\u043d\u0438 \u0441\u0430\u043c\u043e\u0433\u043e js \u0444\u0430\u0439\u043b\u0430(\u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430), \u0442\u0440\u0430\u043d\u0441\u043f\u0438\u043b \u0432 css \u0441\u0442\u0440\u043e\u043a\u0443 scss \u0438\u043b\u0438 sass. \u041f\u043e\u0434\u0440\u0443\u0431\u0430\u0435\u043c\u0441\u044f \u0447\u0435\u0440\u0435\u0437 WebStorm \u043a npm run build \u0447\u0435\u0440\u0435\u0437 \u0434\u0435\u0431\u0430\u0433\u0433\u0435\u0440, \u0441\u0442\u0430\u0432\u0438\u043c \u0442\u043e\u0447\u043a\u0438 \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u0430, \u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b path \u0438 state \u0438 \u0432\u044b\u0443\u0436\u0438\u0432\u0430\u0435\u043c \u0438\u043c\u0435\u043d\u0430 \u0444\u0430\u0439\u043b\u043e\u0432, \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u043c \u0440\u0443\u0433\u043b\u044f\u0440\u043e\u0447\u043a\u0430\u043c\u0438:<\/p>\n<pre><code class=\"javascript\">const { resolve, dirname, join } = require(&quot;path&quot;); const { renderSync } = require(&quot;node-sass&quot;);  const regexps = {   sassFile: \/([A-Za-z0-9]+).s[ac]ss\/g,   sassExt: \/\\.s[ac]ss$\/,   currentFile: \/([A-Za-z0-9]+).(t|j)s(x)\/g,   currentFileExt: \/.(t|j)s(x)\/g };  function transformScss(babel) {   const { types: t } = babel;   return {     name: &quot;babel-plugin-transform-scss&quot;,     visitor: {       ImportDeclaration(path, state) {         \/**          * \u041f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c, \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u043b\u0438 \u0442\u0435\u043a\u0443\u0449\u0438\u0439 \u0444\u0430\u0439\u043b scss\/sass \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u044f \u0432 \u0438\u043c\u043f\u043e\u0440\u0442\u0435          *\/         if (!regexps.sassExt.test(path.node.source.value)) return;         const sassFileNameMatch = path.node.source.value.match(           regexps.sassFile         );          \/**          * \u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0438\u043c\u044f \u0442\u0435\u043a\u0443\u0449\u0435\u0433\u043e scss\/sass \u0444\u0430\u0439\u043b\u0430 \u0438 \u0442\u0435\u043a\u0443\u0449\u0435\u0433\u043e js \u0444\u0430\u0439\u043b\u0430          *\/         const sassFileName = sassFileNameMatch[0].replace(regexps.sassExt, &quot;&quot;);         const file = this.filename.match(regexps.currentFile);         const filename = `${file[0].replace(           regexps.currentFileExt,           &quot;&quot;         )}_${sassFileName}`;          \/**          *          * \u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u043f\u043e\u043b\u043d\u044b\u0439 \u043f\u0443\u0442\u044c \u0434\u043e scss\/sass \u0444\u0430\u0439\u043b\u0430, \u0442\u0440\u0430\u043d\u0441\u043f\u0438\u043b\u0438\u043c \u0432 \u0441\u0442\u0440\u043e\u043a\u0443 css          *\/         const scssFileDirectory = resolve(dirname(state.file.opts.filename));         const fullScssFilePath = join(           scssFileDirectory,           path.node.source.value         );         const projectRoot = process.cwd();         const nodeModulesPath = join(projectRoot, &quot;node_modules&quot;);         const sassDefaults = {           file: fullScssFilePath,           sourceMap: false,           includePaths: [nodeModulesPath, scssFileDirectory, projectRoot]         };         const sassResult = renderSync({ ...sassDefaults, ...state.opts });         const transpiledContent = sassResult.css.toString() || &quot;&quot;;         }     } } <\/code><\/pre>\n<p>  Fire. \u041f\u0435\u0440\u0432\u044b\u0439 \u0443\u0441\u043f\u0435\u0445, \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0430 \u0441\u0442\u0440\u043e\u043a\u0430 css \u0432 transpiledContent. \u0414\u0430\u043b\u044c\u0448\u0435 \u0441\u0430\u043c\u043e\u0435 \u0441\u0442\u0440\u0430\u0448\u043d\u043e\u0435 \u2014 \u043b\u0435\u0437\u0435\u043c \u0432 <a href=\"https:\/\/babeljs.io\/docs\/en\/babel-types#api\" rel=\"nofollow\">babeljs.io\/docs\/en\/babel-types#api<\/a> \u0437\u0430 API \u043f\u043e AST \u0434\u0435\u0440\u0435\u0432\u0443. \u041b\u0435\u0437\u0435\u043c \u0432 <a href=\"https:\/\/astexplorer.net\/\" rel=\"nofollow\">astexplorer.net<\/a> \u043f\u0438\u0448\u0435\u043c \u0442\u0430\u043c \u043a\u043e\u0434 \u0437\u0430\u043f\u0438\u0445\u0438\u0432\u0430\u043d\u0438\u044f \u0432 head \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430 \u0441\u0442\u0438\u043b\u0435\u0439. <\/p>\n<p>  \u0412 <a href=\"https:\/\/astexplorer.net\/\" rel=\"nofollow\">astexplorer.net<\/a> \u043f\u0438\u0448\u0435\u043c Self-Invoking \u0444\u0443\u043d\u043a\u0446\u0438\u044e, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u043c\u0435\u0441\u0442\u0435 \u0438\u043c\u043f\u043e\u0440\u0442\u0430 \u0441\u0442\u0438\u043b\u044f:<\/p>\n<pre><code class=\"javascript\">(function(){   const styles = &quot;generated transpiledContent&quot; \/\/ &quot;.button {\/n display: flex; \/n}\/n&quot;    const fileName = &quot;generated_attributeValue&quot; \/\/Button_style   const element = document.querySelector(&quot;style[data-sass-component='fileName']&quot;)   if(!element){     const styleBlock = document.createElement(&quot;style&quot;)     styleBlock.innerHTML = styles     styleBlock.setAttribute(&quot;data-sass-component&quot;, fileName)     document.head.appendChild(styleBlock)   } })() <\/code><\/pre>\n<p>  \u0412 AST explorer \u0442\u044b\u043a\u0430\u0435\u043c \u0432 \u043b\u0435\u0432\u043e\u0439 \u0447\u0430\u0441\u0442\u0438 \u043d\u0430 \u0441\u0442\u0440\u043e\u043a\u0438, \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0438\u044f, \u043b\u0438\u0442\u0435\u0440\u0430\u043b\u044b, \u2014 \u0441\u043f\u0440\u0430\u0432\u0430 \u0432 \u0434\u0435\u0440\u0435\u0432\u0435 \u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0438\u0439, \u043f\u043e \u044d\u0442\u043e\u0439 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0435 \u043b\u0435\u0437\u0435\u043c \u0432 <a href=\"https:\/\/babeljs.io\/docs\/en\/babel-types#api\" rel=\"nofollow\">babeljs.io\/docs\/en\/babel-types#api<\/a>, \u043a\u0443\u0440\u0438\u043c \u0432\u0441\u0451 \u044d\u0442\u043e \u0438 \u043f\u0438\u0448\u0435\u043c \u0437\u0430\u043c\u0435\u043d\u0443.<\/p>\n<p>  A few moments later\u2026<\/p>\n<p>  \u0421\u043f\u0443\u0441\u0442\u044f 1-1,5 \u0447\u0430\u0441\u0430, \u0431\u0435\u0433\u0430\u044f \u043f\u043e \u0432\u043a\u043b\u0430\u0434\u043a\u0430\u043c \u0438\u0437 ast \u0432 babel-types api, \u0437\u0430\u0442\u0435\u043c \u0432 \u043a\u043e\u0434, \u044f \u043d\u0430\u043f\u0438\u0441\u0430\u043b \u0437\u0430\u043c\u0435\u043d\u0443 \u0438\u043c\u043f\u043e\u0440\u0442\u0430 scss\/sass. \u0420\u0430\u0437\u0431\u0438\u0440\u0430\u0442\u044c \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e \u0434\u0435\u0440\u0435\u0432\u043e ast \u0438 babel-types api \u044f \u043d\u0435 \u0431\u0443\u0434\u0443, \u0431\u0443\u0434\u0435\u0442 \u0435\u0449\u0451 \u0431\u043e\u043b\u044c\u0448\u0435 \u0431\u0443\u043a\u043e\u0432\u043e\u043a. \u041f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u044e \u0441\u0440\u0430\u0437\u0443 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442:<\/p>\n<pre><code class=\"javascript\">const { resolve, dirname, join } = require(&quot;path&quot;); const { renderSync } = require(&quot;node-sass&quot;);  const regexps = {   sassFile: \/([A-Za-z0-9]+).s[ac]ss\/g,   sassExt: \/\\.s[ac]ss$\/,   currentFile: \/([A-Za-z0-9]+).(t|j)s(x)\/g,   currentFileExt: \/.(t|j)s(x)\/g };  function transformScss(babel) {   const { types: t } = babel;   return {     name: &quot;babel-plugin-transform-scss&quot;,     visitor: {       ImportDeclaration(path, state) {         \/**          * \u041f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c, \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u043b\u0438 \u0442\u0435\u043a\u0443\u0449\u0438\u0439 \u0444\u0430\u0439\u043b scss\/sass \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u044f \u0432 \u0438\u043c\u043f\u043e\u0440\u0442\u0435          *\/         if (!regexps.sassExt.test(path.node.source.value)) return;         const sassFileNameMatch = path.node.source.value.match(           regexps.sassFile         );          \/**          * \u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0438\u043c\u044f \u0442\u0435\u043a\u0443\u0449\u0435\u0433\u043e scss\/sass \u0444\u0430\u0439\u043b\u0430 \u0438 \u0442\u0435\u043a\u0443\u0449\u0435\u0433\u043e js \u0444\u0430\u0439\u043b\u0430          *\/         const sassFileName = sassFileNameMatch[0].replace(regexps.sassExt, &quot;&quot;);         const file = this.filename.match(regexps.currentFile);         const filename = `${file[0].replace(           regexps.currentFileExt,           &quot;&quot;         )}_${sassFileName}`;          \/**          *          * \u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u043f\u043e\u043b\u043d\u044b\u0439 \u043f\u0443\u0442\u044c \u0434\u043e scss\/sass \u0444\u0430\u0439\u043b\u0430, \u0442\u0440\u0430\u043d\u0441\u043f\u0438\u043b\u0438\u043c \u0432 \u0441\u0442\u0440\u043e\u043a\u0443 css          *\/         const scssFileDirectory = resolve(dirname(state.file.opts.filename));         const fullScssFilePath = join(           scssFileDirectory,           path.node.source.value         );         const projectRoot = process.cwd();         const nodeModulesPath = join(projectRoot, &quot;node_modules&quot;);         const sassDefaults = {           file: fullScssFilePath,           sourceMap: false,           includePaths: [nodeModulesPath, scssFileDirectory, projectRoot]         };         const sassResult = renderSync({ ...sassDefaults, ...state.opts });         const transpiledContent = sassResult.css.toString() || &quot;&quot;;         \/**          * \u0418\u043c\u043f\u043b\u0435\u043c\u0435\u043d\u0442\u0438\u0440\u0443\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e, \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043d\u0443\u044e \u0432 AST Explorer \u0438 \u0437\u0430\u043c\u0435\u043d\u044f\u0435\u043c \u0438\u043c\u043f\u043e\u0440\u0442 \u043c\u0435\u0442\u043e\u0434\u043e\u043c           * replaceWith \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430 path.          *\/         path.replaceWith(           t.callExpression(             t.functionExpression(               t.identifier(&quot;&quot;),               [],               t.blockStatement(                 [                   t.variableDeclaration(&quot;const&quot;, [                     t.variableDeclarator(                       t.identifier(&quot;styles&quot;),                       t.stringLiteral(transpiledContent)                     )                   ]),                   t.variableDeclaration(&quot;const&quot;, [                     t.variableDeclarator(                       t.identifier(&quot;fileName&quot;),                       t.stringLiteral(filename)                     )                   ]),                   t.variableDeclaration(&quot;const&quot;, [                     t.variableDeclarator(                       t.identifier(&quot;element&quot;),                       t.callExpression(                         t.memberExpression(                           t.identifier(&quot;document&quot;),                           t.identifier(&quot;querySelector&quot;)                         ),                         [                           t.stringLiteral(                             `style[data-sass-component='${filename}']`                           )                         ]                       )                     )                   ]),                   t.ifStatement(                     t.unaryExpression(&quot;!&quot;, t.identifier(&quot;element&quot;), true),                     t.blockStatement(                       [                         t.variableDeclaration(&quot;const&quot;, [                           t.variableDeclarator(                             t.identifier(&quot;styleBlock&quot;),                             t.callExpression(                               t.memberExpression(                                 t.identifier(&quot;document&quot;),                                 t.identifier(&quot;createElement&quot;)                               ),                               [t.stringLiteral(&quot;style&quot;)]                             )                           )                         ]),                         t.expressionStatement(                           t.assignmentExpression(                             &quot;=&quot;,                             t.memberExpression(                               t.identifier(&quot;styleBlock&quot;),                               t.identifier(&quot;innerHTML&quot;)                             ),                             t.identifier(&quot;styles&quot;)                           )                         ),                         t.expressionStatement(                           t.callExpression(                             t.memberExpression(                               t.identifier(&quot;styleBlock&quot;),                               t.identifier(&quot;setAttribute&quot;)                             ),                             [                               t.stringLiteral(&quot;data-sass-component&quot;),                               t.identifier(&quot;fileName&quot;)                             ]                           )                         ),                         t.expressionStatement(                           t.callExpression(                             t.memberExpression(                               t.memberExpression(                                 t.identifier(&quot;document&quot;),                                 t.identifier(&quot;head&quot;),                                 false                               ),                               t.identifier(&quot;appendChild&quot;),                               false                             ),                             [t.identifier(&quot;styleBlock&quot;)]                           )                         )                       ],                       []                     ),                     null                   )                 ],                 []               ),               false,               false             ),             []           )         );         }     } } <\/code><\/pre>\n<p>  <\/p>\n<h3>\u0418\u0442\u043e\u0433\u043e\u0432\u044b\u0435 \u0440\u0430\u0434\u043e\u0441\u0442\u0438<\/h3>\n<p>  \u0423\u0440\u0430!!! \u0418\u043c\u043f\u043e\u0440\u0442 \u0437\u0430\u043c\u0435\u043d\u0438\u043b\u0441\u044f \u043d\u0430 \u0432\u044b\u0437\u043e\u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043d\u0430\u043f\u0438\u0445\u0430\u043b\u0430 \u0432 head \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430 \u0441\u0442\u0438\u043b\u044c \u0441 \u044d\u0442\u043e\u0439 \u043a\u043d\u043e\u043f\u043a\u043e\u0439. \u0418 \u0442\u0443\u0442 \u044f \u043f\u043e\u0434\u0443\u043c\u0430\u043b, \u0430 \u0447\u0442\u043e \u0435\u0441\u043b\u0438 \u044f \u0441\u0442\u0430\u0440\u0442\u0430\u043d\u0443 \u0432\u0441\u044e \u044d\u0442\u0443 \u0431\u0430\u0439\u0434\u0430\u0440\u043a\u0443 \u0447\u0435\u0440\u0435\u0437 \u0432\u0435\u0431\u043f\u0430\u043a, \u0432\u044b\u043a\u043e\u0441\u0438\u0432 sass-loader? \u0411\u0443\u0434\u0435\u0442 \u043b\u0438 \u043e\u043d\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c? \u041e\u043a\u0435\u0439, \u0432\u044b\u043a\u0430\u0448\u0438\u0432\u0430\u0435\u043c \u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c. \u0417\u0430\u043f\u0443\u0441\u043a\u0430\u044e \u0441\u0431\u043e\u0440\u043a\u0443 \u0432\u0435\u0431\u043f\u0430\u043a\u043e\u043c, \u0436\u0434\u0443 \u043e\u0448\u0438\u0431\u043a\u0443, \u0447\u0442\u043e \u044f \u0434\u043e\u043b\u0436\u0435\u043d \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c loader \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0442\u0438\u043f\u0430 \u0444\u0430\u0439\u043b\u0430\u2026 \u0410 \u043e\u0448\u0438\u0431\u043a\u0438-\u0442\u043e \u043d\u0435\u0442, \u0432\u0441\u0451 \u0441\u043e\u0431\u0440\u0430\u043b\u043e\u0441\u044c. \u041e\u0442\u043a\u0440\u044b\u0432\u0430\u044e \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0443, \u0441\u043c\u043e\u0442\u0440\u044e, \u0430 \u0441\u0442\u0438\u043b\u044c \u0432\u043e\u0442\u043a\u043d\u0443\u043b\u0441\u044f \u0432 head \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430. \u0418\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c, \u044f \u0435\u0449\u0451 \u0438\u0437\u0431\u0430\u0432\u0438\u043b\u0441\u044f \u043e\u0442 3 \u043b\u043e\u0430\u0434\u0435\u0440\u043e\u0432 \u0434\u043b\u044f \u0441\u0442\u0438\u043b\u0435\u0439(\u043e\u0447\u0435\u043d\u044c \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u0430\u044f \u0443\u043b\u044b\u0431\u043a\u0430).<\/p>\n<p>  \u0415\u0441\u043b\u0438 \u0432\u0430\u043c \u0431\u044b\u043b\u0430 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u0430 \u0441\u0442\u0430\u0442\u044c\u044f \u2014 <b><a href=\"https:\/\/github.com\/altgifted\/babel-plugin-transform-scss\" rel=\"nofollow\">\u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0442\u0435 \u0437\u0432\u0435\u0437\u0434\u043e\u0447\u043a\u043e\u0439 \u043d\u0430 github<\/a><\/b>.<\/p>\n<p>  \u0422\u0430\u043a \u0436\u0435 \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 npm \u043f\u0430\u043a\u0435\u0442: <a href=\"https:\/\/www.npmjs.com\/package\/babel-plugin-transform-scss\" rel=\"nofollow\">www.npmjs.com\/package\/babel-plugin-transform-scss<\/a><\/p>\n<p>  \u041f\u0440\u0438\u043c\u0435\u0447\u0430\u043d\u0438\u0435: \u0412\u043d\u0435 \u0441\u0442\u0430\u0442\u044c\u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0430 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u043d\u0430 \u0438\u043c\u043f\u043e\u0440\u0442 \u0441\u0442\u0438\u043b\u044f \u043f\u043e \u0442\u0438\u043f\u0443 <i>import styles from &#8216;.\/styles.scss&#8217;<\/i><\/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\/513564\/\"> https:\/\/habr.com\/ru\/post\/513564\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/post\/513564\/\">\n<h3>\u041f\u0440\u0435\u0434\u044b\u0441\u0442\u043e\u0440\u0438\u044f<\/h3>\n<p>  \u041a\u0430\u043a-\u0442\u043e \u0441\u0443\u0431\u0431\u043e\u0442\u043d\u0438\u043c \u0432\u0435\u0447\u0435\u0440\u043e\u043c \u044f \u0441\u0438\u0434\u0435\u043b \u0438 \u0438\u0441\u043a\u0430\u043b \u0441\u043f\u043e\u0441\u043e\u0431\u044b \u0441\u0431\u043e\u0440\u043a\u0438 UI-Kit \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e webpack. \u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0434\u0435\u043c\u043e UI-kit \u044f \u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0441\u044c styleguidst. \u041a\u043e\u043d\u0435\u0447\u043d\u043e \u0436\u0435, webpack \u0443\u043c\u043d\u044b\u0439 \u0438 \u0432\u0441\u0435 \u0444\u0430\u0439\u043b\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0435\u0441\u0442\u044c \u0432 \u0440\u0430\u0431\u043e\u0447\u0435\u043c \u043a\u0430\u0442\u0430\u043b\u043e\u0433\u0435 \u043e\u043d \u0437\u0430\u043f\u0438\u0445\u0438\u0432\u0430\u0435\u0442 \u0432 \u043e\u0434\u0438\u043d \u0431\u0430\u043d\u0434\u043b \u0438 \u043e\u0442\u0442\u0443\u0434\u0430 \u0432\u0441\u0451 \u043a\u0440\u0443\u0442\u0438\u0442\u0441\u044f \u0438 \u0432\u0435\u0440\u0442\u0438\u0442\u0441\u044f.<\/p>\n<p>  \u042f \u0441\u043e\u0437\u0434\u0430\u043b \u0444\u0430\u0439\u043b entry.js, \u0438\u043c\u043f\u043e\u0440\u0442\u043d\u0443\u043b \u0442\u0443\u0434\u0430 \u0432\u0441\u0435 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b, \u0437\u0430\u0442\u0435\u043c \u043e\u0442\u0442\u0443\u0434\u0430 \u0436\u0435 \u044d\u043a\u0441\u043f\u043e\u0440\u0442\u043d\u0443\u043b. \u0412\u0440\u043e\u0434\u0435 \u0432\u0441\u0451 \u043e\u043a.<\/p>\n<pre><code class=\"javascript\">import Button from 'components\/Button' import Dropdown from 'components\/Dropdown '  export {   Button,   Dropdown  } <\/code><\/pre>\n<p>  \u0418 \u043f\u043e\u0441\u043b\u0435 \u0441\u0431\u043e\u0440\u043a\u0438 \u0432\u0441\u0435\u0433\u043e \u044d\u0442\u043e\u0433\u043e, \u044f \u043f\u043e\u043b\u0443\u0447\u0438\u043b \u043d\u0430 \u0432\u044b\u0445\u043e\u0434\u0435 output.js, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043a\u0430\u043a \u0438 \u043e\u0436\u0438\u0434\u0430\u043b\u043e\u0441\u044c \u0431\u044b\u043b\u043e \u0432\u0441\u0451 \u2014 \u0432\u0441\u0435 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b \u0432 \u043a\u0443\u0447\u0435 \u0432 \u043e\u0434\u043d\u043e\u043c \u0444\u0430\u0439\u043b\u0435. \u0422\u0443\u0442 \u0432\u043e\u0437\u043d\u0438\u043a \u0432\u043e\u043f\u0440\u043e\u0441:  <\/p>\n<blockquote><p>\u0410 \u043a\u0430\u043a \u043c\u043d\u0435 \u0441\u043e\u0431\u0440\u0430\u0442\u044c \u0432\u0441\u0435 \u043a\u043d\u043e\u043f\u043e\u0447\u043a\u0438, \u0434\u0440\u043e\u043f\u0434\u0430\u0443\u043d\u044b \u0438 \u043f\u0440\u043e\u0447\u0435\u0435 \u043f\u043e \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438, \u0447\u0442\u043e \u0431\u044b \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432 \u0434\u0440\u0443\u0433\u0438\u0445 \u043f\u0440\u043e\u0435\u043a\u0442\u0430\u0445?   <\/p><\/blockquote>\n<p>\u0410 \u044f \u0432\u0435\u0434\u044c \u0445\u043e\u0447\u0443 \u044d\u0442\u043e \u0435\u0449\u0451 \u0438 \u0432 npm \u0437\u0430\u043b\u0438\u0442\u044c \u043a\u0430\u043a \u043f\u0430\u043a\u0435\u0442.<\/p>\n<p>  \u0425\u043c\u2026 \u041f\u043e\u0435\u0445\u0430\u043b\u0438 \u043f\u043e \u043f\u043e\u0440\u044f\u0434\u043a\u0443.  <\/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-307920","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/307920","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=307920"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/307920\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=307920"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=307920"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=307920"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}