ParcelJS plugin to copy static files from some directory to directory with bundle.
yarn add parcel-plugin-static-files-copy --dev
npm install -D parcel-plugin-static-files-copy
staticdirectory in you project root.
- Fill it with your static files
- Run build - and that's all!
Beyond the default settings, you can:
- Name of the directory to be copied.
- Copy single files.
- Copy multiple directories.
- Copy from a different directory based on different output directory.
- Watch for changes during development (rebuilding when necessary).
- Exclude paths from copying.
The following configures the plugin to copy all files in
public to the build directory and watch for changes
in all source files (
** is a deep wildcard).
Multiple Static Directories
To copy more than one directory to the build directory, specify
staticPath as an array. The following copies
Copying single files
To copy single file (instead of content of directory) just pass path to a file instead of directory.
Different source of static files based on output directory
To copy different files (from different directories) based on output directory (e.g.
--out-dir dist1 and
staticPath a object:
Specify directory to copy static files into
If you want your files from
staticPath to get copied into a subdirectory inside the parcel
staticPath an object with
Copies files from
static1 into the
vendor directory inside the
Watching for Changes
Parcel can rebuild your bundle(s) whenever changes occur in the static directory. This is disabled by default, but it can be enabled by specifying a glob pattern for files that shoudl be watched.
Note the relative file path is used in matching (not just the file name). To match filenames in deep directories, start with a "globstar" (double star). The plugin uses Node's built-in Minimatch Library for glob matching.
The following watches all XML files in the static directory:
To disable watching, either remove the
"watcherGlob" key (disabled is the default) or set it to false/null/undefined:
You can exclude files and directories in your
staticPath from getting copied to the
outDir by specifying
.md files in the
public path from getting copied.
excludeGlobs are possible by specifying it as array:
docs directory and all files inside the
docs directory from getting copied.
You can use the
excludeGlob and negate it to achieve including behavior:
Includes only files from
locales directory with
Minimatch glob options
Passing options into minimatch to change
behavior is possible by specifying a
test directory and all files inside the
test directory, including files starting with a dot, from
Dev and production config using NODE_ENV
You can use
env parameter in
staticPath object to select static path used in environment chosen by passing
build:devwill copy files from
build:prodwill copy files from
You can specify from zero to many static paths per environment.
Check examples directory for additional examples.
You're interested in contributing? Awesome! Fork, make change, commit and create pull request. I'll do my best to merge changes!