Ver código fonte

[refactor] extract first file in getChunkFiles

mightyplow 6 anos atrás
pai
commit
2198ea5727
2 arquivos alterados com 6 adições e 6 exclusões
  1. 2 2
      lib/getChunkFiles.js
  2. 4 4
      lib/replaceAssets.js

+ 2 - 2
lib/getChunkFiles.js

@@ -2,7 +2,7 @@ const isRequired = require('./isRequired.js');
 
 /**
  * Finds all chunks of a webpack compilation object and maps the chunk name
- * to the containing files.
+ * to the first containing file.
  *
  * @param {Object} compilation - a webpack compilation object
  * @param {Object[]} compilation.chunks - an array of webpack chunks
@@ -10,7 +10,7 @@ const isRequired = require('./isRequired.js');
  */
 function getChunkFiles (compilation = isRequired('compilation')) {
     return compilation.chunks.reduce(function mapChunksToFiles(files, chunk) {
-        files[chunk.name] = chunk.files;
+        files[chunk.name] = chunk.files[0];
         return files;
     }, {});
 }

+ 4 - 4
lib/replaceAssets.js

@@ -9,17 +9,17 @@ const defaultAssetRegex = /[{]{2}([^}]+)[}]{2}/g;
  * Replaces asset names with the first of the asset files from a webpack compilation.
  *
  * @param {string} targetSource - a string in which to replace the assets
- * @param {Object} assetFiles - a map of available asset names and their containing files
+ * @param {Object} assetFileNames - a map of available asset names and their containing files
  * @return {string}
  */
-function replaceAssets (targetSource, assetFiles) {
+function replaceAssets (targetSource, assetFileNames) {
     return targetSource.replace(defaultAssetRegex, function replaceAsset (match, assetName) {
-        if (!(assetFiles[assetName] && assetFiles[assetName].length)) {
+        if (!(assetFileNames[assetName] && assetFileNames[assetName].length)) {
             console.warn(`no asset for '${assetName}' was found`);
             return match;
         }
 
-        return assetFiles[assetName][0];
+        return assetFileNames[assetName];
     });
 }