Search code examples
builddirectorygatsby

In Gatsby how to exclude a directory on gatsby build?


After reading the docs I've been unable to find an answer if on gatsby build I can exclude an entire directory or if it's excluded by default. For example if I have a directory on the main level:

  • /design: might include a style guide, SVG icons to be used, json object of the color palette, etc. etc.
  • /docs: directory for component structure for other developers to use, protocols for development, etc. etc.

Gatsby wouldn't be using or pulling anything from these directories and they'd only exist for production references. In my research I've read:

In Gatsby how can a directory be excluded on gatsby build or would it be excluded in the build process?


Solution

  • I'm not sure if it will fit your requirements but one easy thing you can do is to create a project structure like:

    /
    |--/docs
    |--/design
    |--/code
       |-- /.cache
       |-- /public
       |-- /src
           |-- /pages
           |-- /templates
           |-- /static
           |-- gatsby-config.js
       |-- gatsby-node.js
       |-- gatsby-ssr.js
       |-- gatsby-browser.js
    

    In that way, your /docs and /design will be outside the scope of Gatsby and when compiling/building your project, the only source code bundled will be the one inside in /code.

    A .git file placed in the root (/) will keep tracking all the file changes inside /docs, /design and /code as well.