philnash / jekyll-gzip

Generate gzipped assets and files for your Jekyll site at build time
https://rubygems.org/gems/jekyll-gzip
MIT License
37 stars 8 forks source link

not compressing some files node_modules? #10

Open agowa opened 3 years ago

agowa commented 3 years ago

I'm also using the jekyll-node-module plugin and it appears that files copied by that plugin aren't compressed. Even though that plugin is executed first.

This plugin correctly generates the compressed files for everything except the files that are copied (e.g. /assets/webfonts). At least the svg and eot files in there should be compressed, but currently aren't. No such problem with the files that module places in /assets/js or /assets/css. Also if I place another svg file manually in that location e.g. /assets/webfonts/test.svg the gzip files are created correctly, but only for that one specific file. The files that the module copied there are still ignored.

When using --verbose I can also see that the copying happens before jekyll-gzip is invoked.

_config.yml:

plugins:
  - jekyll-node-module
  - jekyll-minifier
  - jekyll-brotli
  - jekyll-gzip

node_modules:
  assets:
    js: assets/js
    css: assets/css
  copy:
    - source: '@fortawesome/fontawesome-free/webfonts/'
      target: assets/webfonts
philnash commented 3 years ago

jekyll-gzip (and jekyll-brotli) both use the Jekyll site post_write hook and use the site object and the method each_static_file to compress all the static files generated by Jekyll. The jekyll-node-module plugin seems to copy across the static files, but they aren't added to the site object at all, so this plugin doesn't know about them.

The plugins do expose a compress_directory method that can be used to iterate over the files in a directory and compress them. This is used within the plugin to detect whether the jekyll-assets plugin is present and then register with that plugin's after_write hook to compress the results.

I imagine something similar could be done for jekyll-node-module. You might be able to do so within your own application, and I'd be happy to take pull requests to add the behaviour if it can be generalised.