pcb icon indicating copy to clipboard operation
pcb copied to clipboard

Add ability to pass function as value inside of `excludes` array.

Open TheLarkInn opened this issue 8 years ago • 4 comments

Currently if you have a unique scenario where minimatch cannot find a complex or questionable path, there is no fallback for filtering assets that are allowed to go into the sw.js and appcache manifest.

With that in mind I'd like to propose a two part enhancement to offline-plugin.

Phase 1: [Partial Implementation]: Allow predicate function to be passed as a value inside of the used array.

This may look like excludes: [(asset) => /\.foo$/.test(asset), ..., ..., ...]

Phase 2: Implement the same condition matching system

Implement the same condition matching system for resource (path names) that webpack uses across all of its plugin values. (See RuleSet.js#normalizeConditions, applyMatchers).

You can learn about the condition matching system here

Conditions can be one of these:

A string: To match the input must start with the provided string. I. e. an absolute directory path, or absolute path to the file.
A RegExp: It's tested with the input.
A function: It's called with the input and must return a truthy value to match.
An array of Conditions: At least one of the Condition must match.
A object: All properties must match. Each property has a defined behavior.

TheLarkInn avatar Apr 15 '17 23:04 TheLarkInn

I think partial implementation somehow should go into v4, even though I planned to not really any version of it except for bug fixing. We have a problem of merging the same code into both v4 and v5.

Full implementation definitely goes to v5.

NekR avatar Apr 15 '17 23:04 NekR

Also, I'm not 100% sure about the "full implementation". It's a bit different in offline-plugin than webpack itself, so maybe we'll end up using just a simple wrapper for all matches which will be accepting glob/regexp/functions.

NekR avatar Apr 16 '17 12:04 NekR

Correct, I would think of the condition in this case as unique to the "exclude" property, where essentially a string (abs path), regex, function() {}, and I suppose if you wanted to make it recursive you could but maybe that is where the line is drawn.

TheLarkInn avatar Apr 16 '17 12:04 TheLarkInn

@TheLarkInn do you mind looking into this https://github.com/NekR/offline-plugin/pull/242? Seems like a thing related to this, so would be good to have a solution which fits both cases.

NekR avatar May 05 '17 18:05 NekR