Skip to content

Detect compilation trigger instead of referencing emitted assets when determining whether to inject css or reload #78

@farmerau

Description

@farmerau

In lib/getCssOnlyEmittedAssetsNames.js, it's apparent that the logic regarding about whether or not to inject CSS is entirely related about the emitted files. This can work in situations where (S)CSS might not be included in JavaScript, or in situations where spritemaps or manifests aren't being generated.

Instead, determining whether or not we should inject CSS could be determined by checking the triggered source files to see if it's an injectable resource. This can be done in the watchRun compiler hook by setting a flag in the plugin to true or false depending on inspection of the keys in compiler.watchFileSystem.(watcher||wfs.watcher).

If there's interest in implementing this, I've written a webpack plugin which manipulates the values inside stats.compilation.assets. I don't think this is the ideal solution, so I haven't published or made it otherwise public in favor of my hope that we might be able to offer the functionality directly in this plugin. I'm happy to submit a pull-request if this is something people would like to see.

Ideally, there'd be an option to specify the source file extensions (probably via Regular Expressions) for testing against the triggering files.

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