Don't apply `.gitignore` rules to the publish directory

Dear Netlify Community,

please don’t apply .gitignore rules to the publish directory!

I’m deploying a NuxtJS app in static mode. During build it will generate a
folder /dist which can be uploaded to any static file hoster. Here’s my
configuration:

Repository: github.com/Schaeferjo/werkhof-ichen
Base directory: frontend
Build command: yarn run generate
Publish directory: frontend/dist

During build, Netlify would basically do the following:

cd frontend
yarn install
yarn run generate

It would then upload the generated folder frontend/dist.

I previous deployments I could see that a particular file was missing: /sw.js

After I changed this line in my .gitignore:

sw.*

To this line:

static/sw.*

The file was suddenly being uploaded during deployment!

Here’s the commit: https://github.com/Schaeferjo/werkhof-ichen/commit/b0a79a17e63b659913b2c039b71ba061a6e9f8b0

I can see what’s going on here but this behaviour doesn’t make any sense. The folder /dist is already in my .gitignore. I don’t want this folder to be in version control, that’s why it’s git-ignored. During deployment, I want it to be uploaded, why do you even apply .gitignore rules here?

Besides that, please document this behaviour!

On another occasion I had a hard time figuring out that a local deployment via Netlify CLI behaves differently compared to a remote deployment of Netlify. In this case, any **/node_modules/ would not be uploaded, even if this folder was in the dist/ directory under _nuxt/something/node_modules/ as it contained my application code required during runtime.

Hope these observations may help some other developers!

Cheers,
Robert

Hi Robert,

That does sound odd! However, I don’t quite see how your change to include “static/sw.*” has anything to do with the behavior of the “dist/” folder. This is probably because I’m missing something, not because you’re wrong or dumb :slight_smile:

My understanding is that gitignore only matters when committing - when we pull, we’ll take whatever is in git, and we’ll deploy whatever is in dist (except, as you discovered, node_modules). But I guess this is not what you were seeing?

Could you link me to the build logs in our UI - one that worked after the change, and one that didn’t before - so I can try to dig in a bit more?

Hi Chris!

Of course, here you go:

Broken build: https://app.netlify.com/sites/werkhof-ichen-frontend/deploys/5f401db77ddef1000894358c/
Missing file (404): https://5f401db77ddef1000894358c--werkhof-ichen-frontend.netlify.app/sw.js

Fixed build: https://app.netlify.com/sites/werkhof-ichen-frontend/deploys/5f4249e1c605d9000765cb2c
Correctly uploaded file: https://5f4249e1c605d9000765cb2c--werkhof-ichen-frontend.netlify.app/sw.js

I totally agree, a .gitignore should only affect the indexed files in the repository. Not the uploaded files during deployment. That is exactly what I complain about and what I discovered by try/error. The cause of the problem must be the .gitignore as changing the ignore rule to the more specific static/sw.* (there is no static/ subfolder in the generated dist/ folder) fixes the issue.

My additional observation with node_modules: The command line tool and the containerized deployment by netlify behave differently. The containerized deployment uploads folders **/node_modules in the publish directory. If I try to deploy via command line, it does not. This is strange. Command line tool and containerized deployment should always behave consistently.

Don’t you agree? :smiley:

The second problem does not exist for me anymore as Nuxt now names the folder _nuxt/vendors/ instead of _nuxt/node_modules/ in a newer version. Nevertheless, it caused me some frustration to discover this behaviour via try/error.

hey @roschaefer, a quick update that we are looking into this behaviour and we will connect back here in case we have more info on this. thanks so much for pointing this out to us, we appreciate it!!

hi there, thanks again for reporting this! we made some changes to how this works based on your report :smiley: