mirror of
https://github.com/discourse/discourse.git
synced 2025-06-03 13:45:09 +08:00

We are no longer using any of the transpilation/bundling features of Sprockets. We only use it to serve assets in development, and then collect & fingerprint them in production. This commit switches us to use the more modern "Propshaft" gem for that functionality. Propshaft is much simpler than Sprockets. Instead of taking a combination of paths + "precompile" list, Propshaft simply assumes all files in the configured directory are required in production. Previously we had some base paths configured quite high in the directory structure, and then only precompiled selected assets within the directory. That's no longer possible, so this commit refactors those places (mostly plugin-related) to use dedicated directories under `app/assets/generated/`. Another difference is that Propshaft applies asset digests in development as well as production. This is great for caching & dev/prod consistency, but does mean some small changes were required in tests. We previously had some freedom-patches applied to Sprockets. Some of those had to be ported across to Propshaft. We now have three patches: 1. Skip adding digest hashes to webpack-generated chunks (which are already digested, and referred to from other js files) 2. Avoid raising errors for missing assets in test mode. We don't always compile assets before running basic RSpec tests. 3. Maintain relative paths for sourcemap URLs, so that files don't need to be recompiled depending on their CDN path Significant refactors are made to the `assets.rake` and `s3.rake` tasks, which rely on implementation details of Sprockets/Propshaft.