Can you use turbolinks with webpack in rails?

陌路散爱 提交于 2020-01-13 17:00:15

问题


This post provides an excellent tutorial on how to replace the rails asset pipeline with webpack. However, it states that you should remove the turbolinks gem. Is there a way to do this and still use turbolinks?


回答1:


You can use it directly from NPM https://www.npmjs.com/package/turbolinks and follow the provided documentation.

Here is the doc https://www.npmjs.com/package/turbolinks#installation-using-npm

This the same as when you use Turbolinks in other frameworks.




回答2:


You will need to have both, turbolinks from npm and the gem because the redirect_to behavior is modified with the ruby code inside of the gem.

If you have disabled Sprockets (e.g using the --skip-sprockets option) you will need to disable the "auto-require" of the gem in your Gemfile:

gem 'turbolinks', require: false

And then you can include Turbolinks::Redirection module in your application_controller.rb:

require "turbolinks/redirection"

class ApplicationController < ActionController::Base
  include Turbolinks::Redirection
  # ...

I've sent a Pull Request to allow the use Turbolinks without Sprockets



来源:https://stackoverflow.com/questions/40685627/can-you-use-turbolinks-with-webpack-in-rails

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!