# rollup-plugin-static-files

> Copies static files into output directory with support for hash replacement.

Latest version **0.3.0** (published 2023-11-29) · MIT license · 0 weekly downloads

## Install

```sh
npm install rollup-plugin-static-files
pnpm add rollup-plugin-static-files
yarn add rollup-plugin-static-files
bun add rollup-plugin-static-files
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.3.0 |
| Published | 2023-11-29 |
| First published | 2019-01-20 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 5.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Paul Sweeney |
| Maintainers | pepsryuu |

## Links

- npm: https://www.npmjs.com/package/rollup-plugin-static-files
- npm.io page: https://npm.io/package/rollup-plugin-static-files

## Dependencies (3)

- [cheerio](https://npm.io/package/cheerio.md) ^1.0.0-rc.2
- [fs-extra](https://npm.io/package/fs-extra.md) ^7.0.1
- [klaw-sync](https://npm.io/package/klaw-sync.md) ^6.0.0

## Recent versions

- 0.3.0 (latest) — 2023-11-29
- 0.2.0 — 2021-02-28
- 0.1.0 — 2020-06-16
- 0.0.1 — 2019-01-20

## README

# rollup-plugin-static-files

[Rollup](https://rollupjs.org) plugin that copies over static files from the specified directories into the output directory.

It also modifies HTML files to override hash values with the hash values generated by Rollup.

## How to use

```npm install rollup-plugin-static-files```

```
let static_files = require('rollup-plugin-static-files');

module.exports = {
    ...
    plugins: [
        static_files({
            include: ['./public'],
            exclude: ['./public/userdata']
        })
    ]
}
```

## File Hashes

All HTML files are scanned for ```script``` and ```link``` tags. The ```src``` and ```href``` attributes are checked and if they match any emitted assets/chunks/entries, those attributes are replaced.

Your index file should refer to these files using their final names, generated by ```assetFileNames```/```entryFileNames```/```chunkFileNames```, with the exception of ```[hash]```. That should not be replaced.

**Example:**

```
    <!DOCTYPE html>
    <html>
    <head>
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <link rel="stylesheet" href="/styles.[hash].css" type="text/css">
    </head>
    <body>
        <div id="app"></div>
        <script src="/main.[hash].js"></script>
    </body>
    </html>

```

## Public Path

If a HTML file includes files that start with a subdirectory, but this subdirectory is only mentioned in the ```output.dir``` option and not in ```output.entryFileNames``` etc, then use this option to make the plugin aware that all outputs start with this subdirectory.

**Example:**

```
output: {
    dir: 'dist/client',
    entryFileNames: '[name].[hash].js'
}

<script src="/client/main.[hash].js"></script>
```

For the plugin: 

```
static_files({
    include: ['./public'],
    publicPath: '/client'
})
```

---
_Source: https://npm.io/package/rollup-plugin-static-files · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
