You can use this plugin to copy files in your Gatsby project. Specify absolute source
path and relative destination
path using plugin options.
-
In
gatsby-plugin-copy-files
you should specify destination and you have no option to copy to multiple direcotries in one go.gatsby-plugin-copy-files-enhanced
enables you to wildcard your destination, so that you can easily copy files. -
This plugin has option to overwrite your destination direcotry simply using
purge
plugin option.
Option | Description |
---|---|
source |
Absolute path of the source (eg: ${__dirname}/path ) |
destination |
Relative path to destination within public/ direcotry You can add /*/ inside destination path to wildcard destination lookup Refer to graphical explanation for better understanding |
purge |
Overwrite destination. false by default |
This plugin should be used with gatsby-source-filesystem
{
resolve: 'gatsby-plugin-copy-files-enhanced',
options: {
source: `${__dirname}/src/reportTemplate` ,
destination: '/reports/*/',
purge: true,
}
}, {
resolve: 'gatsby-plugin-copy-files-enhanced',
options: {
source: `${__dirname}/src/images` ,
destination: '/containers/*/images',
purge: false,
}
}
Let's consider that you have a template.js
file that you need to copy to all reports within public/reports/
direcotry and you are not sure of report names and how many would be there.
In such case you can wildcard the destination path so that you can easily copy template.js
to all direcotries with public/reports/
{
resolve: 'gatsby-plugin-copy-files-enhanced',
options: {
source: `${__dirname}/src/template/` ,
destination: '/reports/*/',
purge: true,
}
}
Inspired by gatsby-plugin-copy-files
<3