You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
webpack-plugin/src/engines/helpers.js

53 lines
1000 B

const path = require('path')
const fs = require('fs')
1 year ago
1 year ago
const Media = require('./../factories/media.js')
1 year ago
/**
* asset - checks manifest.json for given path and return
* file path with id for cache busting
*
*
* @param {String} publicPath
*
*/
1 year ago
function asset(staticPath) {
1 year ago
1 year ago
// getting basePath
let result = staticPath
// path to mix-manifest
const file = path.join(path.resolve()) + 'mix-manifest.json'
1 year ago
if (fs.existsSync(file)) {
const manifest = fs.readFileSync(file)
const files = JSON.parse(manifest)
if (files[staticPath]) {
result = files[staticPath]
}
}
return result
}
/**
* asset - checks manifest.json for given path and return
* file path with id for cache busting
*
*
* @param {String} publicPath
*
*/
async function resize(src, sizes, options, done)
1 year ago
{
const media = new Media()
1 year ago
src = await media.resize(src, sizes, options)
done(null, src)
1 year ago
}
module.exports = { asset, resize }