Open sdedovic opened 1 month ago
You should be able to read the original name of the main entry asset like this:
import {basename} from 'path';
export default new Namer({
name({bundle, bundleGraph}) {
let mainAsset = bundle.getMainEntry();
if (mainAsset.type === 'htpp')
return 'templates/' + basename(mainAsset.filePath);
}
}
});
While the above works, it doesn't completely solve the problem. I still have no way to put the other assets into a subdirectory of dist-dir
without the paths in files being borked. Second, I can no longer have a source directory called templates
as the name will conflict.
Would you consider my above possible solution? Or potentially a plugin type that runs after all other plugins simply to persist files without other side effects (like Namer plugins have)?
I have searched the issues / PRs and cannot find something to help support what I need. I am happy to open a PR if someone can point me in the correct direction.
π feature request
I want to be able to split my assets up by type into two separate folders, without the Namer changing paths.
This is because files under
template
will be deployed to a server application and files understatic
will be deployed to a CDN.Another way to view this - after the Namer, Optimizesr, Compressors run, partition the files into two folders based on bundle type without changing the name.
π€ Expected Behavior
Naming assets (in a Namer plugin) is separate from placing them in the output directory (e.g. support a subdir without changing all the paths).
π― Current Behavior
The name is the path on disk and the reference in other assets (e.g.
src="..."
)π Possible Solution
As far as I am aware, this cannot be done now. I was thinking of changing the
Namer
contract to return either aFilePath
string or an object of the structure:To support existing behviour (where these are the same) and new behaviour (where these can be different).
π¦ Context
I am using Parcel to develop HTML templates. The template files I write reference JS, CSS, and other types of assets relatively. Parcel then processes these Templates to resolve references to assets and point to now bundled/built assets. The problem is that Templates are shipped in a different way than static files - the former are injected into a server application and the latter are deployed on a CDN.
π» Examples
Currently I am doing this manually,