Parcel: V2: How to control `dist` directory

Created on 21 Nov 2019  路  9Comments  路  Source: parcel-bundler/parcel

Parcel Version: 2.0.0-alpha.3.1
OS: Ubuntu 18.04


Context:

I have a pretty simple use case that worked well with parcel 1.x

Basically, I have a server that serves out of public directory where I'd like my build to be placed.

Example:
/server/public/js

In Parcel's previous version, I just used the -d option to do something like:
parcel watch ./app/client/src/index.tsx -d ./dist/server/public/js

or

parcel build ./app/client/src/index.tsx -d ./dist/server/public/js

In the current version, I receive an error:
error: unknown option -d

I've tried finding this option via the README, parcel --help build, and searching "dist" on the repo. If this is documented somewhere, it's not clear and/or buried.


Questions

  • Is there a migrating guide?
  • Can I control where output is placed?

Coming from other configuration tools, this has been a godsend. So, thanks for the ease of use.

Question

Most helpful comment

If you have scripts like

  "scripts": {
    "build:client": "parcel build client/index.html --out-dir dist/client",
    "build:server": "parcel build server/index.js --target node --out-dir dist/server",
}

How would you migrate that to v2?

All 9 comments

Can I control where output is placed?

Parcel 2 can do multiple "builds" at once, so a global dist dir didn't make sense anymore. In your case, adding this entry to your package.json should work:

{
  // ...
  default: "dist/server/public/js/index.js"
  // ...
}

Is there a migrating guide?

That would definitely be part of the docs (yet to be written).

@mischnic I see. I wouldn't mind opening a PR on how to migrate building from v1 to v2. I'm sure I'll need some suggestions from reviews, though.

Is that something that would go in the root 'README` ?

The readme was originally the specification for Parcel 2 and unfortunately serves as documentation as well. This documentation should really go onto the website (https://github.com/parcel-bundler/website) but we haven't really setup anything yet.

Is it possible to output the dist directory when using yarn parcel index.html without specifying anything in the package.json?

Otherwise testing the actual http serving files is not possible, there's no dist :)

It's currently always in .parcel-cache/dist, here's some discussion about that: https://github.com/parcel-bundler/parcel/issues/3691.

With parcel index.html you don't need to start a http server yourself?
If you do want to do that, I'd recommend yarn parcel watch index.html so that you can setup a server in dist yourself.

If you have scripts like

  "scripts": {
    "build:client": "parcel build client/index.html --out-dir dist/client",
    "build:server": "parcel build server/index.js --target node --out-dir dist/server",
}

How would you migrate that to v2?

@vladinator1000 At the moment, the only way is a monorepo-like setup (so with package.json in client and one in server).

How about prod vs. dev/debug?

In the meantime, --dist-dir was added for Parcel 2 (behave like v1's --out-dir)

Was this page helpful?
0 / 5 - 0 ratings