Skip to content

Commit

Permalink
Install Webpacker
Browse files Browse the repository at this point in the history
  • Loading branch information
calleluks committed Feb 1, 2019
1 parent e7e2678 commit da93aeb
Show file tree
Hide file tree
Showing 18 changed files with 7,007 additions and 1 deletion.
18 changes: 18 additions & 0 deletions .babelrc
@@ -0,0 +1,18 @@
{
"presets": [
["env", {
"modules": false,
"targets": {
"browsers": "> 1%",
"uglify": true
},
"useBuiltIns": true
}]
],

"plugins": [
"syntax-dynamic-import",
"transform-object-rest-spread",
["transform-class-properties", { "spec": true }]
]
}
5 changes: 5 additions & 0 deletions .gitignore
Expand Up @@ -29,3 +29,8 @@

# Ignore master key for decrypting credentials and more.
/config/master.key
/public/packs
/public/packs-test
/node_modules
yarn-debug.log*
.yarn-integrity
3 changes: 3 additions & 0 deletions .postcssrc.yml
@@ -0,0 +1,3 @@
plugins:
postcss-import: {}
postcss-cssnext: {}
2 changes: 2 additions & 0 deletions Gemfile
Expand Up @@ -38,6 +38,8 @@ gem 'bootsnap', '>= 1.1.0', require: false

gem 'jquery-rails'

gem 'webpacker', '~> 3.5'

group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
Expand Down
7 changes: 7 additions & 0 deletions Gemfile.lock
Expand Up @@ -113,6 +113,8 @@ GEM
public_suffix (3.0.3)
puma (3.12.0)
rack (2.0.6)
rack-proxy (0.6.5)
rack
rack-test (1.1.0)
rack (>= 1.0, < 3)
rails (5.2.2)
Expand Down Expand Up @@ -188,6 +190,10 @@ GEM
activemodel (>= 5.0)
bindex (>= 0.4.0)
railties (>= 5.0)
webpacker (3.5.5)
activesupport (>= 4.2)
rack-proxy (>= 0.6.1)
railties (>= 4.2)
websocket-driver (0.7.0)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.3)
Expand Down Expand Up @@ -217,6 +223,7 @@ DEPENDENCIES
tzinfo-data
uglifier (>= 1.3.0)
web-console (>= 3.3.0)
webpacker (~> 3.5)

RUBY VERSION
ruby 2.6.1p33
Expand Down
10 changes: 10 additions & 0 deletions app/javascript/packs/application.js
@@ -0,0 +1,10 @@
/* eslint no-console: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.
//
// To reference this file, add <%= javascript_pack_tag 'application' %> to the appropriate
// layout file, like app/views/layouts/application.html.erb

console.log('Hello World from Webpacker')
1 change: 1 addition & 0 deletions app/views/layouts/application.html.erb
Expand Up @@ -7,6 +7,7 @@
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
<%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>
<%= javascript_pack_tag 'application', 'data-turbolinks-track': 'reload' %>
</head>

<body>
Expand Down
15 changes: 15 additions & 0 deletions bin/webpack
@@ -0,0 +1,15 @@
#!/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 "rubygems"
require "bundler/setup"

require "webpacker"
require "webpacker/webpack_runner"
Webpacker::WebpackRunner.run(ARGV)
15 changes: 15 additions & 0 deletions bin/webpack-dev-server
@@ -0,0 +1,15 @@
#!/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 "rubygems"
require "bundler/setup"

require "webpacker"
require "webpacker/dev_server_runner"
Webpacker::DevServerRunner.run(ARGV)
2 changes: 2 additions & 0 deletions config/environments/development.rb
@@ -1,4 +1,6 @@
Rails.application.configure do
# Verifies that versions and hashed value of the package contents in the project's package.json
config.webpacker.check_yarn_integrity = true
# Settings specified here will take precedence over those in config/application.rb.

# In the development environment your application's code is reloaded on
Expand Down
2 changes: 2 additions & 0 deletions config/environments/production.rb
@@ -1,4 +1,6 @@
Rails.application.configure do
# Verifies that versions and hashed value of the package contents in the project's package.json
config.webpacker.check_yarn_integrity = false
# Settings specified here will take precedence over those in config/application.rb.

# Code is not reloaded between requests.
Expand Down
5 changes: 5 additions & 0 deletions config/webpack/development.js
@@ -0,0 +1,5 @@
process.env.NODE_ENV = process.env.NODE_ENV || 'development'

const environment = require('./environment')

module.exports = environment.toWebpackConfig()
3 changes: 3 additions & 0 deletions config/webpack/environment.js
@@ -0,0 +1,3 @@
const { environment } = require('@rails/webpacker')

module.exports = environment
5 changes: 5 additions & 0 deletions config/webpack/production.js
@@ -0,0 +1,5 @@
process.env.NODE_ENV = process.env.NODE_ENV || 'production'

const environment = require('./environment')

module.exports = environment.toWebpackConfig()
5 changes: 5 additions & 0 deletions config/webpack/test.js
@@ -0,0 +1,5 @@
process.env.NODE_ENV = process.env.NODE_ENV || 'development'

const environment = require('./environment')

module.exports = environment.toWebpackConfig()
68 changes: 68 additions & 0 deletions config/webpacker.yml
@@ -0,0 +1,68 @@
# Note: You must restart bin/webpack-dev-server for changes to take effect

default: &default
source_path: app/javascript
source_entry_path: packs
public_output_path: packs
cache_path: tmp/cache/webpacker

# Additional paths webpack should lookup modules
# ['app/assets', 'engine/foo/app/assets']
resolved_paths: []

# Reload manifest.json on all requests so we reload latest compiled packs
cache_manifest: false

extensions:
- .js
- .sass
- .scss
- .css
- .module.sass
- .module.scss
- .module.css
- .png
- .svg
- .gif
- .jpeg
- .jpg

development:
<<: *default
compile: true

# 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: true
overlay: true
compress: true
disable_host_check: true
use_local_ip: false
quiet: false
headers:
'Access-Control-Allow-Origin': '*'
watch_options:
ignored: /node_modules/


test:
<<: *default
compile: true

# Compile test packs to a separate directory
public_output_path: packs-test

production:
<<: *default

# Production depends on precompilation of packs prior to booting for performance.
compile: false

# Cache manifest.json for performance
cache_manifest: true
7 changes: 6 additions & 1 deletion package.json
@@ -1,5 +1,10 @@
{
"name": "webpacker-rails-5-2",
"private": true,
"dependencies": {}
"dependencies": {
"@rails/webpacker": "3.5"
},
"devDependencies": {
"webpack-dev-server": "2.11.2"
}
}

0 comments on commit da93aeb

Please sign in to comment.