Skip to content

Instantly share code, notes, and snippets.

@kevinhq
kevinhq / example1.js
Created July 10, 2020 04:45
Step-by-Step guide on how to move from Sprockets to Webpacker - packs/example1.js
/* app/javascript/packs/example1.js */
var example1 = function doSomething() {
// Your codes here
}
export default example1;
@kevinhq
kevinhq / application.js
Created July 9, 2020 06:09
Step-by-Step guide on how to move from Sprockets to Webpacker - updated application.js
/* app/javascript/packs/application.js */
require("@rails/ujs").start();
require("@rails/activestorage").start();
require("packs/example1");
require("packs/example2");
require("packs/example3");
@kevinhq
kevinhq / application.html.erb
Last active August 15, 2020 18:03
Step-by-Step guide on how to move from Sprockets to Webpacker - application.html.erb
<%# app/views/layouts/application.html.erb %>
<!DOCTYPE html>
<html>
<head>
<!-- add this new application.js -->
<%= javascript_pack_tag 'application' %>
</head>
<body>
<%= yield %>
</body>
@kevinhq
kevinhq / application.js
Created July 9, 2020 05:40
Step-by-Step guide on how to move from Sprockets to Webpacker - application.js
/* app/javascript/packs/application.js */
require("@rails/ujs").start();
require("@rails/activestorage").start();
@kevinhq
kevinhq / Gemfile
Created July 9, 2020 05:22
Step-by-Step guide on how to move from Sprockets to Webpacker - Gemfile
gem "webpacker"
@kevinhq
kevinhq / application.amp.erb
Created July 5, 2020 02:41
Create AMP in Rails powered website - application.amp.erb
# app/views/amp/layouts/application.amp.erb
<!DOCTYPE html>
<html amp lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
<!-- add/remove ampproject.org scripts as you need it -->
<script async src="https://cdn.ampproject.org/v0.js"></script>
<script async custom-element="amp-form" src="https://cdn.ampproject.org/v0/amp-form-0.1.js"></script>
@kevinhq
kevinhq / show.amp.erb
Created July 5, 2020 02:32
Create AMP in Rails powered website - show.amp.erb
# app/views/amp/samples/show.amp.erb
# write your HTML for AMP page here.
@kevinhq
kevinhq / samples_controller.rb
Last active July 9, 2020 01:47
Create AMP in Rails powered website - samples_controller.rb
# app/controllers/samples_controller.rb
Class SamplesController
# other existing methods
def show
# your existing codes
respond_to do |format|
format.html
format.amp { render 'amp/samples/show.amp', layout: 'amp/layouts/application' }
end
@kevinhq
kevinhq / mime_types.rb
Last active July 6, 2020 20:59
Create AMP in Rails powered website - mime_types.rb
# config/initializers/mime_types.rb
Mime::Type.register 'text/html', :amp
@kevinhq
kevinhq / optimization.rb
Created July 3, 2020 06:16
Place this on config/environments/optimization.rb
config.after_initialize do
Bullet.enable = true
Bullet.alert = true
Bullet.bullet_logger = true
Bullet.console = true
Bullet.rails_logger = true
Bullet.add_footer = true
end