アプリケーションに Turbo をインストール
Turbo は、アプリケーションの <head>
内にて Turbo 配布スクリプトから直接、または esbuild などのバンドル経由で npm を使用することにより、コンパイルされた形で参照することができます。
原文
Installing Turbo in Your Application
Turbo can either be referenced in compiled form via the Turbo distributable script directly in the <head>
of your application or through npm via a bundler like esbuild.
# コンパイル済みスクリプト
jsDelivr のような CDN バンドラーを利用してリリースされた最新の Turbo を使用できます。
下の <script>
タグをアプリケーションの <head>
の中に含めるだけです。
またはunpkgからコンパイルされたパッケージをダウンロードできます。
原文
# In Compiled Form
You can float on the latest release of Turbo using a CDN bundler like jsDelivr. Just include a <script>
tag in the <head>
of your application:
<head>
<script type="module" src="https://cdn.jsdelivr.net/npm/@hotwired/turbo@latest/dist/turbo.es2017-esm.min.js"></script>
</head>
# npm パッケージ
パッケージングツールの npm
や yarn
を利用して npm から Turbo をインストールできます。
もし Turbo.visit()
といった Turbo の関数を使うなら、下記のように Turbo の関数をコードにインポートします。
import * as Turbo from "@hotwired/turbo";
もし Turbo.visit()
のような Turbo の関数を使わ ない 場合は、下記のようにTurbo の関数をインポートしてください。
これにより、一部のバンドラーにおいてツリーシェイクや未使用変数の問題を回避することができます。詳しくはMDNの 副作用のためだけにモジュールをインポートするをご覧ください。
import "@hotwired/turbo";
原文
# As An npm Package
You can install Turbo from npm via the npm
or yarn
packaging tools.
If you using any Turbo functions such as Turbo.visit()
import the Turbo
functions into your code:
import * as Turbo from "@hotwired/turbo"
If you’re not using any Turbo functions such as Turbo.visit()
import the library. This avoids issues with tree-shaking and unused variables in some bundlers. See Import a module for its side effects only on MDN.
import "@hotwired/turbo";
# Ruby on Rails アプリケーション
JavaScript フレームワークの Turbo は、アセットパイプラインで直接利用できるように turbo-rails gem に含まれています。
原文
# In a Ruby on Rails application
The Turbo JavaScript framework is included with the turbo-rails gem for direct use with the asset pipeline.