Browse Source

Switch to JSBundling with webpack (#392)

* Switch to JSBundling with webpack

* Set babel target attempt 1

* Fix loose babel warning

* Babel target attempt 2

* Babel target attempt 3

* Maybe we need to polyfill more than just promise...

* Fix promise undefined in IE11

* Target oldest browsers possible

* Set browserlist in package.json

* Development mode browserlist and update readme

* Mode flag

* Does setting es5 web target help?

* It doesn't

* Not using ActiveStorage

* Import all of corejs

* Destructuring including in present-env already

* Just import what we need

* Add polyfill for fetch

* Stimulus polyfills

* Remove unused duplicates

* We don't use channels

* Single babel config

* Stimulus working

* Add additional polyfills for Stimulus and Turbo

* Additional polyfill for Turbo

* Make sure we also transpile our own stimulus controller code

* Add plugin-transform-spread

* Defaults are fine for most babel plugins

* Plugin ordering

* Specify which bits exactly we want to transpile

* Transpiling turbo appears to break it

* Devise logout via get so we don't rely on js

* Override public path for IE11

* Need to make DOM event triggers explicit for IE11

* Update helper spec

* Update helper spec

* Bump dependencies
pull/401/head
baarkerlounger 3 years ago committed by GitHub
parent
commit
6f54c0c979
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      .browserslistrc
  2. 3
      .gitignore
  3. 6
      Gemfile
  4. 48
      Gemfile.lock
  5. 2
      Procfile.dev
  6. 22
      README.md
  7. 0
      app/assets/builds/.keep
  8. 1
      app/assets/config/manifest.js
  9. 2
      app/frontend/active_admin.js
  10. 21
      app/frontend/application.js
  11. 0
      app/frontend/controllers/accessible_autocomplete_controller.js
  12. 0
      app/frontend/controllers/application.js
  13. 0
      app/frontend/controllers/conditional_question_controller.js
  14. 0
      app/frontend/controllers/govukfrontend_controller.js
  15. 19
      app/frontend/controllers/index.js
  16. 0
      app/frontend/controllers/numeric_question_controller.js
  17. 0
      app/frontend/controllers/tasklist_controller.js
  18. 0
      app/frontend/styles/_accessible-autocomplete.scss
  19. 0
      app/frontend/styles/_button.scss
  20. 0
      app/frontend/styles/_figure.scss
  21. 0
      app/frontend/styles/_input.scss
  22. 0
      app/frontend/styles/_panel.scss
  23. 0
      app/frontend/styles/_related-navigation.scss
  24. 0
      app/frontend/styles/_section-skip-link.scss
  25. 0
      app/frontend/styles/_tab-navigation.scss
  26. 0
      app/frontend/styles/_table-group.scss
  27. 0
      app/frontend/styles/_task-list.scss
  28. 0
      app/frontend/styles/_template.scss
  29. 4
      app/frontend/styles/active_admin.scss
  30. 0
      app/frontend/styles/application.scss
  31. 4
      app/helpers/question_attribute_helper.rb
  32. 20
      app/views/layouts/application.html.erb
  33. 6
      app/webpacker/channels/consumer.js
  34. 5
      app/webpacker/channels/index.js
  35. 9
      app/webpacker/controllers/index.js
  36. 15
      app/webpacker/packs/application.js
  37. 34
      babel.config.js
  38. 9
      bin/dev
  39. 18
      bin/webpack
  40. 18
      bin/webpack-dev-server
  41. 9
      config/initializers/active_admin.rb
  42. 2
      config/initializers/devise.rb
  43. 2
      config/routes.rb
  44. 5
      config/webpack/development.js
  45. 5
      config/webpack/environment.js
  46. 7
      config/webpack/plugins/jquery.js
  47. 5
      config/webpack/production.js
  48. 5
      config/webpack/staging.js
  49. 5
      config/webpack/test.js
  50. 102
      config/webpacker.yml
  51. 49
      package.json
  52. 4
      spec/helpers/question_attribute_helper_spec.rb
  53. 70
      webpack.config.js
  54. 5694
      yarn.lock

1
.browserslistrc

@ -1 +0,0 @@
defaults

3
.gitignore vendored

@ -46,3 +46,6 @@ yarn-debug.log*
.DS_Store .DS_Store
.generators .generators
.rakeTasks .rakeTasks
/app/assets/builds/*
!/app/assets/builds/.keep

6
Gemfile

@ -11,8 +11,10 @@ gem "rails", "~> 7.0.2"
gem "pg", "~> 1.1" gem "pg", "~> 1.1"
# Use Puma as the app server # Use Puma as the app server
gem "puma", "~> 5.0" gem "puma", "~> 5.0"
# Transpile app-like JavaScript. Read more: https://github.com/rails/webpacker # The modern asset pipeline for Rails [https://github.com/rails/propshaft]
gem "webpacker", "~> 5.0" gem "propshaft"
# Bundle and transpile JavaScript [https://github.com/rails/propshaft/]
gem "jsbundling-rails"
# Reduces boot times through caching; required in config/boot.rb # Reduces boot times through caching; required in config/boot.rb
gem "bootsnap", ">= 1.4.4", require: false gem "bootsnap", ">= 1.4.4", require: false
# GOV UK frontend components # GOV UK frontend components

48
Gemfile.lock

@ -105,8 +105,8 @@ GEM
ruby2_keywords (>= 0.0.2, < 1.0) ruby2_keywords (>= 0.0.2, < 1.0)
ast (2.4.2) ast (2.4.2)
aws-eventstream (1.2.0) aws-eventstream (1.2.0)
aws-partitions (1.566.0) aws-partitions (1.568.0)
aws-sdk-core (3.129.1) aws-sdk-core (3.130.0)
aws-eventstream (~> 1, >= 1.0.2) aws-eventstream (~> 1, >= 1.0.2)
aws-partitions (~> 1, >= 1.525.0) aws-partitions (~> 1, >= 1.525.0)
aws-sigv4 (~> 1.1) aws-sigv4 (~> 1.1)
@ -120,7 +120,7 @@ GEM
aws-sigv4 (~> 1.4) aws-sigv4 (~> 1.4)
aws-sigv4 (1.4.0) aws-sigv4 (1.4.0)
aws-eventstream (~> 1, >= 1.0.2) aws-eventstream (~> 1, >= 1.0.2)
bcrypt (3.1.16) bcrypt (3.1.17)
bindex (0.8.1) bindex (0.8.1)
bootsnap (1.11.1) bootsnap (1.11.1)
msgpack (~> 1.2) msgpack (~> 1.2)
@ -138,7 +138,7 @@ GEM
rack-test (>= 0.6.3) rack-test (>= 0.6.3)
regexp_parser (>= 1.5, < 3.0) regexp_parser (>= 1.5, < 3.0)
xpath (~> 3.2) xpath (~> 3.2)
capybara-lockstep (1.1.0) capybara-lockstep (1.1.1)
activesupport (>= 3.2) activesupport (>= 3.2)
capybara (>= 2.0) capybara (>= 2.0)
ruby2_keywords ruby2_keywords
@ -160,8 +160,8 @@ GEM
railties (>= 3.2) railties (>= 3.2)
encryptor (3.0.0) encryptor (3.0.0)
erubi (1.10.0) erubi (1.10.0)
excon (0.91.0) excon (0.92.1)
factory_bot (6.2.0) factory_bot (6.2.1)
activesupport (>= 5.0.0) activesupport (>= 5.0.0)
factory_bot_rails (6.2.0) factory_bot_rails (6.2.0)
factory_bot (~> 6.2.0) factory_bot (~> 6.2.0)
@ -206,6 +206,8 @@ GEM
rails-dom-testing (>= 1, < 3) rails-dom-testing (>= 1, < 3)
railties (>= 4.2.0) railties (>= 4.2.0)
thor (>= 0.14, < 2.0) thor (>= 0.14, < 2.0)
jsbundling-rails (1.0.2)
railties (>= 6.0.0)
json-schema (2.8.1) json-schema (2.8.1)
addressable (>= 2.4) addressable (>= 2.4)
jwt (2.3.0) jwt (2.3.0)
@ -224,7 +226,7 @@ GEM
listen (3.7.1) listen (3.7.1)
rb-fsevent (~> 0.10, >= 0.10.3) rb-fsevent (~> 0.10, >= 0.10.3)
rb-inotify (~> 0.9, >= 0.9.10) rb-inotify (~> 0.9, >= 0.9.10)
loofah (2.14.0) loofah (2.15.0)
crass (~> 1.0.2) crass (~> 1.0.2)
nokogiri (>= 1.5.9) nokogiri (>= 1.5.9)
mail (2.7.1) mail (2.7.1)
@ -264,18 +266,23 @@ GEM
childprocess (>= 0.6.3, < 5) childprocess (>= 0.6.3, < 5)
iniparse (~> 1.4) iniparse (~> 1.4)
rexml (~> 3.2) rexml (~> 3.2)
paper_trail (12.2.0) paper_trail (12.3.0)
activerecord (>= 5.2) activerecord (>= 5.2)
request_store (~> 1.1) request_store (~> 1.1)
paper_trail-globalid (0.2.0) paper_trail-globalid (0.2.0)
globalid globalid
paper_trail (>= 3.0.0) paper_trail (>= 3.0.0)
parallel (1.21.0) parallel (1.22.0)
parser (3.1.1.0) parser (3.1.1.0)
ast (~> 2.4.1) ast (~> 2.4.1)
pg (1.3.4) pg (1.3.4)
postcodes_io (0.4.0) postcodes_io (0.4.0)
excon (~> 0.39) excon (~> 0.39)
propshaft (0.6.4)
actionpack (>= 7.0.0)
activesupport (>= 7.0.0)
rack
railties (>= 7.0.0)
pry (0.13.1) pry (0.13.1)
coderay (~> 1.1) coderay (~> 1.1)
method_source (~> 1.0) method_source (~> 1.0)
@ -291,8 +298,6 @@ GEM
rack (>= 1.0, < 3) rack (>= 1.0, < 3)
rack-mini-profiler (2.3.4) rack-mini-profiler (2.3.4)
rack (>= 1.2.0) rack (>= 1.2.0)
rack-proxy (0.7.2)
rack
rack-test (1.1.0) rack-test (1.1.0)
rack (>= 1.0, < 3) rack (>= 1.0, < 3)
rails (7.0.2.3) rails (7.0.2.3)
@ -340,7 +345,7 @@ GEM
actionpack (>= 5.0) actionpack (>= 5.0)
railties (>= 5.0) railties (>= 5.0)
rexml (3.2.5) rexml (3.2.5)
roo (2.8.3) roo (2.9.0)
nokogiri (~> 1) nokogiri (~> 1)
rubyzip (>= 1.3.0, < 3.0.0) rubyzip (>= 1.3.0, < 3.0.0)
rotp (6.2.0) rotp (6.2.0)
@ -405,14 +410,13 @@ GEM
childprocess (>= 0.5, < 5.0) childprocess (>= 0.5, < 5.0)
rexml (~> 3.2, >= 3.2.5) rexml (~> 3.2, >= 3.2.5)
rubyzip (>= 1.2.2) rubyzip (>= 1.2.2)
semantic_range (3.0.0) sentry-rails (5.2.1)
sentry-rails (5.2.0)
railties (>= 5.0) railties (>= 5.0)
sentry-ruby-core (~> 5.2.0) sentry-ruby-core (~> 5.2.1)
sentry-ruby (5.2.0) sentry-ruby (5.2.1)
concurrent-ruby (~> 1.0, >= 1.0.2) concurrent-ruby (~> 1.0, >= 1.0.2)
sentry-ruby-core (= 5.2.0) sentry-ruby-core (= 5.2.1)
sentry-ruby-core (5.2.0) sentry-ruby-core (5.2.1)
concurrent-ruby concurrent-ruby
simplecov (0.21.2) simplecov (0.21.2)
docile (~> 1.1) docile (~> 1.1)
@ -447,11 +451,6 @@ GEM
addressable (>= 2.8.0) addressable (>= 2.8.0)
crack (>= 0.3.2) crack (>= 0.3.2)
hashdiff (>= 0.4.0, < 2.0.0) hashdiff (>= 0.4.0, < 2.0.0)
webpacker (5.4.3)
activesupport (>= 5.2)
rack-proxy (>= 0.6.1)
railties (>= 5.2)
semantic_range (>= 2.3.0)
websocket-driver (0.7.5) websocket-driver (0.7.5)
websocket-extensions (>= 0.1.0) websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.5) websocket-extensions (0.1.5)
@ -482,6 +481,7 @@ DEPENDENCIES
govuk_design_system_formbuilder govuk_design_system_formbuilder
govuk_markdown govuk_markdown
hotwire-rails hotwire-rails
jsbundling-rails
json-schema json-schema
listen (~> 3.3) listen (~> 3.3)
notifications-ruby-client notifications-ruby-client
@ -490,6 +490,7 @@ DEPENDENCIES
paper_trail-globalid paper_trail-globalid
pg (~> 1.1) pg (~> 1.1)
postcodes_io postcodes_io
propshaft
pry-byebug pry-byebug
puma (~> 5.0) puma (~> 5.0)
rack-attack rack-attack
@ -513,7 +514,6 @@ DEPENDENCIES
view_component view_component
web-console (>= 4.1.0) web-console (>= 4.1.0)
webmock webmock
webpacker (~> 5.0)
RUBY VERSION RUBY VERSION
ruby 3.1.1p18 ruby 3.1.1p18

2
Procfile.dev

@ -0,0 +1,2 @@
web: bin/rails server -p 3000
js: yarn build --watch

22
README.md

@ -37,11 +37,29 @@ Pre-requisites:
6. Install the frontend depenencies:\ 6. Install the frontend depenencies:\
`yarn install` `yarn install`
7. Start the Rails server:\ 7. Start the dev servers using foreman:\
`bundle exec rails s` `./bin/dev`
Or start them individually:\
a. Rails:\
`bundle exec rails s`
b. JS (for hot reloading):\
`yarn build --mode=development --watch`
If you're not modifying front end assets you can bundle them as a one off task:\
`yarn build --mode=development`
Development mode will target the latest versions of Chrome, Firefox and Safari for transpilation while
production mode will target older browsers.
The Rails server will start on <http://localhost:3000>. The Rails server will start on <http://localhost:3000>.
Running the test suite (front end assets need to be built or server needs to be running):\
`bundle exec rspec`
### Using Docker ### Using Docker
1. Build the image:\ 1. Build the image:\

0
app/assets/builds/.keep

1
app/assets/config/manifest.js

@ -0,0 +1 @@
//= link_tree ../builds

2
app/webpacker/packs/active_admin.js → app/frontend/active_admin.js

@ -1,6 +1,6 @@
// Load Active Admin's styles into Webpacker, // Load Active Admin's styles into Webpacker,
// see `active_admin.scss` for customization. // see `active_admin.scss` for customization.
import "../styles/active_admin"; import "./styles/active_admin.scss";
import "@activeadmin/activeadmin"; import "@activeadmin/activeadmin";

21
app/frontend/application.js

@ -0,0 +1,21 @@
// This file is automatically compiled by Webpack, along with any other files
// present in this directory. You're encouraged to place your actual application logic in
// a relevant structure within app/javascript and only use these pack files to reference
// that code so it'll be compiled.
// Polyfills for IE
import "@webcomponents/webcomponentsjs"
import "core-js/stable"
import "regenerator-runtime/runtime"
import "@stimulus/polyfills"
import "custom-event-polyfill"
import "intersection-observer"
//
require.context("govuk-frontend/govuk/assets")
import { initAll } from "govuk-frontend"
import "./styles/application.scss"
import "./controllers"
import "@hotwired/turbo-rails"
initAll()

0
app/webpacker/controllers/accessible_autocomplete_controller.js → app/frontend/controllers/accessible_autocomplete_controller.js

0
app/webpacker/controllers/application.js → app/frontend/controllers/application.js

0
app/webpacker/controllers/conditional_question_controller.js → app/frontend/controllers/conditional_question_controller.js

0
app/webpacker/controllers/govukfrontend_controller.js → app/frontend/controllers/govukfrontend_controller.js

19
app/frontend/controllers/index.js

@ -0,0 +1,19 @@
// Load all the controllers within this directory and all subdirectories.
// Controller files must be named *_controller.js.
import { application } from "./application"
import AccessibleAutocompleteController from "./accessible_autocomplete_controller.js"
application.register("accessible-autocomplete", AccessibleAutocompleteController)
import ConditionalQuestionController from "./conditional_question_controller.js"
application.register("conditional-question", ConditionalQuestionController)
import GovukfrontendController from "./govukfrontend_controller.js"
application.register("govukfrontend", GovukfrontendController)
import NumericQuestionController from "./numeric_question_controller.js"
application.register("numeric-question", NumericQuestionController)
import TasklistController from "./tasklist_controller.js"
application.register("tasklist", TasklistController)

0
app/webpacker/controllers/numeric_question_controller.js → app/frontend/controllers/numeric_question_controller.js

0
app/webpacker/controllers/tasklist_controller.js → app/frontend/controllers/tasklist_controller.js

0
app/webpacker/styles/_accessible-autocomplete.scss → app/frontend/styles/_accessible-autocomplete.scss

0
app/webpacker/styles/_button.scss → app/frontend/styles/_button.scss

0
app/webpacker/styles/_figure.scss → app/frontend/styles/_figure.scss

0
app/webpacker/styles/_input.scss → app/frontend/styles/_input.scss

0
app/webpacker/styles/_panel.scss → app/frontend/styles/_panel.scss

0
app/webpacker/styles/_related-navigation.scss → app/frontend/styles/_related-navigation.scss

0
app/webpacker/styles/_section-skip-link.scss → app/frontend/styles/_section-skip-link.scss

0
app/webpacker/styles/_tab-navigation.scss → app/frontend/styles/_tab-navigation.scss

0
app/webpacker/styles/_table-group.scss → app/frontend/styles/_table-group.scss

0
app/webpacker/styles/_task-list.scss → app/frontend/styles/_task-list.scss

0
app/webpacker/styles/_template.scss → app/frontend/styles/_template.scss

4
app/webpacker/styles/active_admin.scss → app/frontend/styles/active_admin.scss

@ -8,8 +8,8 @@
// $sidebar-width: 242px; // $sidebar-width: 242px;
// Active Admin's got SASS! // Active Admin's got SASS!
@import "~@activeadmin/activeadmin/src/scss/mixins"; @import "@activeadmin/activeadmin/src/scss/mixins";
@import "~@activeadmin/activeadmin/src/scss/base"; @import "@activeadmin/activeadmin/src/scss/base";
// Overriding any non-variable Sass must be done after the fact. // Overriding any non-variable Sass must be done after the fact.
// For example, to change the default status-tag color: // For example, to change the default status-tag color:

0
app/webpacker/styles/application.scss → app/frontend/styles/application.scss

4
app/helpers/question_attribute_helper.rb

@ -15,7 +15,7 @@ private
{ {
"data-controller": "numeric-question", "data-controller": "numeric-question",
"data-action": "numeric-question#calculateFields", "data-action": "input->numeric-question#calculateFields",
"data-target": "case-log-#{question.result_field.to_s.dasherize}-field", "data-target": "case-log-#{question.result_field.to_s.dasherize}-field",
"data-calculated": question.fields_to_add.to_json, "data-calculated": question.fields_to_add.to_json,
} }
@ -26,7 +26,7 @@ private
{ {
"data-controller": "conditional-question", "data-controller": "conditional-question",
"data-action": "conditional-question#displayConditional", "data-action": "click->conditional-question#displayConditional",
"data-info": question.conditional_for.to_json, "data-info": question.conditional_for.to_json,
} }
end end

20
app/views/layouts/application.html.erb

@ -5,16 +5,16 @@
<%= csrf_meta_tags %> <%= csrf_meta_tags %>
<%= csp_meta_tag %> <%= csp_meta_tag %>
<%= tag :meta, name: 'viewport', content: 'width=device-width, initial-scale=1' %> <%= tag :meta, name: 'viewport', content: 'width=device-width, initial-scale=1' %>
<%= tag :meta, property: 'og:image', content: asset_pack_path('media/images/govuk-opengraph-image.png') %> <%= tag :meta, property: 'og:image', content: asset_path('images/govuk-opengraph-image.png') %>
<%= tag :meta, name: 'theme-color', content: '#0b0c0c' %> <%= tag :meta, name: 'theme-color', content: '#0b0c0c' %>
<%= favicon_link_tag asset_pack_path('media/images/favicon.ico') %> <%= favicon_link_tag asset_path('images/favicon.ico') %>
<%= favicon_link_tag asset_pack_path('media/images/govuk-mask-icon.svg'), rel: 'mask-icon', type: 'image/svg', color: "#0b0c0c" %> <%= favicon_link_tag asset_path('images/govuk-mask-icon.svg'), rel: 'mask-icon', type: 'image/svg', color: "#0b0c0c" %>
<%= favicon_link_tag asset_pack_path('media/images/govuk-apple-touch-icon.png'), rel: 'apple-touch-icon', type: 'image/png' %> <%= favicon_link_tag asset_path('images/govuk-apple-touch-icon.png'), rel: 'apple-touch-icon', type: 'image/png' %>
<%= favicon_link_tag asset_pack_path('media/images/govuk-apple-touch-icon-152x152.png'), rel: 'apple-touch-icon', type: 'image/png', size: '152x152' %> <%= favicon_link_tag asset_path('images/govuk-apple-touch-icon-152x152.png'), rel: 'apple-touch-icon', type: 'image/png', size: '152x152' %>
<%= favicon_link_tag asset_pack_path('media/images/govuk-apple-touch-icon-167x167.png'), rel: 'apple-touch-icon', type: 'image/png', size: '167x167' %> <%= favicon_link_tag asset_path('images/govuk-apple-touch-icon-167x167.png'), rel: 'apple-touch-icon', type: 'image/png', size: '167x167' %>
<%= favicon_link_tag asset_pack_path('media/images/govuk-apple-touch-icon-180x180.png'), rel: 'apple-touch-icon', type: 'image/png', size: '180x180' %> <%= favicon_link_tag asset_path('images/govuk-apple-touch-icon-180x180.png'), rel: 'apple-touch-icon', type: 'image/png', size: '180x180' %>
<%= stylesheet_pack_tag 'application', media: 'all' %> <%= stylesheet_link_tag "application", "data-turbo-track": "reload" %>
<%= javascript_pack_tag 'application', defer: true %> <%= javascript_include_tag "application", "data-turbo-track": "reload", defer: true %>
<% if content_for?(:head) %> <% if content_for?(:head) %>
<%= yield(:head) %> <%= yield(:head) %>
@ -46,7 +46,7 @@
component.navigation_item(text: 'Logs', href: case_logs_path) component.navigation_item(text: 'Logs', href: case_logs_path)
component.navigation_item(text: 'Your organisation', href: "/organisations/#{current_user.organisation.id}") component.navigation_item(text: 'Your organisation', href: "/organisations/#{current_user.organisation.id}")
component.navigation_item(text: 'Your account', href: user_path(current_user)) component.navigation_item(text: 'Your account', href: user_path(current_user))
component.navigation_item(text: 'Sign out', href: destroy_user_session_path, options: { data: {turbo_method: :delete}, method: :delete }) component.navigation_item(text: 'Sign out', href: destroy_user_session_path)
end end
end end
%> %>

6
app/webpacker/channels/consumer.js

@ -1,6 +0,0 @@
// Action Cable provides the framework to deal with WebSockets in Rails.
// You can generate new channels where WebSocket features live using the `bin/rails generate channel` command.
import { createConsumer } from "@rails/actioncable"
export default createConsumer()

5
app/webpacker/channels/index.js

@ -1,5 +0,0 @@
// Load all the channels within this directory and all subdirectories.
// Channel files must be named *_channel.js.
const channels = require.context('.', true, /_channel\.js$/)
channels.keys().forEach(channels)

9
app/webpacker/controllers/index.js

@ -1,9 +0,0 @@
// Load all the controllers within this directory and all subdirectories.
// Controller files must be named *_controller.js.
import { Application } from "@hotwired/stimulus"
import { definitionsFromContext } from "@hotwired/stimulus-webpack-helpers"
const application = Application.start()
const context = require.context("controllers", true, /_controller\.js$/)
application.load(definitionsFromContext(context))

15
app/webpacker/packs/application.js

@ -1,15 +0,0 @@
// This file is automatically compiled by Webpack, along with any other files
// present in this directory. You're encouraged to place your actual application logic in
// a relevant structure within app/javascript and only use these pack files to reference
// that code so it'll be compiled.
require.context('govuk-frontend/govuk/assets')
import '../styles/application.scss'
import * as ActiveStorage from "@rails/activestorage"
import "channels"
import "controllers"
import "@hotwired/turbo-rails"
import { initAll } from 'govuk-frontend'
ActiveStorage.start()
initAll()

34
babel.config.js

@ -18,12 +18,7 @@ module.exports = function(api) {
return { return {
presets: [ presets: [
isTestEnv && [ isTestEnv && [
'@babel/preset-env', '@babel/preset-env'
{
targets: {
node: 'current'
}
}
], ],
(isProductionEnv || isDevelopmentEnv) && [ (isProductionEnv || isDevelopmentEnv) && [
'@babel/preset-env', '@babel/preset-env',
@ -40,30 +35,17 @@ module.exports = function(api) {
'babel-plugin-macros', 'babel-plugin-macros',
'@babel/plugin-syntax-dynamic-import', '@babel/plugin-syntax-dynamic-import',
isTestEnv && 'babel-plugin-dynamic-import-node', isTestEnv && 'babel-plugin-dynamic-import-node',
'@babel/plugin-transform-destructuring', '@babel/plugin-proposal-class-properties',
'@babel/plugin-proposal-object-rest-spread',
'@babel/plugin-proposal-private-methods',
'@babel/plugin-proposal-private-property-in-object',
'@babel/plugin-transform-regenerator',
'@babel/plugin-transform-runtime',
[ [
'@babel/plugin-proposal-class-properties', '@babel/plugin-transform-spread',
{ {
loose: true loose: true
} }
],
[
'@babel/plugin-proposal-object-rest-spread',
{
useBuiltIns: true
}
],
[
'@babel/plugin-transform-runtime',
{
helpers: false
}
],
[
'@babel/plugin-transform-regenerator',
{
async: false
}
] ]
].filter(Boolean) ].filter(Boolean)
} }

9
bin/dev

@ -0,0 +1,9 @@
#!/usr/bin/env bash
if ! command -v foreman &> /dev/null
then
echo "Installing foreman..."
gem install foreman
fi
foreman start -f Procfile.dev "$@"

18
bin/webpack

@ -1,18 +0,0 @@
#!/usr/bin/env ruby
ENV["RAILS_ENV"] ||= ENV["RACK_ENV"] || "development"
ENV["NODE_ENV"] ||= "development"
require "pathname"
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
Pathname.new(__FILE__).realpath)
require "bundler/setup"
require "webpacker"
require "webpacker/webpack_runner"
APP_ROOT = File.expand_path("..", __dir__)
Dir.chdir(APP_ROOT) do
Webpacker::WebpackRunner.run(ARGV)
end

18
bin/webpack-dev-server

@ -1,18 +0,0 @@
#!/usr/bin/env ruby
ENV["RAILS_ENV"] ||= ENV["RACK_ENV"] || "development"
ENV["NODE_ENV"] ||= "development"
require "pathname"
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
Pathname.new(__FILE__).realpath)
require "bundler/setup"
require "webpacker"
require "webpacker/dev_server_runner"
APP_ROOT = File.expand_path("..", __dir__)
Dir.chdir(APP_ROOT) do
Webpacker::DevServerRunner.run(ARGV)
end

9
config/initializers/active_admin.rb

@ -331,14 +331,7 @@ ActiveAdmin.setup do |config|
# By default, Active Admin uses Sprocket's asset pipeline. # By default, Active Admin uses Sprocket's asset pipeline.
# You can switch to using Webpacker here. # You can switch to using Webpacker here.
# #
config.use_webpacker = true # config.use_webpacker = true
end
# Print stylesheet is no longer a separate stylesheet in upstream so we can
# delete this when the next version bump is released but for now it prevents
# webpacker issues.
Rails.application.config.after_initialize do
ActiveAdmin.application.stylesheets.delete("active_admin/print.css")
end end
Rails.application.config.after_initialize do Rails.application.config.after_initialize do

2
config/initializers/devise.rb

@ -267,7 +267,7 @@ Devise.setup do |config|
# config.navigational_formats = ['*/*', :html] # config.navigational_formats = ['*/*', :html]
# The default HTTP method used to sign out a resource. Default is :delete. # The default HTTP method used to sign out a resource. Default is :delete.
config.sign_out_via = :delete config.sign_out_via = :get
# ==> OmniAuth # ==> OmniAuth
# Add a new OmniAuth provider. Check the wiki for more information on setting # Add a new OmniAuth provider. Check the wiki for more information on setting

2
config/routes.rb

@ -11,7 +11,7 @@ Rails.application.routes.draw do
two_factor_authentication: "auth/two_factor_authentication", two_factor_authentication: "auth/two_factor_authentication",
}, },
path_names: { sign_in: "sign-in", sign_out: "sign-out", two_factor_authentication: "two-factor-authentication" }, path_names: { sign_in: "sign-in", sign_out: "sign-out", two_factor_authentication: "two-factor-authentication" },
sign_out_via: %i[delete get], sign_out_via: %i[get],
} }
devise_scope :admin_user do devise_scope :admin_user do

5
config/webpack/development.js

@ -1,5 +0,0 @@
process.env.NODE_ENV = process.env.NODE_ENV || 'development'
const environment = require('./environment')
module.exports = environment.toWebpackConfig()

5
config/webpack/environment.js

@ -1,5 +0,0 @@
const { environment } = require('@rails/webpacker')
const jquery = require('./plugins/jquery')
environment.plugins.prepend('jquery', jquery)
module.exports = environment

7
config/webpack/plugins/jquery.js vendored

@ -1,7 +0,0 @@
const webpack = require('webpack')
module.exports = new webpack.ProvidePlugin({
"$":"jquery",
"jQuery":"jquery",
"window.jQuery":"jquery"
});

5
config/webpack/production.js

@ -1,5 +0,0 @@
process.env.NODE_ENV = process.env.NODE_ENV || 'production'
const environment = require('./environment')
module.exports = environment.toWebpackConfig()

5
config/webpack/staging.js

@ -1,5 +0,0 @@
process.env.NODE_ENV = process.env.NODE_ENV || 'staging'
const environment = require('./environment')
module.exports = environment.toWebpackConfig()

5
config/webpack/test.js

@ -1,5 +0,0 @@
process.env.NODE_ENV = process.env.NODE_ENV || 'development'
const environment = require('./environment')
module.exports = environment.toWebpackConfig()

102
config/webpacker.yml

@ -1,102 +0,0 @@
# Note: You must restart bin/webpack-dev-server for changes to take effect
default: &default
source_path: app/webpacker
source_entry_path: packs
public_root_path: public
public_output_path: packs
cache_path: tmp/cache/webpacker
webpack_compile_output: true
# Additional paths webpack should lookup modules
# ['app/assets', 'engine/foo/app/assets']
additional_paths: ['node_modules/govuk-frontend/govuk']
# Cache manifest.json for performance
cache_manifest: true
# Extract and emit a css file
extract_css: true
# Production depends on precompilation of packs prior to booting for performance.
compile: false
static_assets_extensions:
- .jpg
- .jpeg
- .png
- .gif
- .tiff
- .ico
- .svg
- .eot
- .otf
- .ttf
- .woff
- .woff2
extensions:
- .mjs
- .js
- .sass
- .scss
- .css
- .module.sass
- .module.scss
- .module.css
- .png
- .svg
- .gif
- .jpeg
- .jpg
development:
<<: *default
compile: true
# Reload manifest.json on all requests so we reload latest compiled packs
cache_manifest: false
# Extract and emit a css file
extract_css: false
# Reference: https://webpack.js.org/configuration/dev-server/
dev_server:
https: false
host: localhost
port: 3035
public: localhost:3035
hmr: false
# Inline should be set to true if using HMR
inline: false
overlay: true
compress: true
disable_host_check: true
use_local_ip: false
quiet: false
pretty: false
headers:
'Access-Control-Allow-Origin': '*'
watch_options:
ignored: '**/node_modules/**'
test:
<<: *default
compile: true
# Reload manifest.json on all requests so we reload latest compiled packs
cache_manifest: false
# Extract and emit a css file
extract_css: false
# Compile test packs to a separate directory
public_output_path: packs-test
staging:
<<: *default
production:
<<: *default

49
package.json

@ -5,28 +5,51 @@
"node": "^16.0.0" "node": "^16.0.0"
}, },
"dependencies": { "dependencies": {
"@activeadmin/activeadmin": "^2.9.0", "@activeadmin/activeadmin": "^2.11.0",
"@babel/core": "^7.17.7",
"@babel/plugin-transform-runtime": "^7.17.0",
"@babel/preset-env": "^7.16.11",
"@hotwired/stimulus": "^3.0.0", "@hotwired/stimulus": "^3.0.0",
"@hotwired/stimulus-webpack-helpers": "^1.0.1",
"@hotwired/turbo": "^7.1.0", "@hotwired/turbo": "^7.1.0",
"@hotwired/turbo-rails": "^7.1.0", "@hotwired/turbo-rails": "^7.1.0",
"@rails/actioncable": "^6.0.0", "@stimulus/polyfills": "^2.0.0",
"@rails/activestorage": "^6.0.0", "@webcomponents/webcomponentsjs": "^2.6.0",
"@rails/webpacker": "5.4.3",
"accessible-autocomplete": "^2.0.3", "accessible-autocomplete": "^2.0.3",
"babel-loader": "^8.2.3",
"babel-plugin-macros": "^3.1.0",
"chart.js": "^3.6.0", "chart.js": "^3.6.0",
"chartkick": "^4.1.0", "chartkick": "^4.1.0",
"copy-webpack-plugin": "^10.2.4",
"core-js": "^3.21.1",
"css-loader": "^6.7.1",
"custom-event-polyfill": "^1.0.7",
"file-loader": "^6.2.0",
"govuk-frontend": "^4.0.1", "govuk-frontend": "^4.0.1",
"stimulus": "^3.0.0", "intersection-observer": "^0.12.0",
"webpack": "^4.46.0", "mini-css-extract-plugin": "^2.6.0",
"webpack-cli": "^4.9.2" "regenerator-runtime": "^0.13.9",
"sass": "^1.49.9",
"sass-loader": "^12.6.0",
"unfetch": "^4.2.0",
"webpack": "^5.70.0",
"webpack-cli": "^4.9.2",
"webpack-remove-empty-scripts": "^0.7.3"
}, },
"version": "0.1.0", "version": "0.1.0",
"devDependencies": { "devDependencies": {},
"webpack-dev-server": "^4.7.4" "browserslist": {
"production": [
"last 1 version",
"> 1%",
"IE 10"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}, },
"resolutions": { "scripts": {
"glob-parent": "^6.0.2", "build": "webpack --config webpack.config.js"
"nth-check": "^2.0.1"
} }
} }

4
spec/helpers/question_attribute_helper_spec.rb

@ -15,7 +15,7 @@ RSpec.describe QuestionAttributeHelper do
brent = questions.find { |q| q.id == "brent" } brent = questions.find { |q| q.id == "brent" }
expect(stimulus_html_attributes(brent)).to eq({ expect(stimulus_html_attributes(brent)).to eq({
"data-controller": "numeric-question", "data-controller": "numeric-question",
"data-action": "numeric-question#calculateFields", "data-action": "input->numeric-question#calculateFields",
"data-target": "case-log-#{brent.result_field.to_s.dasherize}-field", "data-target": "case-log-#{brent.result_field.to_s.dasherize}-field",
"data-calculated": brent.fields_to_add.to_json, "data-calculated": brent.fields_to_add.to_json,
}) })
@ -40,7 +40,7 @@ RSpec.describe QuestionAttributeHelper do
let(:expected_attribs) do let(:expected_attribs) do
{ {
"data-controller": "numeric-question conditional-question", "data-controller": "numeric-question conditional-question",
"data-action": "numeric-question#calculateFields conditional-question#displayConditional", "data-action": "input->numeric-question#calculateFields click->conditional-question#displayConditional",
"data-target": "case-log-#{question.result_field.to_s.dasherize}-field", "data-target": "case-log-#{question.result_field.to_s.dasherize}-field",
"data-calculated": question.fields_to_add.to_json, "data-calculated": question.fields_to_add.to_json,
"data-info": question.conditional_for.to_json, "data-info": question.conditional_for.to_json,

70
webpack.config.js

@ -0,0 +1,70 @@
const path = require("path")
const webpack = require("webpack")
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const RemoveEmptyScriptsPlugin = require('webpack-remove-empty-scripts')
const CopyPlugin = require("copy-webpack-plugin");
const mode = process.env.NODE_ENV === 'development' ? 'development' : 'production'
module.exports = {
mode,
devtool: "source-map",
entry: {
application: [
"./app/frontend/application.js",
],
active_admin: [
'./app/frontend/active_admin.js',
'./app/frontend/styles/active_admin.scss'
]
},
module: {
rules: [
{
test: /\.(js|ts)$/,
include: [
path.resolve(__dirname, 'node_modules/@hotwired/stimulus'),
path.resolve(__dirname, 'node_modules/@rails/actioncable'),
path.resolve(__dirname, 'app/frontend/controllers'),
],
use: ['babel-loader'],
},
{
test: /\.(png|jpe?g|gif|eot|woff2|woff|ttf|svg|ico)$/i,
use: 'file-loader',
},
{
test: /\.(scss|css)/i,
use: [MiniCssExtractPlugin.loader, 'css-loader', 'sass-loader'],
}
],
},
resolve: {
modules: ['node_modules', 'node_modules/govuk-frontend/govuk']
},
output: {
filename: "[name].js",
// we must set publicPath to an empty value to override the default of
// auto which doesn't work in IE11
publicPath: '',
path: path.resolve(__dirname, "app/assets/builds"),
},
plugins: [
new RemoveEmptyScriptsPlugin(),
new MiniCssExtractPlugin(),
new webpack.optimize.LimitChunkCountPlugin({ maxChunks: 1 }),
new CopyPlugin({
patterns: [
{ from: "node_modules/govuk-frontend/govuk/assets/images", to: "images" },
{ from: "node_modules/govuk-frontend/govuk/assets/fonts", to: "fonts" },
],
}),
new webpack.ProvidePlugin({
$: 'jquery',
jQuery: 'jquery',
jquery: 'jquery',
'window.jQuery': 'jquery'
})
]
}

5694
yarn.lock

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save