问题
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