rollup-plugin-static-files

0.3.0 • Public • Published

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'
})

Readme

Keywords

none

Package Sidebar

Install

npm i rollup-plugin-static-files

Weekly Downloads

985

Version

0.3.0

License

MIT

Unpacked Size

5.91 kB

Total Files

4

Last publish

Collaborators

  • pepsryuu