Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V2: How to control dist directory #3820

Closed
olingern opened this issue Nov 21, 2019 · 24 comments
Closed

V2: How to control dist directory #3820

olingern opened this issue Nov 21, 2019 · 24 comments

Comments

@olingern
Copy link

olingern commented Nov 21, 2019

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.

@olingern olingern changed the title How to control dist directory V2: How to control dist directory Nov 21, 2019
@mischnic
Copy link
Member

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).

@olingern
Copy link
Author

@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` ?

@mischnic
Copy link
Member

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.

@damianobarbati
Copy link

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 :)

@mischnic
Copy link
Member

It's currently always in .parcel-cache/dist, here's some discussion about that: #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.

@vladinator1000
Copy link

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?

@mischnic
Copy link
Member

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

@half-halt
Copy link

How about prod vs. dev/debug?

@mischnic
Copy link
Member

mischnic commented Aug 4, 2020

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

@olingern
Copy link
Author

olingern commented Feb 1, 2021

My ass. must install weird nightly version, and read out-of-date docs and dumpster-diving the issues section to piece together how to build my project. wtf...

Dude, this work is people's free time. If it doesn't work for you, go build it yourself.

@mischnic
Copy link
Member

mischnic commented Feb 1, 2021

Both of your problems are listed here in the migration guide:

It's not our responsibility to meet your deadline.

@yairEO
Copy link

yairEO commented Feb 2, 2021

@mischnic - sorry for wasting your time - deleted all my comments

@eduardobcastro
Copy link

--dist-dir is not working. It creates a lot of files in the root dir.

@mischnic
Copy link
Member

mischnic commented May 7, 2021

@eduardobcastro You probably have a main: "index.html" line in your package.json. Remove that

@dev-ggaurav
Copy link

@eduardobcastro You probably have a main: "index.html" line in your package.json. Remove that

This worked for me thanks!

@mkpasala
Copy link

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

its worked for me

@jamesvclements
Copy link

@mischnic in the monorepo setup, what’s the best way to ask for each package/* to have its own dist folder when you build from the root directory?

@devongovett
Copy link
Member

@jamesvclements did you check out https://parceljs.org/getting-started/library/? You can define targets in each package.json (e.g. main/module).

@jamesvclements
Copy link

@devongovett
I did but I think I'm lost on the exact config.

My repo structure looks like this:

/
  package.json
  packages/
    package/
      src/
        index.js
      package.json

The root package.json has the build command:

"build": "parcel build packages/*/src/*.js"

and the package/package.json has the target:

    "targets": {
        "default": {
            "distDir": "./dist"
        }
    },

but running npm run build from the root directory still outputs in /dist/index.js rather than /packages/package/dist/index.js

@jamesvclements
Copy link

Update—I found a workaround. I definitely don't think this is the correct way to do it, but specifying targets for each package lets me run one build command, and then I can publish individual packages with npm publish packages/video-autoplay, etc:

CleanShot 2022-04-27 at 15 47 42@2x

@Nikh9123
Copy link

@eduardobcastro You probably have a main: "index.html" line in your package.json. Remove that

i don't have main: "index.html" this but it is also not working

@samiwazni
Copy link

samiwazni commented Oct 15, 2023

My project is built with React and the server is apps-script. When I make changes the React index.html generates the changes to apps-script.
I run into an error:

[email protected] start
parcel src/ --dist-dir ./apps-script

error: unknown option `--dist-dir'

@mischnic
Copy link
Member

@samiwazni
Copy link

@mischnic I do have it as:
"parcel build src/index.html --dist-dir"
"parcel build src/index.html --dist-dir"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests