How do I get a different output directory for each entry point?April 17, 2020 at 9:14pm
Trying to get started with Parcel 2 here... I have one Parcel 1 repo with has a bunch of different entry points, each of which build to a different "--out-dir".
Since the --out-dir option has been replaced with "targets" in the package,json, I was kind of excited that it was going to make this cleaner, but I'm a bit confused by the docs about targets, they don't seem to allow you to specify an entry point. Is there a way to specify an entry point within the target in package.json, so that each target can encapsulate an entypoint and a destination directory together?
Docs at https://parcel2-docs.now.sh/getting-started/configuration/ say that "Every entrypoint will be processed (and outputted) once per target." which is not what I want at all, but if targets are the new way of specifying an out directory, how do I get a different output directory per entry point? These docs also refer to a "--dist-dir" CLI option and say that "--out-dir" was renamed to "--dist-dir" but when I try that approach i get "error: unknown option `--dist-dir'"
April 17, 2020 at 9:24pm
Are you running
parcel index.html --dist-dir www? That option is only supported with build and watch: https://parcel2-docs.now.sh/getting-started/cli/#parameters-specific-to-the-non-server-commands-(watch-and-build)
I have one Parcel 1 repo with has a bunch of different entry points, each of which build to a different "--out-dir".
Natively, this isn't possible: https://github.com/parcel-bundler/parcel/issues/3302
There is however a workaround: invoke Parcel once per target and specify
parcel build entry1.js --target entry1 && parcel build entry2.js --target entry2(this is however slower than if Parcel supported this directly)
I have 2.0.0-alpha.3.2 and it doesn't seem to want to take --dist-dir no matter whether it is a "build" or "watch" and also --public-url is not recognized even though it's documented in the link above. As for your work-around, yes I had thought of it, though it seems really awkward and redundant to do that when I have one target per entry. In that case it was better the way Parcel 1 worked where I specified both the --out-dir and the entry on the command line, at least it was consistent that way (with everything coming from the command line). I either want to do everything on the comman d line or everything from the package.json, so a wierd mix of the two feels like the worst of both worlds
I see! I just upgraded and you are right --dist-dir is working on the nightly. Thanks! That solves it!
I think it's going to be an issue for me if I cannot use --dist-dir on the default mode ("serve") because I'm relying on
parcel-plugin-static-files-copyto get some of my static assets into place into the directory where I build/test it from, so if I don't have control over what directory I'm testing it from, that whole situation falls apart. Or is
parcel-plugin-static-files-copymade obsolete by some internal support for static files now?
April 20, 2020 at 9:00am
My static file scenario is as I described before, where I have multiple entry points, which I want to have bundled to separate distribution directories, and each entry point has a different collection of static files associated with it. I included a diagram of this.
In this case it's a sort of a "game" where the different levels of the game have different code which I want bundled separately so that you don't load all the code for all the levels at once. Likewise, there are static assets which only belong to certain levels which don't belong in the other levels. On the other hand there is some code and assets which are shared between all the levels.
I realize that Parcel is built around the idea of "assets" which are included and bundled via import statements, as in https://parceljs.org/assets.html, but I don't think that makes sense for game assets (e.g. lots of large images and possibly 3D models). I don't want those things to become part of the bundle, but instead just want them to be static files which are loaded on demand (i.e. when they are requested to be loaded).
To make this work in Parcel 1, I added support to the (now obsolete)
parcel-plugin-static-files-copyplugin for having files conditionally copied, depending on a regex of the dist directory. (https://github.com/elwin013/parcel-plugin-static-files-copy/pull/22)
April 20, 2020 at 10:48pm
I realize that if this stuff was all just hosted on a standard ordinary web server that it would be better to keep the common stuff in one place and rely on browser caching to avoid getting them multiple times. But my situation is somewhat unique I suppose. Each of the "level" is to be built into a self-contained zip file which needs to contain everything necessary for that level. That's because each of these "levels" is hosted separately in a larger system that is managing the content (a "learning management system", a large enterprise piece of crap that I don't want to go into to much detail about).
But for purposes of my question, you could just ignore the fact that thare are "common static files" and instead think of it as each level having its own unique set of static files. I still have a need to copy specific files into specific dist dirs, and it seems that I cannot currently do that in Parcel2 in the "serve" mode, whereas in Parcel1 I can accomplish it with a mix of the static file copying plugin and the --out-dir parameter.
August 23, 2020 at 4:21pm