The copy plugin allows users to copy files around as part of the build command. For example, Greenwood uses this feature to copy all files in the user's /assets/ directory to final output directory automatically. You can use this plugin to copy single files, or entire directories.
This plugin supports providing an array of "location" objects that can either be files or directories.
import path from 'path';
export function myCopyPlugin() {
return {
type: 'copy',
name: 'plugin-copy-some-files',
provider: (compilation) => {
const { context } = compilation;
return [{
// can only copy a file to a file
from: path.join(context.userWorkspace, 'robots.txt'),
to: path.join(context.outputDir, 'robots.txt')
}, {
// can only copy a directory to a directory
from: path.join(context.userWorkspace, 'pdfs'),
to: path.join(context.outputDir, 'pdfs')
}];
}
};
}
You can see more examples in the Greenwood repo.