Skip to content

Commit 436dac9

Browse files
committed
Add webpacker and bootsnap
1 parent 744c3a2 commit 436dac9

17 files changed

+7720
-1
lines changed

.browserslistrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
defaults

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,10 @@ build-iPhoneSimulator/
6868
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
6969
.rvmrc
7070
/logfile
71+
72+
/public/packs
73+
/public/packs-test
74+
/node_modules
75+
/yarn-error.log
76+
yarn-debug.log*
77+
.yarn-integrity

Gemfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
source 'https://rubygems.org'
22
ruby '2.7.1'
33
gem 'rails'
4+
gem 'webpacker', '~> 4.0'
45
gem 'pg', '~> 0.18'
56
gem 'puma', '~> 3.0'
67
gem 'uglifier', '>= 1.3.0'
@@ -28,7 +29,7 @@ gem 'activeadmin'
2829
gem 'materialize-sass', '~> 1.0.0'
2930
gem 'font-awesome-sass'
3031
gem 'material_icons'
31-
32+
gem 'bootsnap', '>= 1.4.2', require: false
3233
group :development, :test do
3334
gem 'byebug', platform: :mri
3435
gem "simplecov"

Gemfile.lock

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ GEM
9696
execjs
9797
bcrypt (3.1.13)
9898
bindex (0.8.1)
99+
bootsnap (1.4.6)
100+
msgpack (~> 1.0)
99101
builder (3.2.4)
100102
byebug (11.1.3)
101103
capybara (3.33.0)
@@ -221,6 +223,7 @@ GEM
221223
monetize (~> 1.9.0)
222224
money (~> 6.13.2)
223225
railties (>= 3.0)
226+
msgpack (1.3.3)
224227
nenv (0.3.0)
225228
nio4r (2.5.2)
226229
nokogiri (1.10.10)
@@ -244,6 +247,8 @@ GEM
244247
puma (3.12.6)
245248
raabro (1.3.1)
246249
rack (2.2.3)
250+
rack-proxy (0.6.5)
251+
rack
247252
rack-test (1.1.0)
248253
rack (>= 1.0, < 3)
249254
rails (6.0.3.2)
@@ -339,6 +344,10 @@ GEM
339344
activemodel (>= 6.0.0)
340345
bindex (>= 0.4.0)
341346
railties (>= 6.0.0)
347+
webpacker (4.2.2)
348+
activesupport (>= 4.2)
349+
rack-proxy (>= 0.6.1)
350+
railties (>= 4.2)
342351
websocket-driver (0.7.3)
343352
websocket-extensions (>= 0.1.0)
344353
websocket-extensions (0.1.5)
@@ -352,6 +361,7 @@ PLATFORMS
352361
DEPENDENCIES
353362
activeadmin
354363
activerecord-import
364+
bootsnap (>= 1.4.2)
355365
byebug
356366
capybara
357367
capybara-screenshot
@@ -384,6 +394,7 @@ DEPENDENCIES
384394
tzinfo-data
385395
uglifier (>= 1.3.0)
386396
web-console
397+
webpacker (~> 4.0)
387398

388399
RUBY VERSION
389400
ruby 2.7.1p83

app/javascript/packs/application.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/* eslint no-console:0 */
2+
// This file is automatically compiled by Webpack, along with any other files
3+
// present in this directory. You're encouraged to place your actual application logic in
4+
// a relevant structure within app/javascript and only use these pack files to reference
5+
// that code so it'll be compiled.
6+
//
7+
// To reference this file, add <%= javascript_pack_tag 'application' %> to the appropriate
8+
// layout file, like app/views/layouts/application.html.erb
9+
10+
11+
// Uncomment to copy all static images under ../images to the output folder and reference
12+
// them with the image_pack_tag helper in views (e.g <%= image_pack_tag 'rails.png' %>)
13+
// or the `imagePath` JavaScript helper below.
14+
//
15+
// const images = require.context('../images', true)
16+
// const imagePath = (name) => images(name, true)
17+
18+
console.log('Hello World from Webpacker')

babel.config.js

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
module.exports = function(api) {
2+
var validEnv = ['development', 'test', 'production']
3+
var currentEnv = api.env()
4+
var isDevelopmentEnv = api.env('development')
5+
var isProductionEnv = api.env('production')
6+
var isTestEnv = api.env('test')
7+
8+
if (!validEnv.includes(currentEnv)) {
9+
throw new Error(
10+
'Please specify a valid `NODE_ENV` or ' +
11+
'`BABEL_ENV` environment variables. Valid values are "development", ' +
12+
'"test", and "production". Instead, received: ' +
13+
JSON.stringify(currentEnv) +
14+
'.'
15+
)
16+
}
17+
18+
return {
19+
presets: [
20+
isTestEnv && [
21+
'@babel/preset-env',
22+
{
23+
targets: {
24+
node: 'current'
25+
}
26+
}
27+
],
28+
(isProductionEnv || isDevelopmentEnv) && [
29+
'@babel/preset-env',
30+
{
31+
forceAllTransforms: true,
32+
useBuiltIns: 'entry',
33+
corejs: 3,
34+
modules: false,
35+
exclude: ['transform-typeof-symbol']
36+
}
37+
]
38+
].filter(Boolean),
39+
plugins: [
40+
'babel-plugin-macros',
41+
'@babel/plugin-syntax-dynamic-import',
42+
isTestEnv && 'babel-plugin-dynamic-import-node',
43+
'@babel/plugin-transform-destructuring',
44+
[
45+
'@babel/plugin-proposal-class-properties',
46+
{
47+
loose: true
48+
}
49+
],
50+
[
51+
'@babel/plugin-proposal-object-rest-spread',
52+
{
53+
useBuiltIns: true
54+
}
55+
],
56+
[
57+
'@babel/plugin-transform-runtime',
58+
{
59+
helpers: false,
60+
regenerator: true,
61+
corejs: false
62+
}
63+
],
64+
[
65+
'@babel/plugin-transform-regenerator',
66+
{
67+
async: false
68+
}
69+
]
70+
].filter(Boolean)
71+
}
72+
}

bin/webpack

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/usr/bin/env ruby
2+
3+
ENV["RAILS_ENV"] ||= ENV["RACK_ENV"] || "development"
4+
ENV["NODE_ENV"] ||= "development"
5+
6+
require "pathname"
7+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
8+
Pathname.new(__FILE__).realpath)
9+
10+
require "bundler/setup"
11+
12+
require "webpacker"
13+
require "webpacker/webpack_runner"
14+
15+
APP_ROOT = File.expand_path("..", __dir__)
16+
Dir.chdir(APP_ROOT) do
17+
Webpacker::WebpackRunner.run(ARGV)
18+
end

bin/webpack-dev-server

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/usr/bin/env ruby
2+
3+
ENV["RAILS_ENV"] ||= ENV["RACK_ENV"] || "development"
4+
ENV["NODE_ENV"] ||= "development"
5+
6+
require "pathname"
7+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
8+
Pathname.new(__FILE__).realpath)
9+
10+
require "bundler/setup"
11+
12+
require "webpacker"
13+
require "webpacker/dev_server_runner"
14+
15+
APP_ROOT = File.expand_path("..", __dir__)
16+
Dir.chdir(APP_ROOT) do
17+
Webpacker::DevServerRunner.run(ARGV)
18+
end

config/boot.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
22

33
require 'bundler/setup' # Set up gems listed in the Gemfile.
4+
require 'bootsnap/setup' # Speed up boot time by caching expensive operations.

config/webpack/development.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
process.env.NODE_ENV = process.env.NODE_ENV || 'development'
2+
3+
const environment = require('./environment')
4+
5+
module.exports = environment.toWebpackConfig()

0 commit comments

Comments
 (0)