parcel-bundler/parcel

πŸ›dist/ directory isn't cleaned on repeated builds

mikecfisher opened this issue Β· 12 comments

I have a very simple package that I'm using parcel to compile. When I run a build I notice that parcel generates new compiled javascript files with new hash numbers, but doesn't clean the old files. I've done extensive searching and can't seem to find a way to fix this. Is this the intended behavior?

Here's the command I'm running:

"build": "parcel build src/iframe.html"
Software Version(s)
Parcel 1.7.1
Node 8.9.4
npm/Yarn yarn 1.3.2
Operating System Mac OS

This is the intended behaviour. The hashes are content hashes.
These are used for invalidating browser cache, for changed files.
One way to (fix) this would be to put a remove command in front of the build command

There's a plugin for that parcel-plugin-clean-dist

Closing this, as the plugin should resolve the issue

In package.json, add another script named prebuild:

"prebuild": "rm -rf dist"

prebuild will run automatically before the build script.
Only works on Linux/Unix systems but saves you a dependency.

@helpermethod Thanks! Actually it works on Windows too :)

Only works on Linux/Unix systems

Then

"prebuild": "shx rm -rf dist/*"

where

shx is a wrapper around ShellJS Unix commands, providing an easy solution for simple Unix-like, cross-platform commands in npm package scripts

Though, then you lose that "saves you a dependency" upshot Β―\_(ツ)_/Β―

In windows I had to use
"prebuild": "rmdir dist /s /q"

to make it work.

The parcel-plugin-clean-dist isn't taking PRs or being actively maintained and, at least on my setup, doesn't seem to actually wipe the /dist directory. So I made an alternative parcel-plugin-nuke-dist, feel free to give it a shot πŸ˜„

To prevent different behaviour on windows/linux, rimraf also works great:

npm install rimraf --save-dev

in package.json:
"prebuild": "rimraf dist",

Hey, "prebuild" work also on macOS, no need to install plugin πŸŽ‰

Tested on maOS 10.14.6.

Grawl commented

this should not be solved using a plugin

this is not an optional feature

every Parcel user have a tons of unused files without this

In package.json, add another script named prebuild:

"prebuild": "rm -rf dist"

prebuild will run automatically before the build script.
Only works on Linux/Unix systems but saves you a dependency.

I'm using Cmder (Portable console emulator for Windows) and it supports linux based syntax so it works with Cmder too.

Thanks πŸ‘