Package detail

parcel-reporter-static-files-copy

elwin01367.4kMIT1.5.3

ParcelJS v2 plugin to copy static files from static dir to bundle directory.

parcel

readme

parcel-reporter-static-files-copy

ParcelJS v2 plugin to copy static files from some directory to output dir. There is no watcher - files are copied on the build finish.

Install

yarn add parcel-reporter-static-files-copy --dev
npm install -D parcel-reporter-static-files-copy

Usage

  1. Create a static directory in your project root.
  2. Fill it with your static files
  3. Add plugin to .parcelrc:
{
  "extends": ["@parcel/config-default"],
  "reporters":  ["...", "parcel-reporter-static-files-copy"]
}

PLEASE NOTE: "..." is not a placeholder - it is used to extend the default list of plugins (reporters in this case). Please see Parcel's plugins documentation for more information.

  1. Run build - and that's all! Files from the static directory will end up in dist!

Customization

Beyond the default settings, you can:

  1. Name of the directory to be copied.
// package.json
  {
  ...
  "staticFiles": {
    "staticPath": "customStatic"
  }
  1. Specify a directory to copy static files into

If files from staticPath needs to get copied into a subdirectory inside the dist dir - staticOutPath can be used:

// package.json
  {
  ...
  "staticFiles": {
    "staticOutPath": "vendor"
  }
  1. Destination of static files

The destination of static files can be set in plugin configuration. It will override --dist-dir parameter.

// package.json
  {
  ...
  "staticFiles": {
    "distDir": "customDist"
  }
  1. Multiple static folders

staticFiles entry in package.json can be set to the array of configurations instead of a single config. Thanks to that it is possible e.g. to copy files from different directories to the output package.

For example please see the example below with environmental variables.

  1. Different static files/folders based on the environmental variable

Different static files/folders can be copied based on the environmental variables using env map for config. There can be more than one variable to match - in that case, ALL must be the same. If env map is omitted - file(s) will be always copied.

The example below - when NODE_ENV is set to production then production.txt will be copied and if set to development then development.txt:

// package.json
  {
  ...
  "staticFiles": [
    {
      "staticPath": "production.txt",
      "env": {
        "NODE_ENV": "production"
      }
    },
    {
      "staticPath": "development.txt",
      "env": {
        "NODE_ENV": "development"
      }
    }
  ]

Additional example

Check examples directory for additional examples.

Flaws and problems

At this moment this plugin copies all static files from some static dir to the output (dist) directory. There is no watcher on static files - the only trigger is finishing the build (no matter if normal build or serving).

Contribute

You're interested in contributing? Awesome! Fork, make changes, commit and create pull requests. I'll do my best to merge changes!

Thanks and acknowledgement

Special thanks to @gmougeolle.

License

MIT

changelog

parcel-reporter-static-files-copy - changelog

1.5.3 - 20/09/2023

  • Fixed copying single file to path specified by staticOutPath.

1.5.1/1.5.2 - 29/07/2023

  • Fix for workspaces package.json resolution (refs issue #16)
  • Bump for forgotten Changelog in package (-;

1.5.0 - 02/01/2023

  • Support for multiple configurations. (refs issue #4)
  • Support for env variables (copy files only if env variables matches). (refs issue #4)

1.4.0 - 04/08/2022

Support for copying single file (not full folder) - issue #20

1.3.4 - 30/11/2021

Bump - only to put forgotten Changelog into npm package ;-)

1.3.3 - 29/11/2021

Change peer dependency of parcel plugin to dependency.

1.3.2 - 25/11/2021

Use path.join instead of string replacement when resolving file destination path.

1.3.1 - 16/11/2021

Change dependency of parcel plugin to peer dependency.

README.md update - regarding "..." from Parcel configuration.

1.3.0 - 25/03/2021

Added correct way of handling --dist-dir Parcel parameter.

Breaking change - staticFiles.distPath overrides --dist-dir option not otherwise.

1.2.2 - 25/03/2021

Bugfix - create the directory where static files will be put BEFORE trying to copy them.

1.2.1 - 01/02/2021

Minor changes - removing forgotten console.log.

1.2.0 - 01/02/2021

Added option to specify a path where to put static files in dist directory - staticFiles.staticOutPath.

Bring back reading --dist-dir Parcel parameter.

1.1.1 - 30/01/2021

Bugfix for creating paths - use path.join instead of hardcoded slash.

1.1.0 - 29/01/2021

Added option to specify custom dist path in configuration (in package.json) - staticFiles.distPath.

1.0.0 - 25/01/2021

Initial version.