magnars / optimus

A Ring middleware for frontend performance optimization.
364 stars 23 forks source link

Add support for globs as well as regexps for path matching #71

Closed augustl closed 4 years ago

augustl commented 4 years ago

This works fine on Windows, provided https://github.com/magnars/optimus/pull/70 is merged.

The original idea behind using vectors was that we can't hard code / as a path separator. But after https://github.com/magnars/optimus/pull/70/, we can. So ["foo" "*.js"] is compiled into glob:/foo/*.js and that works fine on both Windows and *nix.

So the vector syntax is not really needed anymore.

Maybe an alternative approach could be to parse plain strings as glob patterns, and hope people don't already have a literal file named "js/*.js"?

magnars commented 4 years ago

What would happen if we make people type out "glob:/foo/*.js" to use globbing?

augustl commented 4 years ago

Implementation wise that should be trivial. API design wise, I'm torn. A vector is cleaner than a stringly typed syntax thingie. But it's awfully convenient to use it.

We could add a fancy thing that supported symbols maybe..

(assets/load-bundles "public" 
                     {"lib.js" ["/scripts/ext/angular.js"
                                 :glob "/foo/*.js"
                                 "/scripts/ext/another-file-here.js"] })

Not stringly typet, but also kind of weird.

magnars commented 4 years ago

[:glob "/foo/*.js"] perhaps?

augustl commented 4 years ago

Seems like then ["foo" "*.js"] is just as good... No strong opinions here though.

Maybe we can support these:

And then normalize strings and regexps to their corresponding representation?

magnars commented 4 years ago

Yes, that's what I was thinking too. I would like to dispatch on something more explicit than vector?

augustl commented 4 years ago

Just force pushed an alternative version, based on the discussion so far. Thoughts?

magnars commented 4 years ago

Closing this after #70 introduced a better approach with normalising paths.