/** * @typedef {Object} WebpackAsset * @param {Function} size * @param {Function} source */ /** * Creates a webpack asset object from a string. If the asset is falsy, the function returns * undefined. * * @param {string} assetContent - the content for the webpack asset * @param {string} [target] - a target name to be included in an eventual warning * @return {WebpackAsset|undefined} */ function createAsset (assetContent, target) { if (!assetContent) { const message = [ 'the asset content for the target', `'${target}'`, 'is empty' ] .filter((part) => !!part) .join(' '); console.warn(message); return; } return { size () { return assetContent.length; }, source () { return assetContent; } }; } module.exports = createAsset;