Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use CSS and JS bundling for assets #413

Closed
wants to merge 18 commits into from

Conversation

pezholio
Copy link
Contributor

@pezholio pezholio commented Apr 28, 2022

Webpacker is now no longer in active development, so I've added support for cssbundling-rails with sass and jsbundling-rails with Rollup.js.

Now asset dependencies (css / js libraries etc) are all handled by Yarn, and the building of assets is handled by Yarn scripts, rather than magically happening via the asset pipeline. This keeps concerns nicely seperated and gives us much more control over how assets are processed and built.

There is also a bin/dev file which watches assets for changes via Foreman when the server is spun up.

This is draft until #412 is in.

pezholio added 18 commits April 28, 2022 10:39
This was left over from a previous upgrade
This is now an optional dependency
This adds the following:

- An app/assets/builds folder - This will contain built JS,
which will then be served via the asset pipeline
- Add app/javascript/application.js file - This is the entrypoint for
all frontend Javascript
- A bin/dev file - This should be how to run the application in development. It runs (and optionally installs) Foreman, to  run
the server and build Javsacript on the fly
- A Procfile.dev file - This tells Foreman what processes to run
when running the bin/dev script
- A rollup.config.js file - This tells Rollup how to build the Javascript in the application.js
This has required us to install Yarn in the base layer, so we can
run yarn in the main layer and watch the JS for changes
This allows us to support older browsers (down to and including
IE11)
This allows us to `import` separate JS components and have
them all run when the JS is invoked (i.e. on pageload)
As well as gems that we no longer use
Turbolinks is deprecated now, so let’s use [Turbo](https://github.com/hotwired/turbo) instead
This does the following:

- Installs the `sass` node library
- Adds a `build:css` command to build css via node
- Adds the `build:css` command to the Procfile
- Removes the `stylesheets` dir from manifest.js
@pezholio pezholio force-pushed the use-css-and-js-bundling-for-assets branch from 7a7f7e3 to e2f0967 Compare April 28, 2022 13:19
@tahb
Copy link
Contributor

tahb commented Jun 8, 2022

I don't have a strong opinion yet but I think we should talk about the choice of Rollup over importmaps, as I think it is a choice? As I understand it importmaps don't require npm or yarn which would reduce the complexity of working with more than one dependency managers. I don't understand it all yet but this sounds lovely and simple?

Seems like we can get packages like the govuk-frontend by using their "designed to be used with JavaScript CDNs for your npm package dependencies" with pinning.

@mec
Copy link
Contributor

mec commented Aug 23, 2024

Given this PRs age and that the required #412 has been closed, I am going to close this as well.

@mec mec closed this Aug 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants