Add images to assets manifest
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
|
||||
const path = require('path');
|
||||
|
||||
/**
|
||||
@@ -7,12 +8,12 @@ const path = require('path');
|
||||
* @return {String} JSON
|
||||
*/
|
||||
module.exports = (assets) => {
|
||||
const results = {};
|
||||
const manifest = {};
|
||||
Object.keys(assets).forEach((name) => {
|
||||
Object.keys(assets[name]).forEach((ext) => {
|
||||
const filename = `${path.dirname(assets[name][ext])}/${path.basename(`${name}.${ext}`)}`;
|
||||
results[filename] = assets[name][ext];
|
||||
manifest[filename] = assets[name][ext];
|
||||
});
|
||||
});
|
||||
return JSON.stringify(results);
|
||||
return manifest;
|
||||
};
|
||||
|
||||
50
assets/build/util/interpolateName.js
Normal file
50
assets/build/util/interpolateName.js
Normal file
@@ -0,0 +1,50 @@
|
||||
'use strict'; // eslint-disable-line
|
||||
|
||||
const path = require('path');
|
||||
const utils = require('loader-utils');
|
||||
|
||||
/**
|
||||
* Generate output name from output pattern
|
||||
*
|
||||
* @link https://github.com/kevlened/copy-webpack-plugin/blob/323b1d74ef35ed2221637d8028b1bef854deb523/src/writeFile.js#L31-L65
|
||||
* @param {string} pattern
|
||||
* @param {string} relativeFrom
|
||||
* @param {binary} content
|
||||
* @return {string}
|
||||
*/
|
||||
module.exports = (pattern, relativeFrom, content) => {
|
||||
let webpackTo = pattern;
|
||||
let resourcePath = relativeFrom;
|
||||
|
||||
/* A hack so .dotted files don't get parsed as extensions */
|
||||
const basename = path.basename(resourcePath);
|
||||
let dotRemoved = false;
|
||||
if (basename[0] === '.') {
|
||||
dotRemoved = true;
|
||||
resourcePath = path.join(path.dirname(resourcePath), basename.slice(1));
|
||||
}
|
||||
|
||||
/**
|
||||
* If it doesn't have an extension, remove it from the pattern
|
||||
* ie. [name].[ext] or [name][ext] both become [name]
|
||||
*/
|
||||
if (!path.extname(resourcePath)) {
|
||||
webpackTo = webpackTo.replace(/\.?\[ext]/g, '');
|
||||
}
|
||||
|
||||
/**
|
||||
* A hack because loaderUtils.interpolateName doesn't
|
||||
* find the right path if no directory is defined
|
||||
* ie. [path] applied to 'file.txt' would return 'file'
|
||||
*/
|
||||
if (resourcePath.indexOf('/') < 0) {
|
||||
resourcePath = `/${resourcePath}`;
|
||||
}
|
||||
|
||||
webpackTo = utils.interpolateName({ resourcePath }, webpackTo, { content });
|
||||
|
||||
if (dotRemoved) {
|
||||
webpackTo = path.join(path.dirname(webpackTo), `.${path.basename(webpackTo)}`);
|
||||
}
|
||||
return webpackTo;
|
||||
};
|
||||
21
assets/build/util/promisify.js
Normal file
21
assets/build/util/promisify.js
Normal file
@@ -0,0 +1,21 @@
|
||||
/**
|
||||
* Node-style asynchronous function.
|
||||
*
|
||||
* @callback nodeAsyncCallback
|
||||
* @param {string|null} err
|
||||
* @param {*} data
|
||||
*/
|
||||
/**
|
||||
* Promisify node-style asynchronous functions
|
||||
*
|
||||
* @param {nodeAsyncCallback} fn - Function with node-style callback
|
||||
* @param {this} [scope] - Scope to which the function should be bound. Default: fn
|
||||
* @returns {Promise} - An instance of Promise
|
||||
*/
|
||||
module.exports = (fn, scope) => function callback() {
|
||||
const args = [].slice.call(arguments);
|
||||
return new Promise((resolve, reject) => {
|
||||
args.push((err, data) => (err === null ? resolve(data) : reject(err)));
|
||||
return fn.apply(scope || fn, args);
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user