From 2adf55f9c8354fa676616c5fb8c185ffd1eca2ae Mon Sep 17 00:00:00 2001 From: Leevi Graham Date: Wed, 13 Mar 2024 11:49:19 +1100 Subject: [PATCH] Update 08_installing.md Add alternative side-affects only import --- _source/handbook/08_installing.md | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/_source/handbook/08_installing.md b/_source/handbook/08_installing.md index 21b5a02..a86d5e6 100644 --- a/_source/handbook/08_installing.md +++ b/_source/handbook/08_installing.md @@ -13,12 +13,20 @@ You can float on the latest release of Turbo using a CDN bundler like Skypack. S ## As An npm Package -You can install Turbo from npm via the `npm` or `yarn` packaging tools. Then require or import that in your code: +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: ```javascript 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](https://developer.mozilla.org/en-US/docs/web/javascript/reference/statements/import#import_a_module_for_its_side_effects_only) on MDN. + +```javascript +import "@hotwired/turbo"; +``` + ## In a Ruby on Rails application The Turbo JavaScript framework is included with [the turbo-rails gem](https://github.com/hotwired/turbo-rails) for direct use with the asset pipeline.