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

Upgrade Npms for try to fix Webpacker precompile in production env. #1305

Merged
merged 4 commits into from
Dec 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/release_tag.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Release
name: Release Tags
on:
push:
tags:
Expand Down
19 changes: 17 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: Test

on: [push, pull_request]
on: push
jobs:
lint:
name: AutoCorrect Check
Expand All @@ -9,10 +9,25 @@ jobs:
- uses: actions/checkout@v2
- name: huacnlee.autocorrect
uses: huacnlee/autocorrect-action@main
assets_compile:
name: Assets Compile
runs-on: ubuntu-latest
container: homeland/base:3.0.1-slim-buster
steps:
- uses: actions/checkout@v2
- name: Install dependencies
run: |
sed -i "s/gems.ruby-china.org/rubygems.org/g" Gemfile.lock
bundle config path vendor/bundle
bundle install
yarn
- name: Assets Precompile
run: bundle exec rails assets:precompile RAILS_PRECOMPILE=1 RAILS_ENV=production SECRET_KEY_BASE=fake_secure_for_compile

test:
name: CI Test
runs-on: ubuntu-latest
container: homeland/base:2.7.2-slim-buster
container: homeland/base:3.0.1-slim-buster
services:
postgres:
image: postgres:10
Expand Down
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,10 @@ app.local.env
/yarn-error.log
yarn-debug.log*
.yarn-integrity

/public/packs
/public/packs-test
/node_modules
/yarn-error.log
yarn-debug.log*
.yarn-integrity
4 changes: 2 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ gem "rails_autolink"
gem "sass-rails"
gem "turbolinks"
gem "uglifier"
gem "webpacker"
gem "webpacker", "6.0.0.rc.6"

gem "view_component"

Expand All @@ -33,7 +33,7 @@ gem "dotenv-rails"
gem "rack-attack"
gem "http_accept_language"
# https://github.com/svenfuchs/rails-i18n/pull/957
gem "rails-i18n", github: "f6p/rails-i18n", branch: "rails7"
gem "rails-i18n", github: "f6p/rails-i18n", branch: "rails7-hotfix"
gem "twemoji"

# Uploader
Expand Down
8 changes: 4 additions & 4 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
GIT
remote: https://github.com/f6p/rails-i18n.git
revision: 751d497ed2a7b16927b14bbe6096d4b44d7e8a2c
branch: rails7
revision: a2102371c5f46fd1bdc49d5ec9c99fbe9a375bc8
branch: rails7-hotfix
specs:
rails-i18n (7.0.0)
i18n (>= 0.7, < 2)
Expand Down Expand Up @@ -457,7 +457,7 @@ GEM
method_source (~> 1.0)
warden (1.2.9)
rack (>= 2.0.9)
webpacker (5.4.2)
webpacker (6.0.0.rc.6)
activesupport (>= 5.2)
rack-proxy (>= 0.6.1)
railties (>= 5.2)
Expand Down Expand Up @@ -540,7 +540,7 @@ DEPENDENCIES
twemoji
uglifier
view_component
webpacker
webpacker (= 6.0.0.rc.6)

BUNDLED WITH
2.2.3
1 change: 1 addition & 0 deletions app/javascript/admin.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@import "admin/index";
3 changes: 3 additions & 0 deletions app/javascript/application.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import "homeland/index";
import "vendor/bootstrap";
import "front/index";
1 change: 1 addition & 0 deletions app/javascript/front.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@import "front/index";
9 changes: 5 additions & 4 deletions app/javascript/homeland/iconfont.scss
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
$fa-font-path: "~@fortawesome/fontawesome-free/webfonts";
@import "~@fortawesome/fontawesome-free/scss/fontawesome.scss";
@import "~@fortawesome/fontawesome-free/scss/solid.scss";
@import "~@fortawesome/fontawesome-free/scss/brands.scss";
$fa-font-path: "@fortawesome/fontawesome-free/webfonts";

@import "@fortawesome/fontawesome-free/scss/fontawesome";
@import "@fortawesome/fontawesome-free/scss/solid";
@import "@fortawesome/fontawesome-free/scss/brands";

.fa {
&-pin {
Expand Down
1 change: 1 addition & 0 deletions app/javascript/homeland/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
@import "~bootstrap/scss/functions";
@import "~bootstrap/scss/variables";
@import "~bootstrap/scss/utilities";

$utilities: map-merge(
$utilities,
(
Expand Down
6 changes: 2 additions & 4 deletions app/javascript/jsconfig.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
{
"compilerOptions": {
"baseUrl": ".",
"baseUrl": "."
},
"exclude": [
"node_modules",
]
"exclude": ["node_modules"]
}
1 change: 0 additions & 1 deletion app/javascript/packs/admin.scss

This file was deleted.

2 changes: 0 additions & 2 deletions app/javascript/packs/application.js

This file was deleted.

1 change: 0 additions & 1 deletion app/javascript/packs/front.scss

This file was deleted.

1 change: 0 additions & 1 deletion app/javascript/packs/turbolinks-app.scss

This file was deleted.

1 change: 1 addition & 0 deletions app/javascript/turbolinks-app.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@import "homeland/turbolinks-app";
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
window.bootstrap = require("bootstrap");
import * as bootstrap from "bootstrap/dist/js/bootstrap.esm";
window.bootstrap = bootstrap;
require("bootstrap-select");

document.addEventListener("turbolinks:load", () => {
Expand Down
3 changes: 1 addition & 2 deletions app/views/layouts/admin.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@
<meta name="theme" content="<%= user_theme %>">
<title><%= Setting.app_name %> - Admin Panel</title>
<%= stylesheet_pack_tag "admin" %>
<%= javascript_packs_with_chunks_tag "application" %>
<%= javascript_pack_tag "application", defer: false %>
<%= csrf_meta_tag %>
</head>
<body>
<%= javascript_pack_tag "bootstrap", 'data-turbolinks-eval': "false" %>
<div class="header">
<div class="header navbar navbar-expand flex-md-row bd-navbar">
<div class="container d-sm-flex">
Expand Down
5 changes: 2 additions & 3 deletions app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
<%= stylesheet_pack_tag "front", "data-turbolinks-track": "reload" %>
<%= stylesheet_pack_tag "turbolinks-app", 'data-turbolinks-track': 'reload' if turbolinks_app? %>
<%= yield :stylesheets %>
<%= javascript_pack_tag "application", defer: false %>
<%= yield :javascripts %>
<%= action_cable_meta_tag %>
<%= csrf_meta_tag %>
<%= raw Setting.custom_head_html %>
Expand All @@ -37,11 +39,8 @@
<% if current_user %>
<meta name="current-user" data-user-id="<%= current_user.id %>" data-user-login="<%= current_user.login %>" data-user-name="<%= current_user.name %>" data-user-email="<%= current_user.email %>" data-user-avatar-url="<%= current_user.avatar? ? current_user.avatar.url(:md) : current_user.letter_avatar_url(96) %>">
<% end %>
<%= javascript_packs_with_chunks_tag "application", 'data-turbolinks-track': "reload" %>
<%= yield :javascripts %>
</head>
<body class="page-<%= controller_name %><%= ' infinite-scroll' if turbolinks_app? %>" data-controller-name="<%= controller_name %>">
<%= javascript_pack_tag "bootstrap", 'data-turbolinks-eval': "false" %>
<div class="header navbar navbar-expand-md">
<div class="container">
<div class="navbar-header" data-turbolinks-permanent>
Expand Down
3 changes: 1 addition & 2 deletions app/views/layouts/simple.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@
<meta name="apple-mobile-web-app-capable" content="no">
<meta content='True' name='HandheldFriendly'>
<%= stylesheet_pack_tag "front" %>
<%= javascript_packs_with_chunks_tag "application" %>
<%= javascript_pack_tag "application", defer: false %>
<%= csrf_meta_tag %>
<%= raw Setting.custom_head_html %>
</head>
<body data-controller-name="<%= controller_name %>">
<%= javascript_pack_tag "bootstrap", 'data-turbolinks-eval': "false" %>
<div class="header">
<div class="header navbar navbar-expand flex-md-row bd-navbar">
<div class="container d-sm-flex flex-wrap">
Expand Down
88 changes: 0 additions & 88 deletions babel.config.js

This file was deleted.

11 changes: 4 additions & 7 deletions bin/webpack
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
#!/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"

ENV["RAILS_ENV"] ||= ENV["RACK_ENV"] || "development"
ENV["NODE_ENV"] ||= "development"
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", Pathname.new(__FILE__).realpath)

APP_ROOT = File.expand_path("..", __dir__)
Dir.chdir(APP_ROOT) do
Webpacker::WebpackRunner.run(ARGV)
Expand Down
21 changes: 15 additions & 6 deletions bin/yarn
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
#!/usr/bin/env ruby
APP_ROOT = File.expand_path('..', __dir__)

APP_ROOT = File.expand_path("..", __dir__)
Dir.chdir(APP_ROOT) do
exec "yarn", *ARGV
rescue Errno::ENOENT
$stderr.puts "Yarn executable was not detected in the system."
$stderr.puts "Download Yarn at https://yarnpkg.com/en/docs/install"
exit 1
yarn = ENV["PATH"].split(File::PATH_SEPARATOR).
select { |dir| File.expand_path(dir) != __dir__ }.
product(["yarn", "yarnpkg", "yarn.cmd", "yarn.ps1"]).
map { |dir, file| File.expand_path(file, dir) }.
find { |file| File.executable?(file) }

if yarn
exec yarn, *ARGV
else
$stderr.puts "Yarn executable was not detected in the system."
$stderr.puts "Download Yarn at https://yarnpkg.com/en/docs/install"
exit 1
end
end
6 changes: 4 additions & 2 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,7 @@ class Application < Rails::Application
end
end

# Homeland boot must keep in here
require "homeland"
unless ENV["RAILS_PRECOMPILE"].present?
# Homeland boot must keep in here
require "homeland"
end
3 changes: 3 additions & 0 deletions config/initializers/assets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,6 @@
# folder are already added.
# Rails.application.config.assets.precompile += %w( admin.js admin.css )
Rails.application.config.assets.precompile += %w[app.js front.css turbolinks-app.css admin.css]

# Add node_modules folder to the asset load path.
Rails.application.config.assets.paths << Rails.root.join("node_modules")
4 changes: 4 additions & 0 deletions config/webpack/base.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
const { webpackConfig, merge } = require("@rails/webpacker");
const customConfig = require("./custom");

module.exports = merge(webpackConfig, customConfig);
13 changes: 13 additions & 0 deletions config/webpack/custom.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const webpack = require("webpack");

module.exports = {
plugins: [
new webpack.ProvidePlugin({
$: "jquery",
jQuery: "jquery",
}),
],
resolve: {
extensions: [".js", ".ts", ".tsx", ".js.erb", ".css", ".scss"],
},
};
4 changes: 2 additions & 2 deletions config/webpack/development.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
process.env.NODE_ENV = process.env.NODE_ENV || 'development'

const environment = require('./environment')
const webpackConfig = require('./base')

module.exports = environment.toWebpackConfig()
module.exports = webpackConfig
4 changes: 2 additions & 2 deletions config/webpack/production.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
process.env.NODE_ENV = process.env.NODE_ENV || 'production'

const environment = require('./environment')
const webpackConfig = require('./base')

module.exports = environment.toWebpackConfig()
module.exports = webpackConfig
4 changes: 2 additions & 2 deletions config/webpack/test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
process.env.NODE_ENV = process.env.NODE_ENV || 'development'

const environment = require('./environment')
const webpackConfig = require('./base')

module.exports = environment.toWebpackConfig()
module.exports = webpackConfig
Loading