Skip to content

Commit

Permalink
Eject webpacker for jsbundling-rails
Browse files Browse the repository at this point in the history
Signed-off-by: Josh W Lewis <[email protected]>

Update Gemfile.lock

Signed-off-by: Josh W Lewis <[email protected]>

Additional adjustments to asset pipeline

Use inline image assets, drop sass-rails

Signed-off-by: Josh W Lewis <[email protected]>
  • Loading branch information
joshwlewis committed Aug 21, 2024
1 parent 312e074 commit 47736c4
Show file tree
Hide file tree
Showing 22 changed files with 1,764 additions and 941 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,6 @@ package-lock.json

# Ignore asdf versions
.tool-versions

/app/assets/builds/*
!/app/assets/builds/.keep
3 changes: 1 addition & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@ gem 'rack-attack'
gem 'rack-cors'
gem 'rails', '~> 6.1.0'
gem 'rollbar'
gem 'sass-rails', '>= 6'
gem 'toml'
gem 'webpacker', '~> 5.2', '>= 5.2.1'
gem 'jsbundling-rails', '~> 1.3'

group :development, :test do
gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
Expand Down
24 changes: 3 additions & 21 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ GEM
activesupport (>= 5.0)
i18n (1.12.0)
concurrent-ruby (~> 1.0)
jsbundling-rails (1.3.1)
railties (>= 6.0.0)
json_schema (0.21.0)
listen (3.5.0)
rb-fsevent (~> 0.10, >= 0.10.3)
Expand Down Expand Up @@ -127,8 +129,6 @@ GEM
rack (>= 1.0, < 3)
rack-cors (1.1.1)
rack (>= 2.0.0)
rack-proxy (0.6.5)
rack
rack-test (1.1.0)
rack (>= 1.0, < 3)
rails (6.1.3)
Expand Down Expand Up @@ -177,17 +177,6 @@ GEM
rubocop-ast (1.4.1)
parser (>= 2.7.1.5)
ruby-progressbar (1.11.0)
sass-rails (6.0.0)
sassc-rails (~> 2.1, >= 2.1.1)
sassc (2.4.0)
ffi (~> 1.9)
sassc-rails (2.1.2)
railties (>= 4.0.0)
sassc (>= 2.0)
sprockets (> 3.0)
sprockets-rails
tilt
semantic_range (3.0.0)
simplecov (0.21.2)
docile (~> 1.1)
simplecov-html (~> 0.11)
Expand All @@ -202,18 +191,12 @@ GEM
activesupport (>= 4.0)
sprockets (>= 3.0.0)
thor (1.1.0)
tilt (2.0.10)
toml (0.2.0)
parslet (~> 1.8.0)
tzinfo (2.0.5)
concurrent-ruby (~> 1.0)
unicode-display_width (2.0.0)
vcr (6.0.0)
webpacker (5.2.1)
activesupport (>= 5.2)
rack-proxy (>= 0.6.1)
railties (>= 5.2)
semantic_range (>= 2.3.0)
websocket-driver (0.7.3)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.5)
Expand All @@ -226,6 +209,7 @@ DEPENDENCIES
byebug
committee
dotenv-rails
jsbundling-rails (~> 1.3)
listen (~> 3.3)
minitest-reporters
mocha
Expand All @@ -238,12 +222,10 @@ DEPENDENCIES
rails (~> 6.1.0)
rollbar
rubocop
sass-rails (>= 6)
simplecov
toml
tzinfo-data
vcr
webpacker (~> 5.2, >= 5.2.1)

RUBY VERSION
ruby 2.7.2p137
Expand Down
2 changes: 2 additions & 0 deletions Procfile.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
web: env RUBY_DEBUG_OPEN=true bin/rails server
js: yarn build --watch
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,10 +180,10 @@ Run the tests:
```
$ make test
```
Then run the app:
Then run the Rails app and asset watcher/compiler with:

```
$ bundle exec rails s
$ ./bin/dev
```

In other terminal session, run the background worker to create the index:
Expand Down
Empty file added app/assets/builds/.keep
Empty file.
2 changes: 1 addition & 1 deletion app/assets/config/manifest.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
//= link_tree ../images
//= link_directory ../stylesheets .css
//= link_tree ../builds
2 changes: 2 additions & 0 deletions app/javascript/application.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Entry point for the build script in your package.json
import Index from "./packs/Index.tsx";
8 changes: 4 additions & 4 deletions app/javascript/components/search/Search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class Search extends React.Component<{}, { searchTerm: string, searchResults: an
if (this.state.loading || (this.state.searchResults.length === 0 && this.state.searchTerm === '')) {
summary = null;
}

return (
<div className="Search">
<div className="Search-header">
Expand All @@ -72,7 +72,7 @@ class Search extends React.Component<{}, { searchTerm: string, searchResults: an
</div>
);
}

async keyPressed(e: any) {
const searchTerm = (e.target.value + '').trim();
if (searchTerm === '' || e.keyCode !== 13) {
Expand All @@ -93,7 +93,7 @@ class Search extends React.Component<{}, { searchTerm: string, searchResults: an
this.setState({
formValue: a
});

await this.fetchSearchResults(a);
}

Expand All @@ -103,7 +103,7 @@ class Search extends React.Component<{}, { searchTerm: string, searchResults: an
}

try {
const apiHost = process.env.CNB_API_HOST || 'https://cnb-registry-api.herokuapp.com';
const apiHost = process.env.CNB_API_HOST;
const link = `${apiHost}/api/v1/search?matches=${searchText}`;
const response: AxiosResponse = await Axios.get(link);
if (response.status >= 200 && response.status < 300) {
Expand Down
2 changes: 0 additions & 2 deletions app/javascript/packs/Index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import React from "react";
import { render } from "react-dom";
import 'bootstrap/dist/css/bootstrap.min.css';
import 'bootstrap/dist/js/bootstrap.bundle.min';
import App from "../components/App";

document.addEventListener("DOMContentLoaded", () => {
Expand Down
4 changes: 2 additions & 2 deletions app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
<%= csrf_meta_tags %>
<%= csp_meta_tag %>

<%= stylesheet_pack_tag 'application', media: 'all' %>
<%= stylesheet_link_tag 'application', media: 'all' %>
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<%= javascript_pack_tag 'Index' %>
<%= javascript_include_tag "application", type: "module" %>
</head>

<body>
Expand Down
11 changes: 11 additions & 0 deletions bin/dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env sh

if gem list --no-installed --exact --silent foreman; then
echo "Installing foreman..."
gem install foreman
fi

# Default to port 3000 if not specified
export PORT="${PORT:-3000}"

exec foreman start -f Procfile.dev --env /dev/null "$@"
18 changes: 0 additions & 18 deletions bin/webpack

This file was deleted.

18 changes: 0 additions & 18 deletions bin/webpack-dev-server

This file was deleted.

5 changes: 0 additions & 5 deletions config/webpack/development.js

This file was deleted.

3 changes: 0 additions & 3 deletions config/webpack/environment.js

This file was deleted.

5 changes: 0 additions & 5 deletions config/webpack/production.js

This file was deleted.

5 changes: 0 additions & 5 deletions config/webpack/test.js

This file was deleted.

54 changes: 54 additions & 0 deletions config/webpack/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
const path = require("path")
const webpack = require("webpack")
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const mode = process.env.NODE_ENV === 'development' ? 'development' : 'production';

module.exports = {
mode,
entry: {
application: [
"./app/javascript/application.js",
'./app/assets/stylesheets/application.css',
],
},
optimization: {
moduleIds: 'deterministic',
},
output: {
filename: "[name].js",
chunkFilename: "[name]-[contenthash].digested.js",
sourceMapFilename: "[file]-[fullhash].map",
path: path.resolve(__dirname, '..', '..', 'app/assets/builds'),
hashFunction: "sha256",
hashDigestLength: 64,
},
module: {
rules: [
{
test: /\.(js|jsx|ts|tsx|)$/,
exclude: /node_modules/,
use: ['babel-loader'],
},
{
test: /\.(?:sa|sc|c)ss$/i,
use: [MiniCssExtractPlugin.loader, 'css-loader', 'sass-loader'],
},
{
test: /\.(png|jpe?g|svg)$/i,
type: 'asset/inline'
},
],
},
resolve: {
extensions: ['.js', '.jsx', '.ts', '.tsx', '.scss', '.css', '.png', '.svg'],
},
plugins: [
new MiniCssExtractPlugin(),
new webpack.optimize.LimitChunkCountPlugin({
maxChunks: 1
}),
new webpack.EnvironmentPlugin({
CNB_API_HOST: 'https://cnb-registry-api.herokuapp.com'
})
]
}
95 changes: 0 additions & 95 deletions config/webpacker.yml

This file was deleted.

Loading

0 comments on commit 47736c4

Please sign in to comment.