-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Flag to delete output folder before building #3591
Comments
Hi @mkg20001 Userfull links |
I would say using gulp is overkill here, running But I still think that this should be somehow integrated into Parcel. |
I'm sorry if it comes around as a stupid question, but is there really a reason to not remove the output directory before building? What would be the use case for that? I feel like removing that directory beforehand is what you would want by default 99% of the time, so just making it the default behavior with no flags involved might make sense, and that other 1% of cases would be handled with manual scripting. |
@kirillrogovoy While I tend to agree with that, it's still something someone might want to disable. Although we could also add it and then wait for somebody to request that (disabling auto-deletion) as a feature |
I'm sure there'll be cases where auto-deletion is undesirable, but I'd be curious to study them. Ultimately, just as for manual deletion, preservation might be done via scripting around Parcel for that 1 case out of 100. :) I'm going to see what it'd look like codewise to add auto-deletion. |
Just adding https://npm.im/rimraf propably One problematic case would be symlinks, in that case I think it should check if it's a symlink via lstat and instead rimraf all the files in the folder and not the folder (link) |
So I guess it would look like this — #3616. |
FWIW, if your build step involves multiple different tools, and all of them decide to clear the output directory before building, it makes it extra annoying to get them working together. A good reason for making it a flag. The term "clean" is often used for this purpose, so it could be |
@ianstormtaylor I kind of see what you mean, but I can't come up with an example... I mean:
But I assume I might be missing something obvious here too. |
@kirillrogovoy the use cases that become annoying are ones where (a) you have to use two different tools (bundlers, transpilers, etc.) and (b) you need them to both use the same directory for their output. There are probably many combinations of edge cases that end up having both constraints. That said, the flag could either be But something to consider too is that there might be big performance gains to be had using caching and not cleaning by default (unless cleaning got a lot smarter than |
My preference would be to have the dist cleaned by default, but I'd go with either. Waiting for the feedback from the core team. |
Also unlike Parcel 1, Parcel 2 can output files wherever you want (not necessarily into a {
"name": "my-package",
"source": "src/index.js",
"main": "index.js"
} In that example, the dist directory is actually the main package dir with all your source code too. You wouldn't want to delete that. |
Does parcel@1 plugins still work on parcel@2? I was using |
No, the plugin system was completely changed. |
this is going to be implemented? I guess this is basic functionality, lib should provide, --clean-before-build or --clean flag can be implemented |
at the moment I'm using npm scripts: "preparcel": "rm -rf dist/",
"parcel": "parcel $RUN src/index.js --no-autoinstall",
"build": "RUN=build npm run parcel -- --no-cache",
"watch": "RUN=watch npm run parcel",
"serve": "RUN=serve npm run parcel", but it would be nice to clean dist with plugin, etc, also started similar discussion |
I would add the same option for |
I have to use the following as a workaround. I really like the idea of a --clean flag but it looks like nobody has implemented such a thing yet. This only works on windows.
this breaks however if there is not a dist folder existing |
The best way to handle this is having control of the code.
For example: project/
|dist/
|...
|src/
|assets/
|text.txt
|memos.txt
|info.ini
|css/
|style.css
|img/
|a.png
|b.jpg
|c.jpeg
|data.json
|not-to-copy.json
|not-to-copy.conf
|index.js
|index.html
|package.json If you have a project structure like this add, some scripts to the {
...
"source": "src/index.html",
"scripts": {
"clean-dist": "rm -rf dist && mkdir dist",
"copy-img": "cp -vR ./src/img ./dist",
"copy-data": "cp -r src/data.json dist",
"copy-assets": "cp -r src/assets/* dist",
"copy-files": "npm run copy-img & npm run copy-assets & npm run copy-data",
"init": "npm run clean-dist && npm run copy-files",
"start": "npm run init && parcel",
"build": "npm run init && parcel build"
},
...
} This configuration will sequentially run |
Could there not be an option to simply allow overwriting output files? Right now, if I want to commit all my output files to my repository, I simply can't. When I'm running a parcel build with API Can't run an entire folder cleanup because most of the time these output folders are used for different Parcel compiled assets. The solution for now is to remove manually these files before compiling because we never know what the output of parcel.run() will give us. If I'm processing a .ts file with a .scss import it will result in 2 different files. We basically just want to use Parcel as a build/compiler tool outside of the context of a SPA application. Is there a limitation to allow overwriting output files because of Parcel cache? |
🙋 Feature request
A flag/option to delete the output folder before building.
It's common place to do that in order to avoid mixing dev asssets and production assets.
🤔 Expected Behavior
Simply remove the output destination recursively before building via a flag
Should be enabled by default.
😯 Current Behavior
It has to be scripted manually.
💁 Possible Solution
Per-target flag/option
deleteBeforeBuild
which is enabled by default in production build mode. Simply removes the output folder.🔦 Context
Most people add
rm -rf dist;
before the parcel commandThat's bad for windows users since rm doesn't work that way there
Having it in parcel would make things a lot easier and save the hassle of manually adding the recursive rm command
💻 Examples
$ npx parcel build index.html -o dist --delete-before-build
The text was updated successfully, but these errors were encountered: