rollup-plugin-static-files
v0.3.0
Published
Copies static files into output directory with support for hash replacement.
Downloads
3,348
Readme
rollup-plugin-static-files
Rollup 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'
})