<h1 dir="auto">Bug report</h1>




<p dir="auto"><strong>What is the current behavior?</strong></p>
<p dir="auto">I have a .js file which uses AMD using the <code class="notranslate">define()</code> method. <strong>IF</strong> the file contains a particular JS warning (i.e. "no-dupe-keys" == an object with duplicate keys such as <code class="notranslate">{ a: 6, a: 6 }</code>) <strong>THEN</strong> the <code class="notranslate">define()</code> is not currently processed, and it is outputted in the transpiled content (leading to an JS runtime error such as "define is not defined").</p>
<p dir="auto"><strong>NOTE:</strong> the above happens ONLY for a production build. Development build works OK.</p>
<p dir="auto"><strong>If the current behavior is a bug, please provide the steps to reproduce.</strong></p>
<p dir="auto">This <a href="https://stackoverflow.com/questions/71623355/amd-w-define-doesnt-work-in-a-particular-case-create-react-app-based-app-w" rel="nofollow">stack overflow post</a> I described the situation more in detail; I'm copying here a TLDR;</p>
<p dir="auto">I have a <code class="notranslate">create-react-app</code> based project. In it, I have a legacy JS file, e.g.:</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="define([&quot;jquery&quot;, &quot;backbone&quot;],
         function($, Backbone) {
    
    var AppInit = function() {
//      this.initialize.apply(this, arguments);
    };
    
    _.extend(AppInit.prototype, {
        
        initApp: function() {
            var originalBackboneSync = Backbone.sync;
            
            if (window.isWindowsApp) {
                var path = decodeURI(window.location.pathname);
                window.operationDomain = new NodeDomain(&quot;operation&quot;, path.substr(1, path.lastIndexOf(&quot;/&quot;)) + &quot;lib/modules/node/OperationDomain&quot;);"><pre class="notranslate"><span class="pl-s1">define</span><span class="pl-kos">(</span><span class="pl-kos">[</span><span class="pl-s">"jquery"</span><span class="pl-kos">,</span> <span class="pl-s">"backbone"</span><span class="pl-kos">]</span><span class="pl-kos">,</span>
         <span class="pl-k">function</span><span class="pl-kos">(</span><span class="pl-s1">$</span><span class="pl-kos">,</span> <span class="pl-v">Backbone</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
    
    <span class="pl-k">var</span> <span class="pl-v">AppInit</span> <span class="pl-c1">=</span> <span class="pl-k">function</span><span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
<span class="pl-c">//      this.initialize.apply(this, arguments);</span>
    <span class="pl-kos">}</span><span class="pl-kos">;</span>
    
    <span class="pl-s1">_</span><span class="pl-kos">.</span><span class="pl-c1">extend</span><span class="pl-kos">(</span><span class="pl-v">AppInit</span><span class="pl-kos">.</span><span class="pl-c1">prototype</span><span class="pl-kos">,</span> <span class="pl-kos">{</span>
        
        <span class="pl-c1">initApp</span>: <span class="pl-k">function</span><span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
            <span class="pl-k">var</span> <span class="pl-s1">originalBackboneSync</span> <span class="pl-c1">=</span> <span class="pl-v">Backbone</span><span class="pl-kos">.</span><span class="pl-c1">sync</span><span class="pl-kos">;</span>
            
            <span class="pl-k">if</span> <span class="pl-kos">(</span><span class="pl-smi">window</span><span class="pl-kos">.</span><span class="pl-c1">isWindowsApp</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
                <span class="pl-k">var</span> <span class="pl-s1">path</span> <span class="pl-c1">=</span> <span class="pl-en">decodeURI</span><span class="pl-kos">(</span><span class="pl-smi">window</span><span class="pl-kos">.</span><span class="pl-c1">location</span><span class="pl-kos">.</span><span class="pl-c1">pathname</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
                <span class="pl-smi">window</span><span class="pl-kos">.</span><span class="pl-c1">operationDomain</span> <span class="pl-c1">=</span> <span class="pl-k">new</span> <span class="pl-v">NodeDomain</span><span class="pl-kos">(</span><span class="pl-s">"operation"</span><span class="pl-kos">,</span> <span class="pl-s1">path</span><span class="pl-kos">.</span><span class="pl-en">substr</span><span class="pl-kos">(</span><span class="pl-c1">1</span><span class="pl-kos">,</span> <span class="pl-s1">path</span><span class="pl-kos">.</span><span class="pl-en">lastIndexOf</span><span class="pl-kos">(</span><span class="pl-s">"/"</span><span class="pl-kos">)</span><span class="pl-kos">)</span> <span class="pl-c1">+</span> <span class="pl-s">"lib/modules/node/OperationDomain"</span><span class="pl-kos">)</span><span class="pl-kos">;</span></pre></div>
<p dir="auto">This file contains such a construct (observe the <code class="notranslate">data</code> key twice), that gives a linter warning: "no-dupe-keys" = there are duplicate keys:</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="				var requestResponse = {
					    url: ajaxOptions.url,
					    method: ajaxOptions.type,
					    data: ajaxOptions.data,
					    httpStatus: jqXHR.status,
					    error: data || jqXHR.statusText,
					    data: ajaxOptions.data
					  };"><pre class="notranslate">				<span class="pl-k">var</span> <span class="pl-s1">requestResponse</span> <span class="pl-c1">=</span> <span class="pl-kos">{</span>
					    <span class="pl-c1">url</span>: <span class="pl-s1">ajaxOptions</span><span class="pl-kos">.</span><span class="pl-c1">url</span><span class="pl-kos">,</span>
					    <span class="pl-c1">method</span>: <span class="pl-s1">ajaxOptions</span><span class="pl-kos">.</span><span class="pl-c1">type</span><span class="pl-kos">,</span>
					    <span class="pl-c1">data</span>: <span class="pl-s1">ajaxOptions</span><span class="pl-kos">.</span><span class="pl-c1">data</span><span class="pl-kos">,</span>
					    <span class="pl-c1">httpStatus</span>: <span class="pl-s1">jqXHR</span><span class="pl-kos">.</span><span class="pl-c1">status</span><span class="pl-kos">,</span>
					    <span class="pl-c1">error</span>: <span class="pl-s1">data</span> <span class="pl-c1">||</span> <span class="pl-s1">jqXHR</span><span class="pl-kos">.</span><span class="pl-c1">statusText</span><span class="pl-kos">,</span>
					    <span class="pl-c1">data</span>: <span class="pl-s1">ajaxOptions</span><span class="pl-kos">.</span><span class="pl-c1">data</span>
					  <span class="pl-kos">}</span><span class="pl-kos">;</span></pre></div>






<p dir="auto"><strong>What is the expected behavior?</strong></p>


<p dir="auto">For a "development" build, the output for this file is correct and looks like this:</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="/***/ &quot;./src/old-app/AppInit.js&quot;:
/*!**************************************************!*\
  !*** ./src/old-app/AppInit.js ***!
  \**************************************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {

    var __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;!(__WEBPACK_AMD_DEFINE_ARRAY__ = [__webpack_require__(/*! jquery */ &quot;./node_modules/jquery/dist/jquery.js&quot;), __webpack_require__(/*! backbone */ &quot;./node_modules/backbone/backbone.js&quot;)], __WEBPACK_AMD_DEFINE_RESULT__ = (function ($, Backbone) {
        var AppInit = function () {//       this.initialize.apply(this, arguments);
        };
      
        _.extend(AppInit.prototype, {
          initApp: function () {
            var originalBackboneSync = Backbone.sync;
      
            if (window.isWindowsApp) {
              var path = decodeURI(window.location.pathname);
              window.operationDomain = new NodeDomain(&quot;operation&quot;, path.substr(1, path.lastIndexOf(&quot;/&quot;)) + &quot;lib/modules/node/OperationDomain&quot;);"><pre class="notranslate"><span class="pl-c">/***/</span> <span class="pl-s">"./src/old-app/AppInit.js"</span>:
<span class="pl-c">/*!**************************************************!*\</span>
<span class="pl-c">  !*** ./src/old-app/AppInit.js ***!</span>
<span class="pl-c">  \**************************************************/</span>
<span class="pl-c">/*! no static exports found */</span>
<span class="pl-c">/***/</span> <span class="pl-kos">(</span><span class="pl-k">function</span><span class="pl-kos">(</span><span class="pl-s1">module</span><span class="pl-kos">,</span> <span class="pl-s1">exports</span><span class="pl-kos">,</span> <span class="pl-s1">__webpack_require__</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>

    <span class="pl-k">var</span> <span class="pl-c1">__WEBPACK_AMD_DEFINE_ARRAY__</span><span class="pl-kos">,</span> <span class="pl-c1">__WEBPACK_AMD_DEFINE_RESULT__</span><span class="pl-kos">;</span><span class="pl-c1">!</span><span class="pl-kos">(</span><span class="pl-c1">__WEBPACK_AMD_DEFINE_ARRAY__</span> <span class="pl-c1">=</span> <span class="pl-kos">[</span><span class="pl-s1">__webpack_require__</span><span class="pl-kos">(</span><span class="pl-c">/*! jquery */</span> <span class="pl-s">"./node_modules/jquery/dist/jquery.js"</span><span class="pl-kos">)</span><span class="pl-kos">,</span> <span class="pl-s1">__webpack_require__</span><span class="pl-kos">(</span><span class="pl-c">/*! backbone */</span> <span class="pl-s">"./node_modules/backbone/backbone.js"</span><span class="pl-kos">)</span><span class="pl-kos">]</span><span class="pl-kos">,</span> <span class="pl-c1">__WEBPACK_AMD_DEFINE_RESULT__</span> <span class="pl-c1">=</span> <span class="pl-kos">(</span><span class="pl-k">function</span> <span class="pl-kos">(</span><span class="pl-s1">$</span><span class="pl-kos">,</span> <span class="pl-v">Backbone</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
        <span class="pl-k">var</span> <span class="pl-v">AppInit</span> <span class="pl-c1">=</span> <span class="pl-k">function</span> <span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-kos">{</span><span class="pl-c">//       this.initialize.apply(this, arguments);</span>
        <span class="pl-kos">}</span><span class="pl-kos">;</span>
      
        <span class="pl-s1">_</span><span class="pl-kos">.</span><span class="pl-c1">extend</span><span class="pl-kos">(</span><span class="pl-v">AppInit</span><span class="pl-kos">.</span><span class="pl-c1">prototype</span><span class="pl-kos">,</span> <span class="pl-kos">{</span>
          <span class="pl-c1">initApp</span>: <span class="pl-k">function</span> <span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
            <span class="pl-k">var</span> <span class="pl-s1">originalBackboneSync</span> <span class="pl-c1">=</span> <span class="pl-v">Backbone</span><span class="pl-kos">.</span><span class="pl-c1">sync</span><span class="pl-kos">;</span>
      
            <span class="pl-k">if</span> <span class="pl-kos">(</span><span class="pl-smi">window</span><span class="pl-kos">.</span><span class="pl-c1">isWindowsApp</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
              <span class="pl-k">var</span> <span class="pl-s1">path</span> <span class="pl-c1">=</span> <span class="pl-en">decodeURI</span><span class="pl-kos">(</span><span class="pl-smi">window</span><span class="pl-kos">.</span><span class="pl-c1">location</span><span class="pl-kos">.</span><span class="pl-c1">pathname</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
              <span class="pl-smi">window</span><span class="pl-kos">.</span><span class="pl-c1">operationDomain</span> <span class="pl-c1">=</span> <span class="pl-k">new</span> <span class="pl-v">NodeDomain</span><span class="pl-kos">(</span><span class="pl-s">"operation"</span><span class="pl-kos">,</span> <span class="pl-s1">path</span><span class="pl-kos">.</span><span class="pl-en">substr</span><span class="pl-kos">(</span><span class="pl-c1">1</span><span class="pl-kos">,</span> <span class="pl-s1">path</span><span class="pl-kos">.</span><span class="pl-en">lastIndexOf</span><span class="pl-kos">(</span><span class="pl-s">"/"</span><span class="pl-kos">)</span><span class="pl-kos">)</span> <span class="pl-c1">+</span> <span class="pl-s">"lib/modules/node/OperationDomain"</span><span class="pl-kos">)</span><span class="pl-kos">;</span></pre></div>
<p dir="auto">But for a "production" build, the output looks cf. below. Observe the presence of "define()" in the code, which is not correct.</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="/***/ &quot;./src/old-app/AppInit.js&quot;:
/***/ (function(module, __webpack_exports__, __webpack_require__) {

&quot;use strict&quot;;
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _home_poweruser_git2_xops_xops6_xops6_react_node_modules_babel_preset_react_app_node_modules_babel_runtime_helpers_esm_defineProperty__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(&quot;./node_modules/babel-preset-react-app/node_modules/@babel/runtime/helpers/esm/defineProperty.js&quot;);

define([&quot;jquery&quot;, &quot;backbone&quot;], function ($, Backbone) {
  var AppInit = function AppInit() {//      this.initialize.apply(this, arguments);
  };

  _.extend(AppInit.prototype, {
    initApp: function initApp() {
      var originalBackboneSync = Backbone.sync;

      if (window.isWindowsApp) {
        var path = decodeURI(window.location.pathname);
        window.operationDomain = new NodeDomain(&quot;operation&quot;, path.substr(1, path.lastIndexOf(&quot;/&quot;)) + &quot;lib/modules/node/OperationDomain&quot;);"><pre class="notranslate"><span class="pl-c">/***/</span> <span class="pl-s">"./src/old-app/AppInit.js"</span>:
<span class="pl-c">/***/</span> <span class="pl-kos">(</span><span class="pl-k">function</span><span class="pl-kos">(</span><span class="pl-s1">module</span><span class="pl-kos">,</span> <span class="pl-s1">__webpack_exports__</span><span class="pl-kos">,</span> <span class="pl-s1">__webpack_require__</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>

<span class="pl-s">"use strict"</span><span class="pl-kos">;</span>
<span class="pl-s1">__webpack_require__</span><span class="pl-kos">.</span><span class="pl-en">r</span><span class="pl-kos">(</span><span class="pl-s1">__webpack_exports__</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-c">/* harmony import */</span> <span class="pl-k">var</span> <span class="pl-s1">_home_poweruser_git2_xops_xops6_xops6_react_node_modules_babel_preset_react_app_node_modules_babel_runtime_helpers_esm_defineProperty__WEBPACK_IMPORTED_MODULE_0__</span> <span class="pl-c1">=</span> <span class="pl-s1">__webpack_require__</span><span class="pl-kos">(</span><span class="pl-s">"./node_modules/babel-preset-react-app/node_modules/@babel/runtime/helpers/esm/defineProperty.js"</span><span class="pl-kos">)</span><span class="pl-kos">;</span>

<span class="pl-s1">define</span><span class="pl-kos">(</span><span class="pl-kos">[</span><span class="pl-s">"jquery"</span><span class="pl-kos">,</span> <span class="pl-s">"backbone"</span><span class="pl-kos">]</span><span class="pl-kos">,</span> <span class="pl-k">function</span> <span class="pl-kos">(</span><span class="pl-s1">$</span><span class="pl-kos">,</span> <span class="pl-v">Backbone</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
  <span class="pl-k">var</span> <span class="pl-v">AppInit</span> <span class="pl-c1">=</span> <span class="pl-k">function</span> <span class="pl-v">AppInit</span><span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-kos">{</span><span class="pl-c">//      this.initialize.apply(this, arguments);</span>
  <span class="pl-kos">}</span><span class="pl-kos">;</span>

  <span class="pl-s1">_</span><span class="pl-kos">.</span><span class="pl-c1">extend</span><span class="pl-kos">(</span><span class="pl-v">AppInit</span><span class="pl-kos">.</span><span class="pl-c1">prototype</span><span class="pl-kos">,</span> <span class="pl-kos">{</span>
    <span class="pl-c1">initApp</span>: <span class="pl-k">function</span> <span class="pl-s1">initApp</span><span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
      <span class="pl-k">var</span> <span class="pl-s1">originalBackboneSync</span> <span class="pl-c1">=</span> <span class="pl-v">Backbone</span><span class="pl-kos">.</span><span class="pl-c1">sync</span><span class="pl-kos">;</span>

      <span class="pl-k">if</span> <span class="pl-kos">(</span><span class="pl-smi">window</span><span class="pl-kos">.</span><span class="pl-c1">isWindowsApp</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
        <span class="pl-k">var</span> <span class="pl-s1">path</span> <span class="pl-c1">=</span> <span class="pl-en">decodeURI</span><span class="pl-kos">(</span><span class="pl-smi">window</span><span class="pl-kos">.</span><span class="pl-c1">location</span><span class="pl-kos">.</span><span class="pl-c1">pathname</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
        <span class="pl-smi">window</span><span class="pl-kos">.</span><span class="pl-c1">operationDomain</span> <span class="pl-c1">=</span> <span class="pl-k">new</span> <span class="pl-v">NodeDomain</span><span class="pl-kos">(</span><span class="pl-s">"operation"</span><span class="pl-kos">,</span> <span class="pl-s1">path</span><span class="pl-kos">.</span><span class="pl-en">substr</span><span class="pl-kos">(</span><span class="pl-c1">1</span><span class="pl-kos">,</span> <span class="pl-s1">path</span><span class="pl-kos">.</span><span class="pl-en">lastIndexOf</span><span class="pl-kos">(</span><span class="pl-s">"/"</span><span class="pl-kos">)</span><span class="pl-kos">)</span> <span class="pl-c1">+</span> <span class="pl-s">"lib/modules/node/OperationDomain"</span><span class="pl-kos">)</span><span class="pl-kos">;</span></pre></div>
<p dir="auto"><strong>Other relevant information:</strong><br>
webpack version:  4.42.0<br>
Node.js version: 14.17.0<br>
Operating System: Linux Ubuntu 20.04 (within WSL)<br>
Additional tools: create-react-app</p>
<p dir="auto">We have a problem with performance when enabling source-maps (cheap-module-eval-source-map) in our project. After some investigation I found an issue with <code class="notranslate">replace</code> function inside <code class="notranslate">FunctionModuleTemplatePlugin</code>. <code class="notranslate">replace</code> took too much time even when the string (req) is small.</p>
<div class="highlight highlight-source-shell notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="webpack@3.12.0
webpack-dev-server@2.11.3
node@v10.15.0
npm@6.4.1
darwin 18.2.0 MacOs Mojave (10.14.3) 2.3GHz i5/ 8GB"><pre class="notranslate">webpack@3.12.0
webpack-dev-server@2.11.3
node@v10.15.0
npm@6.4.1
darwin 18.2.0 MacOs Mojave (10.14.3) 2.3GHz i5/ 8GB</pre></div>
<p dir="auto"><a href="https://github.com/webpack/webpack/blob/master/lib/FunctionModuleTemplatePlugin.js#L44-L46">https://github.com/webpack/webpack/blob/master/lib/FunctionModuleTemplatePlugin.js#L44-L46</a></p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="	source.add(&quot;/*!****&quot; + req.replace(/./g, &quot;*&quot;) + &quot;****!*\\\n&quot;);
	source.add(&quot;  !*** &quot; + req.replace(/\*\//g, &quot;*_/&quot;) + &quot; ***!\n&quot;);
	source.add(&quot;  \\****&quot; + req.replace(/./g, &quot;*&quot;) + &quot;****/\n&quot;);"><pre class="notranslate">	<span class="pl-s1">source</span><span class="pl-kos">.</span><span class="pl-en">add</span><span class="pl-kos">(</span><span class="pl-s">"/*!****"</span> <span class="pl-c1">+</span> <span class="pl-s1">req</span><span class="pl-kos">.</span><span class="pl-en">replace</span><span class="pl-kos">(</span><span class="pl-pds"><span class="pl-c1">/</span>.<span class="pl-c1">/</span>g</span><span class="pl-kos">,</span> <span class="pl-s">"*"</span><span class="pl-kos">)</span> <span class="pl-c1">+</span> <span class="pl-s">"****!*\\\n"</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
	<span class="pl-s1">source</span><span class="pl-kos">.</span><span class="pl-en">add</span><span class="pl-kos">(</span><span class="pl-s">"  !*** "</span> <span class="pl-c1">+</span> <span class="pl-s1">req</span><span class="pl-kos">.</span><span class="pl-en">replace</span><span class="pl-kos">(</span><span class="pl-pds"><span class="pl-c1">/</span><span class="pl-cce">\*</span><span class="pl-cce">\/</span><span class="pl-c1">/</span>g</span><span class="pl-kos">,</span> <span class="pl-s">"*_/"</span><span class="pl-kos">)</span> <span class="pl-c1">+</span> <span class="pl-s">" ***!\n"</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
	<span class="pl-s1">source</span><span class="pl-kos">.</span><span class="pl-en">add</span><span class="pl-kos">(</span><span class="pl-s">"  \\****"</span> <span class="pl-c1">+</span> <span class="pl-s1">req</span><span class="pl-kos">.</span><span class="pl-en">replace</span><span class="pl-kos">(</span><span class="pl-pds"><span class="pl-c1">/</span>.<span class="pl-c1">/</span>g</span><span class="pl-kos">,</span> <span class="pl-s">"*"</span><span class="pl-kos">)</span> <span class="pl-c1">+</span> <span class="pl-s">"****/\n"</span><span class="pl-kos">)</span><span class="pl-kos">;</span></pre></div>
<p dir="auto">First simple solution just remove duplications <code class="notranslate">req.replace(/./g, "*")</code>.<br>
Second I replaced <code class="notranslate">replace</code> with Array</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="        const x = Array(req.length).fill(&quot;*&quot;).join('');
        const y = Array(req.length).fill(null).map((_, i) =&gt; (i &gt; 0 &amp;&amp; req[i - 1] === '*' &amp;&amp; req[i] === '/') ? '_/' : req[i]).join('');
        source.add(&quot;/*!****&quot; + x + &quot;****!*\\\n&quot;);
        source.add(&quot;  !*** &quot; + y + &quot; ***!\n&quot;);
        source.add(&quot;  \\****&quot; + x + &quot;****/\n&quot;);
"><pre class="notranslate">        <span class="pl-k">const</span> <span class="pl-s1">x</span> <span class="pl-c1">=</span> <span class="pl-v">Array</span><span class="pl-kos">(</span><span class="pl-s1">req</span><span class="pl-kos">.</span><span class="pl-c1">length</span><span class="pl-kos">)</span><span class="pl-kos">.</span><span class="pl-en">fill</span><span class="pl-kos">(</span><span class="pl-s">"*"</span><span class="pl-kos">)</span><span class="pl-kos">.</span><span class="pl-en">join</span><span class="pl-kos">(</span><span class="pl-s">''</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
        <span class="pl-k">const</span> <span class="pl-s1">y</span> <span class="pl-c1">=</span> <span class="pl-v">Array</span><span class="pl-kos">(</span><span class="pl-s1">req</span><span class="pl-kos">.</span><span class="pl-c1">length</span><span class="pl-kos">)</span><span class="pl-kos">.</span><span class="pl-en">fill</span><span class="pl-kos">(</span><span class="pl-c1">null</span><span class="pl-kos">)</span><span class="pl-kos">.</span><span class="pl-en">map</span><span class="pl-kos">(</span><span class="pl-kos">(</span><span class="pl-s1">_</span><span class="pl-kos">,</span> <span class="pl-s1">i</span><span class="pl-kos">)</span> <span class="pl-c1">=&gt;</span> <span class="pl-kos">(</span><span class="pl-s1">i</span> <span class="pl-c1">&gt;</span> <span class="pl-c1">0</span> <span class="pl-c1">&amp;&amp;</span> <span class="pl-s1">req</span><span class="pl-kos">[</span><span class="pl-s1">i</span> <span class="pl-c1">-</span> <span class="pl-c1">1</span><span class="pl-kos">]</span> <span class="pl-c1">===</span> <span class="pl-s">'*'</span> <span class="pl-c1">&amp;&amp;</span> <span class="pl-s1">req</span><span class="pl-kos">[</span><span class="pl-s1">i</span><span class="pl-kos">]</span> <span class="pl-c1">===</span> <span class="pl-s">'/'</span><span class="pl-kos">)</span> ? <span class="pl-s">'_/'</span> : <span class="pl-s1">req</span><span class="pl-kos">[</span><span class="pl-s1">i</span><span class="pl-kos">]</span><span class="pl-kos">)</span><span class="pl-kos">.</span><span class="pl-en">join</span><span class="pl-kos">(</span><span class="pl-s">''</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
        <span class="pl-s1">source</span><span class="pl-kos">.</span><span class="pl-en">add</span><span class="pl-kos">(</span><span class="pl-s">"/*!****"</span> <span class="pl-c1">+</span> <span class="pl-s1">x</span> <span class="pl-c1">+</span> <span class="pl-s">"****!*\\\n"</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
        <span class="pl-s1">source</span><span class="pl-kos">.</span><span class="pl-en">add</span><span class="pl-kos">(</span><span class="pl-s">"  !*** "</span> <span class="pl-c1">+</span> <span class="pl-s1">y</span> <span class="pl-c1">+</span> <span class="pl-s">" ***!\n"</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
        <span class="pl-s1">source</span><span class="pl-kos">.</span><span class="pl-en">add</span><span class="pl-kos">(</span><span class="pl-s">"  \\****"</span> <span class="pl-c1">+</span> <span class="pl-s1">x</span> <span class="pl-c1">+</span> <span class="pl-s">"****/\n"</span><span class="pl-kos">)</span><span class="pl-kos">;</span></pre></div>
<p dir="auto">After this fixes rebuild time decreased <code class="notranslate">3-4</code> times.<br>
Performance of <code class="notranslate">FunctionModuleTemplatePlugin</code> increased in ~15 times (by profile)</p>
<p dir="auto">I have created a small test file which reproduces this problem<br>
<a href="https://gist.github.com/maksimr/cff8cb1ebda05d530071c9c78cd0d82e">https://gist.github.com/maksimr/cff8cb1ebda05d530071c9c78cd0d82e</a></p>
<p dir="auto"><a target="_blank" rel="noopener noreferrer nofollow" href="https://user-images.githubusercontent.com/616193/54871116-82800b80-4dc0-11e9-8714-e1ce09df60c6.png"><img src="https://user-images.githubusercontent.com/616193/54871116-82800b80-4dc0-11e9-8714-e1ce09df60c6.png" alt="image1553370705714" style="max-width: 100%;"></a><br>
<a target="_blank" rel="noopener noreferrer nofollow" href="https://user-images.githubusercontent.com/616193/54871125-ad6a5f80-4dc0-11e9-851c-044706d05dd7.png"><img src="https://user-images.githubusercontent.com/616193/54871125-ad6a5f80-4dc0-11e9-851c-044706d05dd7.png" alt="image1553370308610 (1)" style="max-width: 100%;"></a></p>
<p dir="auto"><a href="https://gist.githubusercontent.com/maksimr/cff8cb1ebda05d530071c9c78cd0d82e/raw/c38c39206655d61716181d72df8c5777b7dec729/CPU-20190323T223837.cpuprofile" rel="nofollow">CPU profile for replace</a></p>
<p dir="auto"><a href="https://gist.githubusercontent.com/maksimr/cff8cb1ebda05d530071c9c78cd0d82e/raw/c38c39206655d61716181d72df8c5777b7dec729/CPU-patched.cpuprofile" rel="nofollow">CPU profile for Array</a></p>
<p dir="auto">All CPU profiles I have added to gist<br>
<a href="https://gist.github.com/maksimr/cff8cb1ebda05d530071c9c78cd0d82e">https://gist.github.com/maksimr/cff8cb1ebda05d530071c9c78cd0d82e</a></p>
<p dir="auto">Thanks</p>