Skip to content

Plugin does not support multiple livereload instances at once #76

@leumasme

Description

@leumasme

Rollup supports producing multiple bundles at once by exporting multiple configs in an array from the rollup config script, e.g.

import livereload from "rollup-plugin-livereload";

export default [{
{
        input: `modA/src/main.js`,
        output: {
            sourcemap: true,
            format: "iife",
            name: "app",
            file: `modA/public/build/bundle.js`
        },
        plugins: [
            livereload("modA/public"),
        ]
    }
},{
{
        input: `modB/src/main.js`,
        output: {
            sourcemap: true,
            format: "iife",
            name: "app",
            file: `modB/public/build/bundle.js`
        },
        plugins: [
            livereload("modB/public"),
        ]
    }
}]

Using this rollup feature however breaks this plugin. The livereload server is kept in a global state variable PLUGIN_LIVERELOAD

const state = (global.PLUGIN_LIVERELOAD = global.PLUGIN_LIVERELOAD || {
server: null,
})

If livereload is instantiated multiple times in the same rollup process, they clash and the variable will be overwritten.
When reloading the rollup config, this leads to multiple livereload instances trying to close the same server
if (state.server) {
state.server.close()
}

which results in a crash, as closing the same server multiple times is not supported by livereload

[!] TypeError: Cannot read properties of null (reading 'close')
    at Server.close (PROJECT\node_modules\livereload\lib\livereload.js:227:27)
    at livereload (PROJECT\node_modules\rollup-plugin-livereload\dist\index.cjs.js:104:18)
    at constructConfig (file:///PROJECT/rollup.config.mjs?1683999555521:92:28)
    at file:///PROJECT/rollup.config.mjs?1683999555521:109:5
    at ModuleJob.run (node:internal/modules/esm/module_job:194:25

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions