DEV Community

Pacharapol Withayasakpunt
Pacharapol Withayasakpunt

Posted on

Include files, rather than ignore

In short, the syntax for .dockerignore, which is more restrictive than .gitignore is

# Ignore everything
**

# Allow files and directories
!/file.txt
!/src/**

# Ignore unnecessary files inside allowed directories
# This should go after the allowed directories
**/*~
**/*.log
**/.DS_Store
**/Thumbs.db
Enter fullscreen mode Exit fullscreen mode

So, my current .dockerignore is

# Ignore everything
**

# Allow files and directories
!/packages/server/src
!/packages/server/package.json
!/packages/server/yarn.lock
!/packages/server/tsconfig.json

!/packages/web/public
!/packages/web/src
!/packages/web/.browserslistrc
!/packages/web/babel.config.js
!/packages/web/package.json
!/packages/web/yarn.lock
!/packages/web/tsconfig.json
!/packages/web/vue.config.js
Enter fullscreen mode Exit fullscreen mode

.eslintignore is much closer to .gitignore, but I am not sure about nesting, which obviously, .gitignore can do.

*.*
!*.js
!*.jsx
!*.ts
!*.tsx
!*.vue
node_modules
dist
lib
Enter fullscreen mode Exit fullscreen mode

Top comments (2)

Collapse
 
bravemaster619 profile image
bravemaster619 •

So you choose whitelist, instead of blacklist.

Collapse
 
patarapolw profile image
Pacharapol Withayasakpunt •

Just like package.json's "files": [] is much safer than .npmignore.