-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Webpacker support #3414
Webpacker support #3414
Conversation
ffa7d8a
to
b383d35
Compare
Pull Request Test Coverage Report for Build 1459001873
💛 - Coveralls |
Changes unknown |
612cd6f
to
ee102ce
Compare
I realize that this is a draft PR but I want to share my experience trying to install rails_admin from this branch. I ran into issues with the location of my javascript. In my project, I renamed the location of my scripts folders to
|
@TheBrockEllis Thanks for trying this out, looks like a configuration issue. If you could provide me the source code with relevant configuration I can take a look. |
Because rails-ujs has the same functionality now. https://github.com/rails/rails/blob/f95c0b7e96eb36bc3efc0c5beffbb9e84ea664e4/actionview/app/assets/javascripts/rails-ujs/features/remote.coffee#L36-L37
@codealchemy @jdufresne |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work! This is an exciting change.
.github/workflows/test.yml
Outdated
- name: Run check | ||
run: npx prettier --check . | ||
run: ./node_modules/.bin/prettier --check . |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe yarn
will execute scripts from node_modules/.bin
run: ./node_modules/.bin/prettier --check . | |
run: yarn prettier --check . |
@@ -12,35 +12,48 @@ jobs: | |||
gemfile: [gemfiles/rails_6.1.gemfile] | |||
orm: [active_record] | |||
adapter: [sqlite3] | |||
asset: [sprockets] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you explain why aren't other asset pipelines defined here? Don't we want to verify webpack/webpacker in all scenarios?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we go this way,
ruby: [2.6, 2.7, 3.0, jruby]
asset: [sprockets, webpacker]
we'll get every combination of 2.6/sprockets, 2.6/webpacker, 2.7/sprockets, ... and so on. That's kind of redundant, since in general Ruby version will not affect how JavaScript assets are executed.
So I didn't add webpacker in the global matrix, and added it individually like this to save CI execution time and computer resource.
include:
...
- ruby: 3.0
gemfile: gemfiles/rails_6.1.gemfile
orm: active_record
adapter: postgresql
asset: webpacker
- ruby: 3.0
gemfile: gemfiles/rails_7.0.gemfile
orm: active_record
adapter: sqlite3
asset: webpacker
@@ -195,5 +195,17 @@ def flash_alert_class(flash_key) | |||
else "alert-#{flash_key}" | |||
end | |||
end | |||
|
|||
def handle_asset_dependency_error |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the existing exception insufficient or confusing? I'm thinking maybe we don't need this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It gives an exception like this:
LoadError in RailsAdmin::MainController#dashboard
cannot load such file -- sassc
not so confusing, but we're dropping existing sassc dependency from our gem so it would be better to be friendly for existing users to instruct what's happening after their gem upgrade.
<% when :webpack, :sprockets %> | ||
<% handle_asset_dependency_error do %> | ||
<%= stylesheet_link_tag "rails_admin.css", media: :all %> | ||
<%= javascript_include_tag "rails_admin.js", defer: true %> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is better to use async
rather than defer
.
Can we also apply the aync attribute to the webpacker file?
gemfiles/rails_6.1.gemfile
Outdated
gem "database_cleaner-active_record", ">= 2.0", require: false | ||
gem "database_cleaner-mongoid", ">= 2.0", require: false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What are these unrelated ordering changes? Can they be reverted or moved to a separete PR so this remains focused on just webpack and assets?
], | ||
"main": "src/rails_admin/base.js", | ||
"scripts": { | ||
"link": "yarn link && cd spec/dummy_app && yarn link rails_admin", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this link script get used? I don't see it and am not familiar with it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is useful for working with webpack-built assets. After your run yarn run link
a symlink is created under dummy_app's node_modules so the changes made to the files under src
dir will be immediately picked up by webpack-dev-server.
https://classic.yarnpkg.com/en/docs/cli/link/
@@ -0,0 +1,10872 @@ | |||
/*! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same thought here, could import from node_modules to avoid vendoring?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as #3414 (comment).
- "spec/dummy_app/bin/**/*" | ||
- "spec/dummy_app/db/schema.rb" | ||
- "spec/dummy_app/tmp/**/*" | ||
- "vendor/bundle/**/*" | ||
NewCops: disable | ||
SuggestExtensions: false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is this silencing? Maybe it would be better to install the suggestion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Showing the suggestion everytime Rubocop is run is pointless. I run it so many times during development.
You can install those extensions if you want to, regardless of the suggestion.
app/assets/stylesheets/rails_admin/aristo | ||
app/assets/stylesheets/rails_admin/themes/cerulean | ||
coverage | ||
lib/generators/rails_admin/templates |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why ignore this directory? Sems like this should be formatted the same as any other file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's reason for it...
Some of files contained here (specifically speaking, they're environment.js
and webpack.config.js
) are need to be merged with existing ones which are created by Webpacker or Rails. And if a user already has some configurations, they need to be merged manually with the changes RailsAdmin need.
If we apply prettier to our templates and run RailsAdmin installer, what users get is like this:
% rails g rails_admin:install
...
conflict webpack.config.js
Overwrite /path/to/webpack.config.js? (enter "h" for help) [Ynaqdhm] d
--- /path/to/webpack.config.js 2021-12-04 13:53:59.000000000 +0900
+++ /path/to/webpack.config.js20211204-51180-i5ghjr 2021-12-04 13:54:22.000000000 +0900
@@ -1,18 +1,32 @@
-const path = require("path")
-const webpack = require('webpack')
+const path = require("path");
+const webpack = require("webpack");
+const MiniCssExtractPlugin = require("mini-css-extract-plugin");
...
those diffs are unnecessary if we don't apply prettier. Then it looks like:
conflict webpack.config.js
Overwrite /path/to/webpack.config.js? (enter "h" for help) [Ynaqdhm] d
--- /path/to/webpack.config.js 2021-12-04 13:53:59.000000000 +0900
+++ /path/to/webpack.config.js20211204-51508-jf8k2a 2021-12-04 13:58:12.000000000 +0900
@@ -1,18 +1,32 @@
const path = require("path")
const webpack = require('webpack')
+const MiniCssExtractPlugin = require("mini-css-extract-plugin")
...
much cleaner.
My intention is enabling users to install RailsAdmin with less work, instead of applying prettier to templates to get feeling of tidiness. Users can choose to apply prettier to their source code anyway, without hustle.
@@ -86,6 +86,9 @@ class << self | |||
attr_accessor :navigation_static_links | |||
attr_accessor :navigation_static_label | |||
|
|||
# Set where RailsAdmin fetches JS/CSS from, defaults to :sprockets |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As this is targeting a new major release, any thought on defaulting to webpacker? Upstream Rails recommends webpack for new projects and describes sprockets as "legacy": https://edgeguides.rubyonrails.org/webpacker.html
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to ensure compatibility with existing applications. Since using :webpacker
as default value for asset_source
doesn't automatically make those applications Webpacker-ready, we need to provide migration path for users.
In this way, users can proceed like this:
- Upgrade RailsAdmin, keeping the app functional since RailsAdmin delivers assets using Sprockets by default
- Make their app Webpacker-ready
- When things are ready, they can configure RailsAdmin to use Webpacker-sourced assets
- Use `yarn run`, instead of `./node_modules/.bin/` - Remove unnecessary .prettierignore entries - Address Rubocop Performance/RegexpMatch offense in the PR build - Apply async: true to javascript tags - Restore order changes in gemfiles/* - Change scripts task `prettier` to `format`, since it conflicts with the prettier command itself - Apply prettier to src/rails_admin/styles/themes/cerulean
@jdufresne Addressed all review suggestions, please take a look again 🙏 |
Let me merge this for now, since it's blocking other works. |
It was introduced by #3414, but is not fully functional yet
Closes #3277