UNPKG

@fet.web/parcel-namer-simple-structure

Version:

Plugin tries to retain the existing folder structure of your source files.

27 lines (25 loc) 1.06 kB
const { Namer } = require("@parcel/plugin"); const path = require('path') module.exports = new Namer({ async name({ bundle, bundleGraph, logger, options }) { const bundleGroup = bundleGraph.getBundleGroupsContainingBundle(bundle)[0] const bundleGroupBundles = bundleGraph.getBundlesInBundleGroup(bundleGroup, { includeInline: true, }); const mainBundle = bundleGroupBundles.find(b => b.getEntryAssets().some(a => a.id === bundleGroup.entryAssetId)) const isEntry = bundleGraph.isEntryBundleGroup(bundleGroup) let name = getFileName(bundle, bundleGraph) if (!(isEntry && bundle.id === mainBundle.id)) { name += "." + bundle.hashReference } return name + "." + bundle.type }, }); function getFileName(bundle, bundleGraph) { let root = bundleGraph.getEntryRoot(bundle.target) let filePath = bundle.getMainEntry().filePath filePath = filePath.replace(root, '') filePathObj = path.parse(filePath) filePath = path.join(filePathObj.dir, filePathObj.name) return filePath }