Created
April 24, 2020 14:13
-
-
Save dustinsoftware/63780eac0d85041fa9b2969df612fb73 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* eslint-disable */ | |
const fs = require('fs'); | |
const path = require('path'); | |
const glob = require('glob'); | |
function createManifest(options = { assetPath: '', assetKeys: [] }) { | |
let assetManifest = { script: [], link: [], appVersion: '0.0.1' }; | |
for (let file of options.assetKeys.flatMap(assetKey => glob.sync(`${options.assetPath}${assetKey}*`))) { | |
let basename = path.basename(file); | |
let extname = path.extname(file); | |
let nameWithoutBuildHash = basename.substring(0, basename.indexOf('.')); | |
if (options.assetKeys.includes(nameWithoutBuildHash)) { | |
if (extname === '.js') { | |
assetManifest.script.push({ name: nameWithoutBuildHash, src: basename }); | |
} | |
if (extname === '.css') { | |
assetManifest.link.push({ rel: 'stylesheet', name: nameWithoutBuildHash, href: basename }); | |
} | |
} | |
} | |
fs.writeFileSync(options.manifestPath, JSON.stringify(assetManifest)); | |
} | |
createManifest({ manifestPath: 'dist/assets/asset-manifest.json', assetPath: 'dist/assets/', assetKeys: ['vendor','menu-audit-logs']}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment