{"_id":"esbuild-copy-static-files","_rev":"1-4fb4a941ea36b1083866eaf197bbc52b","name":"esbuild-copy-static-files","dist-tags":{"latest":"0.1.0"},"versions":{"0.1.0":{"name":"esbuild-copy-static-files","version":"0.1.0","description":"An esbuild plugin to copy static files that changed from a source directory to a destination directory","main":"index.js","repository":{"type":"git","url":"git+https://github.com/nickjj/esbuild-copy-static-files.git"},"keywords":["esbuild","copy","static","files"],"author":{"name":"Nick Janetakis"},"license":"MIT","bugs":{"url":"https://github.com/nickjj/esbuild-copy-static-files/issues"},"homepage":"https://github.com/nickjj/esbuild-copy-static-files","gitHead":"0c3d27c3bc102047d5fc12acf4498e9ec9dd96d8","_id":"esbuild-copy-static-files@0.1.0","_nodeVersion":"16.13.1","_npmVersion":"8.1.2","dist":{"integrity":"sha512-KlpmYqANA1t2nZavEdItfcOjJC6wbHA21v35HJWN32DddGTWKNNGDKljUzbCPojmpD+wAw8/DXr5abJ4jFCE0w==","shasum":"4bb4987b5b554d2fc122a45f077d74663b4dbcf0","tarball":"https://registry.npmjs.org/esbuild-copy-static-files/-/esbuild-copy-static-files-0.1.0.tgz","fileCount":12,"unpackedSize":11797,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJhzRY+CRA9TVsSAnZWagAAay0P/2+5yBeFeYRBwxby7csr\nrwS4CuayY7r2AsHIL2Vqj7VYZVjJsFaYUvn2NQWtCX1T2y/Ua/gbikGSptWI\nwcVlOC0aIfBKo64h5cU4rqHtjhguEQnlgLLzOpQFFfSXVmj01AWpAc6+V3dX\n08pg7HuzVK+fGq04wqfpS1d+QxLeu92TSPoUrJWfKErHOCQZ+SuELYpfzAgI\nxiJYgMsqyEieaLIMORxbZABCtsJpv65UBpPFJAMM8x/Vz1TzRcvs7qm8rmPj\nGAHfJyG+uHShW2MA7z2/M/EPb5snNYx4VU3jjAdgUqoWY1+mib5esO1Hj1M5\nRTawGg3gVwPWQb9/qKQWtjKNhjC9AdTPWZzv6mHCN04wSmTiZ1l98fh2w6US\nbNmfRUcUGtGjG58t2It0WdFyC1ztm0FI26P7EpNNBTGtaQSrnrxht1BEQe/Y\niXimsMBD4HoOTZru+NBMeCzwPZeV6k//A67FtZKl71t5Tay3Gp7V0CMhtoo6\nq7I2PUuw3Xs86zZc8vK8fHpwaSQyGzwnGrxBnJwKvfV5HsXPwx5eN+PsMU9p\n6zGrqH7UdfyplIGginfVzE8NcP6T1onKu6CKdDBeHmeM8VemPROfN+Sw7ilW\nKxqXiu35S7Fwsw+kDDsrbtE6d929o0nszf5q5z8p6DLKuUpGNBzhFqze0EO5\nTt4P\r\n=rnNu\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIC6+l9ffRYQuks8nVIgfKHdYhjvdDjeyu6NR8NTuf4PqAiAfZC5r4ZicZDy8EGDeWS3/AIbdRuVAd3zL2Yxg5boZMg=="}]},"_npmUser":{"name":"nickjj","email":"nick.janetakis@gmail.com"},"directories":{},"maintainers":[{"name":"nickjj","email":"nick.janetakis@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/esbuild-copy-static-files_0.1.0_1640830526428_0.965337613647083"},"_hasShrinkwrap":false}},"time":{"created":"2021-12-30T02:15:26.357Z","0.1.0":"2021-12-30T02:15:26.582Z","modified":"2022-05-01T11:47:56.143Z"},"maintainers":[{"name":"nickjj","email":"nick.janetakis@gmail.com"}],"description":"An esbuild plugin to copy static files that changed from a source directory to a destination directory","homepage":"https://github.com/nickjj/esbuild-copy-static-files","keywords":["esbuild","copy","static","files"],"repository":{"type":"git","url":"git+https://github.com/nickjj/esbuild-copy-static-files.git"},"author":{"name":"Nick Janetakis"},"bugs":{"url":"https://github.com/nickjj/esbuild-copy-static-files/issues"},"license":"MIT","readme":"# esbuild-copy-static-files\n\n![CI](https://github.com/nickjj/esbuild-copy-static-files/workflows/CI/badge.svg?branch=main)\n\nAn [esbuild](https://esbuild.github.io/) plugin to efficiently copy static\nfiles from a source directory to a destination directory.\n\n✔️ Only copy files that changed *(it compares an MD5 hash of each file)*  \n✔️  No 3rd party dependencies *(it only uses a few functions from the Node standard library)*\n\n## Why?\n\nI mainly created this because a certain live reloading tool I use didn't filter\nout files that didn't change. This resulted in dozens of unnecessary file being\ncopied and log output in development every time I changed a single CSS or JS\nfile. It was wildly inefficient.\n\nThis plugin fixes the above because it'll only copy static files if they\nchanged on disk since they were last copied.\n\n### How it works at a high level\n\nFor most web apps, when it comes to my front-end I like the idea of this type of directory structure:\n\n```sh\n# This is where your assets are located and is used as input for esbuild.\nassets/\n├── css/\n│   └── app.css\n├── js/\n│   └── app.js\n├── static/\n│   ├── images/\n│   │   └── logo.png\n│   ├── favicon.ico\n│   ├── robots.txt\n├── esbuild.config.js\n├── package.json\n├── postcss.config.js\n├── tailwind.config.js\n└── yarn.lock\n\n# This is the output of where esbuild will write its file(s) to.\npublic/\n├── css/\n│   └── app.css\n├── js/\n│   └── app.js\n├── images/\n│   └── logo.png\n├── favicon.ico\n├── robots.txt\n```\n\nIn my opinion it's really nice having all of your assets in 1 spot which then\nget output to another location.\n\nesbuild manages the `js/` directory and TailwindCSS (or whatever you prefer)\nmanages the `css/` directory but that leaves us with a bunch of static files\nthat are composed of HTML, icons, images, fonts and more.\n\nThis esbuild plugin will copy your static files to your esbuild output\ndirectory. No processing will be done on these static files. It's a quick `cp`\nand only files that have changed are copied so it's really efficient.\n\nYou can name your `static/` and `public/` directories and configure their paths\nhowever you want. We'll go over all of the configuration options in a bit.\n\n## Installation\n\n```sh\n# Prefer Yarn?\nyarn add --dev esbuild-copy-static-files\n\n# Or NPM instead?\nnpm install --save-dev esbuild-copy-static-files\n```\n\n## Getting Started\n\nIf you had the same directory structure as above, here's the bare minimum\nesbuild config to get going:\n\n```js\nconst esbuild = require('esbuild')\nconst copyStaticFiles = require('esbuild-copy-static-files')\n\nesbuild.build({\n  entryPoints: ['./js/app.js'],\n  outfile: '../public/js/app.js',\n  bundle: true,\n  minify: true,\n  sourcemap: false,\n  watch: false,\n  plugins: [copyStaticFiles()],\n})\n```\n\n## Configuration\n\nThis plugin uses Node's [`fs.cpSync`\nfunction](https://nodejs.org/api/fs.html#fscpsyncsrc-dest-options) under the\nhood. Any option that it has can be configured here.\n\nHere's a list of what you can configure and the default values if you don't\noverride them:\n\n```js\n  plugins: [\n    copyStaticFiles({\n      src: './static',\n      dest: '../public',\n      dereference: true,\n      errorOnExist: false,\n      filter: EXPLAINED_IN_MORE_DETAIL_BELOW,\n      preserveTimestamps: true,\n      recursive: true,\n    })\n  ],\n```\n\n**In most cases you'll likely only change the `src` and `dest` to fit your\nproject's directory structure.**\n\nHere's the docs of every configurable option from Node's documentation:\n\n- `src` source path to copy.\n- `dest` destination path to copy to.\n- `dereference` dereference symlinks.\n- `errorOnExist` when `force` is `false` and the destination exists, throw an error.\n- `filter` function to filter copied files / directories. Return `true` to copy the item, `false` to ignore it.\n- `force` overwrite existing file or directory. The copy operation will ignore errors if you set this to false and the destination exists. Use the `errorOnExist` option to change this behavior.\n- `preserveTimestamps` when `true` timestamps from `src` will be preserved.\n- `recursive` copy directories recursively.\n\n### How does the filter function work?\n\nBy default it will filter out, AKA skip copying any files that haven't changed.\nIt does this by getting the MD5 hash of each `src` and `dest` file. If both\nfiles have the same MD5 hash then it get skipped.\n\nThis is nice because if you had let's say 50 static files and only 1 of them\nchanged then only 1 file will get copied.\n\n#### Using a custom filter function\n\nIf you can think of a more efficient way of detecting which file(s) should get\ncopied you can customize the filter function by providing your own function\nthat returns `true` or `false` based on whatever criteria you prefer.\n\nHere's an example of a simple filter function that always returns `true`:\n\n```js\n  plugins: [\n    copyStaticFiles({\n      filter: function () { return true },\n    })\n  ],\n```\n\n## About the author\n\n- Nick Janetakis | <https://nickjanetakis.com> | [@nickjanetakis](https://twitter.com/nickjanetakis)\n\nI'm a self taught developer and have been freelancing for the last ~20 years.\nYou can read about everything I've learned along the way on my site at\n[https://nickjanetakis.com](https://nickjanetakis.com/).\n\nThere's hundreds of [blog posts / videos](https://nickjanetakis.com/blog/) and\na couple of [video courses](https://nickjanetakis.com/courses/) on web\ndevelopment and deployment topics. I also have a\n[podcast](https://runninginproduction.com) where I talk with folks about\nrunning web apps in production.\n","readmeFilename":"README.md"}