Socket
Book a DemoInstallSign in
Socket

rollup-plugin-static-files

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rollup-plugin-static-files

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

latest
npmnpm
Version
0.3.0
Version published
Maintainers
1
Created
Source

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

FAQs

Package last updated on 29 Nov 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts