{"id":13878675,"url":"https://github.com/shakacode/shakapacker","last_synced_at":"2025-10-11T05:50:17.305Z","repository":{"id":37967148,"uuid":"85431399","full_name":"shakacode/shakapacker","owner":"shakacode","description":"Use Webpack to manage app-like JavaScript modules in Rails","archived":false,"fork":false,"pushed_at":"2025-10-10T07:43:36.000Z","size":7447,"stargazers_count":458,"open_issues_count":24,"forks_count":101,"subscribers_count":10,"default_branch":"main","last_synced_at":"2025-10-10T13:12:40.641Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/shakacode.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"MIT-LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null},"funding":{"github":["shakacode"]}},"created_at":"2017-03-18T20:53:33.000Z","updated_at":"2025-10-10T06:11:00.000Z","dependencies_parsed_at":"2022-07-10T00:45:07.087Z","dependency_job_id":"eae62470-6d83-49bf-8d57-dc4709a0c1c6","html_url":"https://github.com/shakacode/shakapacker","commit_stats":{"total_commits":1637,"total_committers":502,"mean_commits":3.260956175298805,"dds":0.916310323762981,"last_synced_commit":"2aa5a8e047c70267a452ed36840ffe5b1300abc6"},"previous_names":[],"tags_count":110,"template":false,"template_full_name":null,"purl":"pkg:github/shakacode/shakapacker","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shakacode%2Fshakapacker","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shakacode%2Fshakapacker/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shakacode%2Fshakapacker/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shakacode%2Fshakapacker/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/shakacode","download_url":"https://codeload.github.com/shakacode/shakapacker/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shakacode%2Fshakapacker/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279006357,"owners_count":26084088,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-11T02:00:06.511Z","response_time":55,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-06T08:01:56.446Z","updated_at":"2025-10-11T05:50:17.298Z","avatar_url":"https://github.com/shakacode.png","language":"Ruby","funding_links":["https://github.com/sponsors/shakacode"],"categories":["Ruby","Gems","Resources","Assets"],"sub_categories":["Articles","Ecosystem"],"readme":"# Shakapacker (v9)\n\n---\n\n_🚀 Shakapacker 9 supports [Rspack](https://rspack.rs/)! 10x faster than webpack!_\n\n---\n\n_Official, actively maintained successor to [rails/webpacker](https://github.com/rails/webpacker). ShakaCode stands behind the long-term maintenance and development of this project for the Rails community._\n\n- ⚠️ See the [6-stable](https://github.com/shakacode/shakapacker/tree/6-stable) branch for Shakapacker v6.x code and documentation. :warning:\n- **See [V9 Upgrade](./docs/v9_upgrade.md) for upgrading from the v8 release.**\n- See [V8 Upgrade](./docs/v8_upgrade.md) for upgrading from the v7 release.\n- See [V7 Upgrade](./docs/v7_upgrade.md) for upgrading from the v6 release.\n- See [V6 Upgrade](./docs/v6_upgrade.md) for upgrading from v5 or prior v6 releases.\n\n[![Ruby based checks](https://github.com/shakacode/shakapacker/workflows/Ruby%20based%20checks/badge.svg)](https://github.com/shakacode/shakapacker/actions)\n[![Jest specs](https://github.com/shakacode/shakapacker/workflows/Jest%20specs/badge.svg)](https://github.com/shakacode/shakapacker/actions)\n[![Rubocop](https://github.com/shakacode/shakapacker/workflows/Rubocop/badge.svg)](https://github.com/shakacode/shakapacker/actions)\n[![JS lint](https://github.com/shakacode/shakapacker/workflows/JS%20lint/badge.svg)](https://github.com/shakacode/shakapacker/actions)\n\n[![node.js](https://img.shields.io/badge/node-%3E%3D%2012.0.0-brightgreen.svg)](https://www.npmjs.com/package/shakapacker)\n[![Gem](https://img.shields.io/gem/v/shakapacker.svg)](https://rubygems.org/gems/shakapacker)\n[![npm version](https://badge.fury.io/js/shakapacker.svg)](https://badge.fury.io/js/shakapacker)\n\nShakapacker makes it easy to use the JavaScript pre-processor and bundler [Webpack v5+](https://webpack.js.org/)\nto manage frontend JavaScript in Rails. It can coexist with the asset pipeline,\nleaving Webpack responsible solely for frontend JavaScript, or can be used exclusively, making it also responsible for images, fonts, and CSS.\n\nCheck out 6.1.1+ for [SWC](https://swc.rs/) and [esbuild-loader](https://github.com/privatenumber/esbuild-loader) support! They are faster than Babel!\n\nSee a comparison of [Shakapacker with jsbundling-rails](https://github.com/rails/jsbundling-rails/blob/main/docs/comparison_with_webpacker.md). For an in-depth discussion of choosing between `shakapacker` and `jsbundling-rails`, see the discussion [Webpacker alternatives - which path should we go to? #8783](https://github.com/decidim/decidim/discussions/8783) and the resulting PR [Switch away from Webpacker to Shakapacker #10389](https://github.com/decidim/decidim/pull/10389).\n\nFor discussions, see our [Slack Channel](https://reactrails.slack.com/join/shared_invite/enQtNjY3NTczMjczNzYxLTlmYjdiZmY3MTVlMzU2YWE0OWM0MzNiZDI0MzdkZGFiZTFkYTFkOGVjODBmOWEyYWQ3MzA2NGE1YWJjNmVlMGE).\n\n---\n\n## ShakaCode Support\n\n[ShakaCode](https://www.shakacode.com) focuses on helping Ruby on Rails teams use React and Webpack better. We can upgrade your project and improve your development and customer experiences, allowing you to focus on building new features or fixing bugs instead.\n\nFor an overview of working with us, see our [Client Engagement Model](https://www.shakacode.com/blog/client-engagement-model/) article and [how we bill for time](https://www.shakacode.com/blog/shortcut-jira-trello-github-toggl-time-and-task-tracking/).\n\nWe also specialize in helping development teams lower infrastructure and CI costs. Check out our project [Control Plane Flow](https://github.com/shakacode/control-plane-flow/), which can allow you to get the ease of Heroku with the power of Kubernetes and big cost savings.\n\nIf you think ShakaCode can help your project, [click here](https://meetings.hubspot.com/justingordon/30-minute-consultation) to book a call with [Justin Gordon](mailto:justin@shakacode.com), the creator of React on Rails and Shakapacker.\n\nHere's a testimonial of how ShakaCode can help from [Florian Gößler](https://github.com/FGoessler) of [Blinkist](https://www.blinkist.com/), January 2, 2023:\n\n\u003e Hey Justin 👋\n\u003e\n\u003e I just wanted to let you know that we today shipped the webpacker to shakapacker upgrades and it all seems to be running smoothly! Thanks again for all your support and your teams work! 😍\n\u003e\n\u003e On top of your work, it was now also very easy for me to upgrade Tailwind and include our external node_module based web component library which we were using for our other (more modern) apps already. That work is going to be shipped later this week though as we are polishing the last bits of it. 😉\n\u003e\n\u003e Have a great 2023 and maybe we get to work together again later in the year! 🙌\n\nRead the [full review here](https://clutch.co/profile/shakacode#reviews?sort_by=date_DESC#review-2118154).\n\n---\n\n\u003c!-- START doctoc generated TOC please keep comment here to allow auto update --\u003e\n\u003c!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE --\u003e\n\n- [Prerequisites](#prerequisites)\n- [Features](#features)\n  - [Optional support](#optional-support)\n- [Installation](#installation)\n  - [Rails v6+](#rails-v6)\n- [Concepts](#concepts)\n- [Usage](#usage)\n  - [Configuration and Code](#configuration-and-code)\n  - [View Helpers](#view-helpers)\n    - [View Helpers `javascript_pack_tag` and `stylesheet_pack_tag`](#view-helpers-javascript_pack_tag-and-stylesheet_pack_tag)\n    - [View Helpers `append_javascript_pack_tag`, `prepend_javascript_pack_tag` and `append_stylesheet_pack_tag`](#view-helper-append_javascript_pack_tag-prepend_javascript_pack_tag-and-append_stylesheet_pack_tag)\n    - [View Helper: `asset_pack_path`](#view-helper-asset_pack_path)\n    - [View Helper: `image_pack_tag`](#view-helper-image_pack_tag)\n    - [View Helper: `favicon_pack_tag`](#view-helper-favicon_pack_tag)\n    - [View Helper: `preload_pack_asset`](#view-helper-preload_pack_asset)\n  - [Images in Stylesheets](#images-in-stylesheets)\n  - [Server-Side Rendering (SSR)](#server-side-rendering-ssr)\n  - [Development](#development)\n    - [Automatic Webpack Code Building](#automatic-webpack-code-building)\n    - [Compiler strategies](#compiler-strategies)\n    - [Common Development Commands](#common-development-commands)\n  - [Webpack Configuration](#webpack-configuration)\n  - [Babel configuration](#babel-configuration)\n  - [SWC configuration](#swc-configuration)\n  - [esbuild loader configuration](#esbuild-loader-configuration)\n  - [Integrations](#integrations)\n    - [React](#react)\n    - [Typescript](#typescript)\n    - [CSS](#css)\n    - [Postcss](#postcss)\n    - [Sass](#sass)\n    - [Less](#less)\n    - [Stylus](#stylus)\n    - [CoffeeScript](#coffeescript)\n    - [Other frameworks](#other-frameworks)\n  - [Custom Rails environments](#custom-rails-environments)\n  - [Upgrading](#upgrading)\n  - [Paths](#paths)\n  - [Additional paths](#additional-paths)\n- [Deployment](#deployment)\n- [Example Apps](#example-apps)\n- [Troubleshooting](#troubleshooting)\n- [Contributing](#contributing)\n- [License](#license)\n- [Supporters](#supporters)\n\n\u003c!-- END doctoc generated TOC please keep comment here to allow auto update --\u003e\n\n## Prerequisites\n\n- Ruby 2.7+\n- Rails 5.2+\n- Node.js 14+\n\n## Features\n\n- Rails view helpers that fully support Webpack output, including HMR and code splitting.\n- Convenient but not required webpack configuration. The only requirement is that your webpack configuration creates a manifest.\n- HMR with the `shakapacker-dev-server`, such as for hot-reloading React!\n- Automatic code splitting using multiple entry points to optimize JavaScript downloads.\n- Support for [NPM](https://www.npmjs.com/package/npm), Yarn ([classic](https://classic.yarnpkg.com/lang/en/) and [berry](https://yarnpkg.com/getting-started)), [PNPM](https://pnpm.io/), and [Bun](https://bun.sh/)\n- [Webpack v5+](https://webpack.js.org/)\n- ES6 with [babel](https://babeljs.io/), [SWC](https://swc.rs/), or [Esbuild](https://github.com/privatenumber/esbuild-loader)\n- Asset compression, source-maps, and minification\n- CDN support\n- Extensible and configurable. For example, all major dependencies are specified as peers, so you can upgrade easily.\n\n### Optional support\n\n_Requires extra packages to be installed._\n\n- React\n- TypeScript\n- Stylesheets - Sass, Less, Stylus and Css, PostCSS\n- CoffeeScript\n\n## Installation\n\n### Rails v6+\n\nWith Rails v6+, skip JavaScript for a new app and follow below Manual Installation Steps to manually add the `shakapacker` gem to your Gemfile.\n\n```bash\nrails new myapp --skip-javascript\n```\n\n_Note, Rails 6 installs the older v5 version of webpacker unless you specify `--skip-javascript`._\n\nAdd `shakapacker` gem to your `Gemfile`:\n\n```bash\nbundle add shakapacker --strict\n```\n\nThen run the following to install Shakapacker:\n\n```bash\n./bin/bundle install\n./bin/rails shakapacker:install\n```\n\nBefore initiating the installation process, ensure you have committed all the changes. While installing Shakapacker, there might be some conflict between the existing file content and what Shakapacker tries to copy. You can either approve all the prompts for overriding these files or use the `FORCE=true` environment variable before the installation command to force the override without any prompt.\n\nShakapacker uses the [`package_json`](https://github.com/shakacode/package_json) gem to handle updating the `package.json` and interacting with the underlying package manager of choice for managing dependencies and running commands; the package manager is managed using the [`packageManager`](https://nodejs.org/api/packages.html#packagemanager) property in the `package.json`, otherwise falling back to the value of `PACKAGE_JSON_FALLBACK_MANAGER` if set or otherwise `npm`.\n\nIf `packageManager` is not set when running `shakapacker:install`, Shakapacker will set it based on the lockfile and the result of calling `--version` on the inferred manager; if no lockfile is present, then `npm` be used unless you choose to explicitly set the `PACKAGE_JSON_FALLBACK_MANAGER` to your preferred package manager.\n\n\u003e [!NOTE]\n\u003e\n\u003e The `packageManager` property is only used to determine the package manager to use, based primarily on its name.\n\u003e The version (if present) is only used to determine if Yarn Classic or Yarn Berry should be used, but is otherwise\n\u003e _not_ checked, nor is [`corepack`](https://nodejs.org/api/corepack.html) used to ensure that the package manager is installed.\n\u003e\n\u003e It is up to the developer to ensure that the desired package manager is actually install at the right version, which can be done\n\u003e using `corepack` or by other means.\n\nSee [here](https://github.com/G-Rath/package_json#specifying-a-package-manager) for a list of the supported package managers and more information; note that `package_json` does not handle ensuring the manager is installed.\n\nIf you wish to use [Yarn PnP](https://yarnpkg.com/features/pnp) you will need to configure Babel using a `babel.config.js` file rather than via `package.json` - see [customizing Babel Config](./docs/customizing_babel_config.md) for examples on how to do this.\n\n\u003e [!NOTE]\n\u003e\n\u003e The rest of the documentation will only reference `npm` when providing commands such as to install optional packages except in cases where\n\u003e a particular package manager requires a very different command; otherwise it should be safe to just replace `npm` with the name of your\n\u003e preferred package manager when running the command\n\nNote, in v6+, most JS packages are peer dependencies. Thus, the installer will add the packages:\n\n- `@babel/core`\n- `@babel/plugin-transform-runtime`\n- `@babel/preset-env`\n- `@babel/runtime`\n- `babel-loader`\n- `compression-webpack-plugin`\n- `terser-webpack-plugin`\n- `webpack`\n- `webpack-assets-manifest`\n- `webpack-cli`\n- `webpack-merge`\n- `webpack-sources`\n- `webpack-dev-server`\n\nPreviously, these \"webpack\" and \"babel\" packages were direct dependencies for `shakapacker`. By\nmaking these peer dependencies, you have control over the versions used in your webpack and babel configs.\n\n### Optional Peer Dependencies\n\nAll peer dependencies in Shakapacker are marked as optional via `peerDependenciesMeta`. This design decision ensures:\n\n- **No warnings during package installation** when dependencies are not needed\n- **Clear visibility of supported package versions** for upgrades\n- **Flexibility to choose only the tools you need** (webpack vs rspack, babel vs swc vs esbuild)\n\nThe optional peer dependencies approach means you only install what you actually use, while still maintaining\nversion compatibility constraints when you do install those packages.\n\n#### Required Dependencies by Configuration\n\nDepending on your setup, you'll need different subsets of the optional peer dependencies:\n\n**For Webpack + Babel (traditional setup):**\n\n```json\n{\n  \"dependencies\": {\n    \"shakapacker\": \"^9.0.0\",\n    \"@babel/core\": \"^7.17.9\",\n    \"@babel/plugin-transform-runtime\": \"^7.17.0\",\n    \"@babel/preset-env\": \"^7.16.11\",\n    \"@babel/runtime\": \"^7.17.9\",\n    \"babel-loader\": \"^8.2.4\",\n    \"compression-webpack-plugin\": \"^9.0.0\",\n    \"terser-webpack-plugin\": \"^5.3.1\",\n    \"webpack\": \"^5.76.0\",\n    \"webpack-assets-manifest\": \"^5.0.6\",\n    \"webpack-cli\": \"^5.0.0\",\n    \"webpack-dev-server\": \"^5.0.0\"\n  }\n}\n```\n\n**For Webpack + SWC (faster alternative):**\n\n```json\n{\n  \"dependencies\": {\n    \"shakapacker\": \"^9.0.0\",\n    \"@swc/core\": \"^1.3.0\",\n    \"swc-loader\": \"^0.2.0\",\n    \"compression-webpack-plugin\": \"^9.0.0\",\n    \"terser-webpack-plugin\": \"^5.3.1\",\n    \"webpack\": \"^5.76.0\",\n    \"webpack-assets-manifest\": \"^5.0.6\",\n    \"webpack-cli\": \"^5.0.0\",\n    \"webpack-dev-server\": \"^5.0.0\"\n  }\n}\n```\n\n**For Rspack + SWC (10x faster bundling):**\n\n```json\n{\n  \"dependencies\": {\n    \"shakapacker\": \"^9.0.0\",\n    \"@rspack/core\": \"^1.0.0\",\n    \"@rspack/cli\": \"^1.0.0\",\n    \"@swc/core\": \"^1.3.0\",\n    \"swc-loader\": \"^0.2.0\",\n    \"rspack-manifest-plugin\": \"^5.0.0\"\n  }\n}\n```\n\n**Quick tip:** You can easily switch between webpack and rspack using:\n\n```bash\nrails shakapacker:switch_bundler rspack --install-deps\n# or with rake (note the -- separator)\nrake shakapacker:switch_bundler rspack -- --install-deps\n\n# For faster switching, use --no-uninstall to keep both bundlers installed\nrails shakapacker:switch_bundler webpack --install-deps --no-uninstall\n```\n\nSee the [Rspack Migration Guide](./docs/rspack_migration_guide.md) for details.\n\n**For CSS/Sass processing (add to any config above):**\n\n```json\n{\n  \"dependencies\": {\n    \"css-loader\": \"^6.8.1\",\n    \"mini-css-extract-plugin\": \"^2.0.0\",\n    \"sass\": \"^1.50.0\",\n    \"sass-loader\": \"^13.0.0\"\n  }\n}\n```\n\n## Concepts\n\nAt its core, Shakapacker's essential function is to:\n\n1. Provide configuration by a single file used by both Rails view helpers and JavaScript webpack compilation code.\n2. Provide Rails view helpers, utilizing this configuration file so that a webpage can load JavaScript, CSS, and other static assets compiled by webpack, supporting bundle splitting, fingerprinting, and HMR.\n3. Provide a community-supported, default webpack compilation that generates the necessary bundles and manifest, using the same configuration file. This compilation can be extended for any needs.\n\n## Usage\n\n### Configuration and Code\n\nYou will need your file system to correspond to the setup of your `config/shakapacker.yml` file.\n\nSuppose you have the following configuration:\n\n`shakapacker.yml`\n\n```yml\ndefault: \u0026default\n  source_path: app/javascript\n  source_entry_path: packs\n  public_root_path: public\n  public_output_path: packs\n  nested_entries: false\n# And more\n```\n\nAnd that maps to a directory structure like this:\n\n```\napp/javascript:\n  └── packs:               # sets up webpack entries\n  │   └── application.js   # references ../src/my_component.js\n  │   └── application.css\n  └── src:                 # any directory name is fine. Referenced files need to be under source_path\n  │   └── my_component.js\n  └── stylesheets:\n  │   └── my_styles.css\n  └── images:\n      └── logo.svg\npublic/packs                # webpack output\n```\n\nWebpack intelligently includes only necessary files. In this example, the file `packs/application.js` would reference `../src/my_component.js`\n\n`nested_entries` allows you to have webpack entry points nested in subdirectories. This defaults to true as of shakapacker v7. With `nested_entries: false`, you can have your entire `source_path` used for your source (using the `source_entry_path: /`) and you place files at the top level that you want as entry points. `nested_entries: true` allows you to have entries that are in subdirectories. This is useful if you have entries that are generated, so you can have a `generated` subdirectory and easily separate generated files from the rest of your codebase.\n\nTo enable/disable the usage of contentHash in any node environment (specified using the `NODE_ENV` environment variable), add/modify `useContentHash` with a boolean value in `config/shakapacker.yml`. This feature is disabled for all environments except production by default. You may not disable the content hash for a `NODE_ENV` of production as that would break the browser caching of assets. Notice that despite the possibility of enabling this option for the development environment, [it is not recommended](https://webpack.js.org/guides/build-performance/#avoid-production-specific-tooling).\n\n#### Precompile Hook\n\nShakapacker supports running a custom command before webpack compilation via the `precompile_hook` configuration option. This is useful for:\n\n- Dynamically generating entry points (e.g., React on Rails `generate_packs`)\n- Running preparatory tasks before asset compilation in both development and production\n\n```yaml\n# Works in all environments (development, production)\ndefault: \u0026default\n  precompile_hook: \"bin/rails react_on_rails:generate_packs\"\n```\n\nFor complete documentation including React on Rails integration, security features, and troubleshooting, see the [Precompile Hook Guide](docs/precompile_hook.md).\n\n#### Setting custom config path\n\nYou can use the environment variable `SHAKAPACKER_CONFIG` to enforce a particular path to the config file rather than the default `config/shakapacker.yml`.\n\n### View Helpers\n\nThe Shakapacker view helpers generate the script and link tags to get the webpack output onto your views.\n\nBe sure to consult the API documentation in the source code of [helper.rb](./lib/shakapacker/helper.rb).\n\n**Note:** For your styles or static assets files to be available in your view, you would need to link them in your \"pack\" or entry file. Otherwise, Webpack won't know to package up those files.\n\n#### View Helpers `javascript_pack_tag` and `stylesheet_pack_tag`\n\nThese view helpers take your `shakapacker.yml` configuration file and the resulting webpack compilation `manifest.json` and generate the HTML to load the assets.\n\nYou can then link the JavaScript pack in Rails views using the `javascript_pack_tag` helper. If you have styles imported in your pack file, you can link them by using `stylesheet_pack_tag`:\n\n```erb\n\u003c%= javascript_pack_tag 'application' %\u003e\n\u003c%= stylesheet_pack_tag 'application' %\u003e\n```\n\nThe `javascript_pack_tag` and `stylesheet_pack_tag` helpers will include all the transpiled\npacks with the chunks in your view, which creates HTML tags for all the chunks.\n\nYou can provide multiple packs and other attributes. Note, `defer` defaults to showing.\n\n```erb\n\u003c%= javascript_pack_tag 'calendar', 'map', 'data-turbo-track': 'reload' %\u003e\n```\n\nThe resulting HTML would look like this:\n\n```html\n\u003cscript src=\"/packs/vendor-16838bab065ae1e314.js\" data-turbo-track=\"reload\" defer\u003e\u003c/script\u003e\n\u003cscript src=\"/packs/calendar~runtime-16838bab065ae1e314.js\" data-turbo-track=\"reload\" defer\u003e\u003c/script\u003e\n\u003cscript src=\"/packs/calendar-1016838bab065ae1e314.js\" data-turbo-track=\"reload\" defer\"\u003e\u003c/script\u003e\n\u003cscript src=\"/packs/map~runtime-16838bab065ae1e314.js\" data-turbo-track=\"reload\" defer\u003e\u003c/script\u003e\n\u003cscript src=\"/packs/map-16838bab065ae1e314.js\" data-turbo-track=\"reload\" defer\u003e\u003c/script\u003e\n```\n\nIn this output, both the calendar and map codes might refer to other common libraries. Those get placed in something like the vendor bundle. The view helper removes any duplication.\n\nNote, the default of \"defer\" for the `javascript_pack_tag`. You can override that to `false`. If you expose jquery globally with `expose-loader,` by using `import $ from \"expose-loader?exposes=$,jQuery!jquery\"` in your `app/javascript/application.js`, pass the option `defer: false` to your `javascript_pack_tag`.\n\nThe `javascript_pack_tag` also supports the `async` attribute, which you can enable by passing `async: true`:\n\n```erb\n\u003c%= javascript_pack_tag 'application', async: true %\u003e\n```\n\nThis will generate script tags with the `async` attribute, which allows the browser to download and execute the script asynchronously without blocking HTML parsing:\n\n```html\n\u003cscript src=\"/packs/vendor-16838bab065ae1e314.js\" async\u003e\u003c/script\u003e\n\u003cscript src=\"/packs/application~runtime-16838bab065ae1e314.js\" async\u003e\u003c/script\u003e\n\u003cscript src=\"/packs/application-1016838bab065ae1e314.js\" async\u003e\u003c/script\u003e\n```\n\nNote that when using `async: true`, scripts may execute in any order as soon as they're downloaded, which could cause issues if your code has dependencies between files. In most cases, `defer` (the default) is preferred as it maintains execution order.\n\n\u003e [!NOTE]\n\u003e\n\u003e When both `async` and `defer` attributes are specified, `async` takes precedence according to HTML5 specifications. So if you pass both `async: true` and `defer: true`, the script tag will use `async`.\n\n**Important:** Pass all your pack names as multiple arguments, not multiple calls, when using `javascript_pack_tag` and the `stylesheet_pack_tag`. Otherwise, you will get duplicated chunks on the page.\n\n```erb\n\u003c%# DO %\u003e\n\u003c%= javascript_pack_tag 'calendar', 'map' %\u003e\n\n\u003c%# DON'T %\u003e\n\u003c%= javascript_pack_tag 'calendar' %\u003e\n\u003c%= javascript_pack_tag 'map' %\u003e\n```\n\nWhile this also generally applies to `stylesheet_pack_tag`,\nyou may use multiple calls to stylesheet_pack_tag if,\nsay,\nyou require multiple `\u003cstyle\u003e` tags for different output media:\n\n```erb\n\u003c%= stylesheet_pack_tag 'application', media: 'screen' %\u003e\n\u003c%= stylesheet_pack_tag 'print', media: 'print' %\u003e\n```\n\n#### View Helper `append_javascript_pack_tag`, `prepend_javascript_pack_tag` and `append_stylesheet_pack_tag`\n\nIf you need to configure your script pack names or stylesheet pack names from the view for a route or partials, then you will need some logic to ensure you call the helpers only once with multiple arguments. The new view helpers, `append_javascript_pack_tag` and `append_stylesheet_pack_tag` can solve this problem. The helper `append_javascript_pack_tag` will queue up script packs when the `javascript_pack_tag` is finally used. Similarly,`append_stylesheet_pack_tag` will queue up style packs when the `stylesheet_pack_tag` is finally used.\n\nMain view:\n\n```erb\n\u003c% append_javascript_pack_tag 'calendar' %\u003e\n\u003c% append_stylesheet_pack_tag 'calendar' %\u003e\n```\n\nSome partial:\n\n```erb\n\u003c% append_javascript_pack_tag 'map' %\u003e\n\u003c% append_stylesheet_pack_tag 'map' %\u003e\n```\n\nAnd the main layout has:\n\n```erb\n\u003c%= javascript_pack_tag 'application' %\u003e\n\u003c%= stylesheet_pack_tag 'application' %\u003e\n```\n\nis the same as using this in the main layout:\n\n```erb\n\u003c%= javascript_pack_tag 'calendar', 'map', application' %\u003e\n\u003c%= stylesheet_pack_tag 'calendar', 'map', application' %\u003e\n```\n\nHowever, you typically can't do that in the main layout, as the view and partial codes will depend on the route.\n\nThus, you can distribute the logic of what packs are needed for any route. All the magic of splitting up the code and CSS was automatic!\n\n**Important:** These helpers can be used anywhere in your application as long as they are executed BEFORE `(javascript/stylesheet)_pack_tag` respectively. If you attempt to call one of these helpers after the respective `(javascript/stylesheet)_pack_tag`, an error will be raised.\n\nThe typical issue is that your layout might reference some partials that need to configure packs. A good way to solve this problem is to use `content_for` to ensure that the code to render your partial comes before the call to `javascript_pack_tag`.\n\n```erb\n\u003c% content_for :footer do\n   render 'shared/footer' %\u003e\n\n\u003c%= javascript_pack_tag %\u003e\n\n\u003c%= content_for :footer %\u003e\n```\n\nThere is also `prepend_javascript_pack_tag` that will put the entry at the front of the queue. This is handy when you want an entry in the main layout to go before the partial and main layout `append_javascript_pack_tag` entries.\n\nMain view:\n\n```erb\n\u003c% append_javascript_pack_tag 'map' %\u003e\n```\n\nSome partial:\n\n```erb\n\u003c% append_javascript_pack_tag 'map' %\u003e\n```\n\nAnd the main layout has:\n\n```erb\n\u003c% prepend_javascript_pack_tag 'main' %\u003e\n\u003c%= javascript_pack_tag 'application' %\u003e\n```\n\nis the same as using this in the main layout:\n\n```erb\n\u003c%= javascript_pack_tag 'main', 'calendar', 'map', application' %\u003e\n```\n\nFor alternative options for setting the additional packs, [see this discussion](https://github.com/shakacode/shakapacker/issues/39).\n\n#### View Helper: `asset_pack_path`\n\nIf you want to link a static asset for `\u003cimg /\u003e` tag, you can use the `asset_pack_path` helper:\n\n```erb\n\u003cimg src=\"\u003c%= asset_pack_path 'static/logo.svg' %\u003e\" /\u003e\n```\n\n#### View Helper: `image_pack_tag`\n\nOr use the dedicated helper:\n\n```erb\n\u003c%= image_pack_tag 'application.png', size: '16x10', alt: 'Edit Entry' %\u003e\n\u003c%= image_pack_tag 'picture.png', srcset: { 'picture-2x.png' =\u003e '2x' } %\u003e\n```\n\n#### View Helper: `favicon_pack_tag`\n\nIf you want to create a favicon:\n\n```erb\n\u003c%= favicon_pack_tag 'mb-icon.png', rel: 'apple-touch-icon', type: 'image/png' %\u003e\n```\n\n#### View Helper: `preload_pack_asset`\n\nIf you want to preload a static asset in your `\u003chead\u003e`, you can use the `preload_pack_asset` helper:\n\n```erb\n\u003c%= preload_pack_asset 'fonts/fa-regular-400.woff2' %\u003e\n```\n\n### Images in Stylesheets\n\nIf you want to use images in your stylesheets:\n\n```css\n.foo {\n  background-image: url(\"../images/logo.svg\");\n}\n```\n\n### Server-Side Rendering (SSR)\n\nNote, if you are using server-side rendering of JavaScript with dynamic code-splitting, as is often done with extensions to Shakapacker, like [React on Rails](https://github.com/shakacode/react_on_rails), your JavaScript should create the link prefetch HTML tags that you will use, so you won't need to use to `asset_pack_path` in those circumstances.\n\n### Development\n\nShakapacker ships with two binstubs: `./bin/shakapacker` and `./bin/shakapacker-dev-server`. Both are thin wrappers around the standard `webpack.js` and `webpack-dev-server.js` executables to ensure that the right configuration files and environmental variables are loaded based on your environment.\n\n_Note: older Shakapacker installations had set a missing NODE_ENV in the binstubs. Please remove this for versions 6.5.2 and newer._\n\n#### Automatic Webpack Code Building\n\nShakapacker can be configured to automatically compile on demand when needed using `compile` option in the `shakapacker.yml`. This happens when you refer to any of the pack assets using the Shakapacker helper methods. This means that you don't have to run any separate processes. Compilation errors are logged to the standard Rails log. However, this auto-compilation happens when a web request is made that requires an updated webpack build, not when files change. Thus, that can be **painfully slow** for front-end development in this default way. Instead, you should either run the `bin/shakapacker --watch` or run `./bin/shakapacker-dev-server` during development.\n\nThe `compile: true` option can be more useful for test and production builds.\n\n#### Compiler strategies\n\nShakapacker ships with two different strategies that are used to determine whether assets need recompilation per the `compile: true` option:\n\n- `digest` - This strategy calculates SHA1 digest of files in your watched paths (see below). The calculated digest is then stored in a temp file. To check whether the assets need to be recompiled, Shakapacker calculates the SHA1 of the watched files and compares it with the one stored. If the digests are equal, no recompilation occurs. If the digests are different or the temp file is missing, files are recompiled.\n- `mtime` - This strategy looks at the last \"modified at\" timestamps of both files AND directories in your watched paths. The timestamp of the most recent file or directory is then compared with the timestamp of `manifest.json` file generated. If the manifest file timestamp is newer than one of the most recently modified files or directories in the watched paths, no recompilation occurs. If the manifest file is older, files are recompiled.\n\nThe `mtime` strategy is generally faster than the `digest` one, but it requires stable timestamps, this makes it perfect for a development environment, such as needing to rebuild bundles for tests, or if you're not changing frontend assets much.\n\nIn production or CI environments, the `digest` strategy is more suitable, unless you are using incremental builds or caching and can guarantee that the timestamps will not change after e.g. cache restore. However, many production or CI environments will explicitly compile assets, so `compile: false` is more appropriate. Otherwise, you'll waste time either checking file timestamps or computing digests.\n\nYou can control what strategy is used by the `compiler_strategy` option in `shakapacker.yml` config file. By default `mtime` strategy is used in development environment, `digest` is used elsewhere.\n\n\u003e [!NOTE]\n\u003e\n\u003e If you are not using the `shakapacker-dev-server`, your packs will be served by the Rails public file server.\n\u003e If you've enabled caching (Rails application `config.action_controller.perform_caching` setting),\n\u003e your changes will likely not be picked up due to `Cache-Control` header being set and assets being cached in the browser memory.\n\u003e\n\u003e For more details see [issue 88: Caching issues in Development since migrating to Shakapacker](https://github.com/shakacode/shakapacker/issues/88).\n\nIf you want to use live code reloading, or you have enough JavaScript that on-demand compilation is too slow, you'll need to run `./bin/shakapacker-dev-server`. This process will watch for changes in the relevant files, defined by `shakapacker.yml` configuration settings for `source_path`, `source_entry_path`, and `additional_paths`, and it will then automatically reload the browser to match. This feature is also known as [Hot Module Replacement](https://webpack.js.org/concepts/hot-module-replacement/).\n\n#### Common Development Commands\n\n```bash\n# webpack dev server\n./bin/shakapacker-dev-server\n\n# watcher\n./bin/shakapacker --watch --progress\n\n# standalone build\n./bin/shakapacker --progress\n```\n\nOnce you start this webpack development server, Shakapacker will automatically start proxying all webpack asset requests to this server. When you stop this server, Rails will detect that it's not running and Rails will revert back to on-demand compilation _if_ you have the `compile` option set to true in your `config/shakapacker.yml`\n\nYou can use environment variables as options supported by [webpack-dev-server](https://webpack.js.org/configuration/dev-server/) in the form `SHAKAPACKER_DEV_SERVER_\u003cOPTION\u003e`. Please note that these environmental variables will always take precedence over the ones already set in the configuration file, and that the _same_ environmental variables must be available to the `rails server` process.\n\n```bash\nSHAKAPACKER_DEV_SERVER_PORT=4305 SHAKAPACKER_DEV_SERVER_HOST=example.com SHAKAPACKER_DEV_SERVER_INLINE=true SHAKAPACKER_DEV_SERVER_HOT=false ./bin/shakapacker-dev-server\n```\n\nBy default, the webpack dev server listens on `localhost:3035` in development for security purposes. However, if you want your app to be available on port 4035 over local LAN IP or a VM instance like vagrant, you can set the `port` and `host` when running `./bin/shakapacker-dev-server` binstub:\n\n```bash\nSHAKAPACKER_DEV_SERVER_PORT=4305 SHAKAPACKER_DEV_SERVER_HOST=0.0.0.0 ./bin/shakapacker-dev-server\n```\n\n**Note:** You need to allow webpack-dev-server host as an allowed origin for `connect-src` if you are running your application in a restrict CSP environment (like Rails 5.2+). This can be done in Rails 5.2+ in the CSP initializer `config/initializers/content_security_policy.rb` with a snippet like this:\n\n```ruby\nRails.application.config.content_security_policy do |policy|\n  policy.connect_src :self, :https, 'http://localhost:3035', 'ws://localhost:3035' if Rails.env.development?\nend\n```\n\n**Note:** Don't forget to prefix `ruby` when running these binstubs on Windows\n\n### Webpack Configuration\n\nFirst, you don't _need_ to use Shakapacker's webpack configuration. However, the `shakapacker` NPM package provides convenient access to configuration code that reads the `config/shakapacker.yml` file which the view helpers also use. If you have your customized webpack configuration, at the minimum, you must ensure:\n\n1. Your output files go to the right directory\n2. Your output includes a manifest, via package [`webpack-assets-manifest`](https://github.com/webdeveric/webpack-assets-manifest) that maps output names (your 'packs') to the fingerprinted versions, including bundle-splitting dependencies. That's the main secret sauce of Shakapacker!\n\nThe webpack configuration used by Shakapacker lives in `config/webpack/webpack.config.js`; this makes it easy to customize the configuration beyond what's available in `config/shakapacker.yml` by giving you complete control of the final configuration. By default, this file exports the result of `generateWebpackConfig` which handles generating a webpack configuration based on `config/shakapacker.yml`.\n\nThe easiest way to modify this config is to pass your desired customizations to `generateWebpackConfig` which will use [webpack-merge](https://github.com/survivejs/webpack-merge) to merge them with the configuration generated from `config/shakapacker.yml`:\n\n```js\n// config/webpack/webpack.config.js\nconst { generateWebpackConfig } = require(\"shakapacker\")\n\nconst options = {\n  resolve: {\n    extensions: [\".css\", \".ts\", \".tsx\"]\n  }\n}\n\n// This results in a new object copied from the mutable global\nmodule.exports = generateWebpackConfig(options)\n```\n\nThe `shakapacker` package also exports the `merge` function from [webpack-merge](https://github.com/survivejs/webpack-merge) to make it easier to do more advanced customizations:\n\n```js\n// config/webpack/webpack.config.js\nconst { generateWebpackConfig, merge } = require(\"shakapacker\")\n\nconst webpackConfig = generateWebpackConfig()\n\nconst options = {\n  resolve: {\n    extensions: [\".css\", \".ts\", \".tsx\"]\n  }\n}\n\nmodule.exports = merge(options, webpackConfig)\n```\n\nThis example is based on [an example project](https://github.com/shakacode/react_on_rails_tutorial_with_ssr_and_hmr_fast_refresh/blob/master/config/webpack/webpack.config.js)\n\nShakapacker gives you a default configuration file `config/webpack/webpack.config.js`, which, by default, you don't need to make any changes to `config/webpack/webpack.config.js` since it's a standard production-ready configuration. However, you will probably want to customize or add a new loader by modifying the webpack configuration, as shown above.\n\nYou might add separate files to keep your code more organized.\n\n```js\n// config/webpack/custom.js\nmodule.exports = {\n  resolve: {\n    alias: {\n      jquery: \"jquery/src/jquery\",\n      vue: \"vue/dist/vue.js\",\n      React: \"react\",\n      ReactDOM: \"react-dom\",\n      vue_resource: \"vue-resource/dist/vue-resource\"\n    }\n  }\n}\n```\n\nThen `require` this file in your `config/webpack/webpack.config.js`:\n\n```js\n// config/webpack/webpack.config.js\n// use the new NPM package name, `shakapacker`.\nconst { generateWebpackConfig } = require(\"shakapacker\")\n\nconst customConfig = require(\"./custom\")\n\nmodule.exports = generateWebpackConfig(customConfig)\n```\n\nIf you need access to configs within Shakapacker's configuration, you can import them like so:\n\n```js\n// config/webpack/webpack.config.js\nconst { generateWebpackConfig } = require(\"shakapacker\")\n\nconst webpackConfig = generateWebpackConfig()\n\nconsole.log(webpackConfig.output_path)\nconsole.log(webpackConfig.source_path)\n\n// Or to print out your whole webpack configuration\nconsole.log(JSON.stringify(webpackConfig, undefined, 2))\n```\n\nYou may want to modify the rules in the default configuration. For instance, if you are using a custom svg loader, you may want to remove `.svg` from the default file loader rules. You can search and filter the default rules like so:\n\n```js\nconst fileRule = config.module.rules.find((rule) =\u003e rule.test.test(\".svg\"))\n// removing svg from asset file rule's test RegExp\nfileRule.test =\n  /\\.(bmp|gif|jpe?g|png|tiff|ico|avif|webp|eot|otf|ttf|woff|woff2)$/\n// changing the rule type from 'asset/resource' to 'asset'. See https://webpack.js.org/guides/asset-modules/\nfileRule.type = \"asset\"\n```\n\n### Babel configuration\n\nBy default, you will find the Shakapacker preset in your `package.json`. Note, you need to use the new NPM package name, `shakapacker`.\n\n```json\n\"babel\": {\n  \"presets\": [\n    \"./node_modules/shakapacker/package/babel/preset.js\"\n  ]\n},\n```\n\nOptionally, you can change your Babel configuration by removing these lines in your `package.json` and adding [a Babel configuration file](https://babeljs.io/docs/en/config-files) to your project. For an example of customization based on the original, see [Customizing Babel Config](./docs/customizing_babel_config.md).\n\n### SWC configuration\n\nYou can try out experimental integration with the SWC loader. You can read more at [SWC usage docs](./docs/using_swc_loader.md).\n\nPlease note that if you want opt-in to use SWC, you can skip [React](#react) integration instructions as it is supported out of the box.\n\n### esbuild loader configuration\n\nYou can try out experimental integration with the esbuild-loader. You can read more at [esbuild-loader usage docs](./docs/using_esbuild_loader.md).\n\nPlease note that if you want opt-in to use esbuild-loader, you can skip [React](#react) integration instructions as it is supported out of the box.\n\n### Switching between transpilers\n\nTo switch between Babel, SWC, or esbuild, or to configure environment-specific transpiler settings, see the [Transpiler Migration Guide](./docs/transpiler-migration.md).\n\n### Debugging Configuration\n\nShakapacker provides a powerful utility to export and analyze your webpack/rspack configuration:\n\n```bash\n# Export all configs for troubleshooting (recommended)\nbin/export-bundler-config --doctor\n\n# Or via rake task\nbundle exec rake shakapacker:export_bundler_config -- --doctor\n```\n\nThis exports development and production configurations for both client and server bundles to `shakapacker-config-exports/` directory in annotated YAML format. Perfect for:\n\n- Debugging configuration issues\n- Comparing webpack vs rspack configs (works with `rake shakapacker:switch_bundler`)\n- Understanding differences between development and production\n- Analyzing client vs server bundle configurations\n\nFor more options and usage examples, see the [Troubleshooting Guide](./docs/troubleshooting.md#exporting-webpack--rspack-configuration).\n\n### Integrations\n\nShakapacker out of the box supports JS and static assets (fonts, images etc.) compilation. To enable support for CoffeeScript or TypeScript install relevant packages:\n\n#### React\n\nSee here for detailed instructions on how to [configure Shakapacker to bundle a React app](./docs/react.md) (with optional HMR).\n\nSee also [Customizing Babel Config](./docs/customizing_babel_config.md) for an example React configuration.\n\n#### TypeScript\n\n**📚 TypeScript Support:** See the **[TypeScript Documentation](./docs/typescript.md)** for type-safe configuration.\n\n```bash\nnpm install typescript @babel/preset-typescript\n```\n\nBabel won't perform any type-checking on TypeScript code. To optionally use type-checking run:\n\n```bash\nnpm install fork-ts-checker-webpack-plugin\n```\n\nAdd tsconfig.json\n\n```json\n{\n  \"compilerOptions\": {\n    \"declaration\": false,\n    \"emitDecoratorMetadata\": true,\n    \"experimentalDecorators\": true,\n    \"lib\": [\"es6\", \"dom\"],\n    \"module\": \"es6\",\n    \"moduleResolution\": \"node\",\n    \"sourceMap\": true,\n    \"target\": \"es5\",\n    \"jsx\": \"react\",\n    \"noEmit\": true\n  },\n  \"exclude\": [\"**/*.spec.ts\", \"node_modules\", \"vendor\", \"public\"],\n  \"compileOnSave\": false\n}\n```\n\nThen modify the webpack config to use it as a plugin:\n\n```js\n// config/webpack/webpack.config.js\nconst { generateWebpackConfig } = require(\"shakapacker\")\nconst ForkTSCheckerWebpackPlugin = require(\"fork-ts-checker-webpack-plugin\")\n\nmodule.exports = generateWebpackConfig({\n  plugins: [new ForkTSCheckerWebpackPlugin()]\n})\n```\n\nOptionally, your webpack config file itself can be written in Typescript:\n\n```bash\nnpm install ts-node @types/node @types/webpack\n```\n\n```ts\n// config/webpack/webpack.config.ts\nimport { generateWebpackConfig } from \"shakapacker\"\nimport ForkTSCheckerWebpackPlugin from \"fork-ts-checker-webpack-plugin\"\n\nconst config = generateWebpackConfig({\n  plugins: [new ForkTSCheckerWebpackPlugin()]\n})\n\nexport default config\n```\n\n#### CSS\n\nTo enable CSS support in your application, add the following packages:\n\n```bash\nnpm install css-loader style-loader mini-css-extract-plugin css-minimizer-webpack-plugin\n```\n\nOptionally, add the `CSS` extension to webpack config for easy resolution.\n\n```js\n// config/webpack/webpack.config.js\nconst { generateWebpackConfig } = require(\"shakapacker\")\n\nconst customConfig = {\n  resolve: {\n    extensions: [\".css\"]\n  }\n}\n\nmodule.exports = generateWebpackConfig(customConfig)\n```\n\nTo enable `PostCSS`, `Sass` or `Less` support, add `CSS` support first and\nthen add the relevant pre-processors:\n\n#### Postcss\n\n```bash\nnpm install postcss postcss-loader\n```\n\nOptionally add these two plugins if they are required in your `postcss.config.js`:\n\n```bash\nnpm install postcss-preset-env postcss-flexbugs-fixes\n```\n\n#### Sass\n\n```bash\nnpm install sass-loader\n```\n\nYou will also need to install [Dart Sass](https://github.com/sass/dart-sass), [Node Sass](https://github.com/sass/node-sass) or [Sass Embedded](https://github.com/sass/embedded-host-node) to pick the implementation to use. sass-loader will automatically pick an implementation based on installed packages.\n\nPlease refer to [sass-loader documentation](https://www.npmjs.com/package/sass-loader) and individual packages repos for more information on all the options.\n\n##### Dart Sass\n\n```bash\nnpm install sass\n```\n\n##### Node Sass\n\n```bash\nnpm install node-sass\n```\n\n##### Sass Embedded\n\n```bash\nnpm install sass-embedded\n```\n\n#### Less\n\n```bash\nnpm install less less-loader\n```\n\n#### Stylus\n\n```bash\nnpm install stylus stylus-loader\n```\n\n#### CoffeeScript\n\n```bash\nnpm install coffeescript coffee-loader\n```\n\n#### Other frameworks\n\nPlease follow Webpack integration guide for the relevant framework or library,\n\n1. [Svelte](https://github.com/sveltejs/svelte-loader#install)\n2. [Angular](https://v2.angular.io/docs/ts/latest/guide/webpack.html#!#configure-webpack)\n3. [Vue](https://vue-loader.vuejs.org/guide/)\n\nFor example to add Vue support:\n\n```js\n// config/webpack/rules/vue.js\nconst { VueLoaderPlugin } = require(\"vue-loader\")\n\nmodule.exports = {\n  module: {\n    rules: [\n      {\n        test: /\\.vue$/,\n        loader: \"vue-loader\"\n      }\n    ]\n  },\n  plugins: [new VueLoaderPlugin()],\n  resolve: {\n    extensions: [\".vue\"]\n  }\n}\n```\n\n```js\n// config/webpack/webpack.config.js\nconst { generateWebpackConfig, merge } = require(\"shakapacker\")\n\nconst webpackConfig = generateWebpackConfig()\n\nconst vueConfig = require(\"./rules/vue\")\n\nmodule.exports = merge(vueConfig, webpackConfig)\n```\n\n### Custom Rails environments\n\nOut of the box Shakapacker ships with - development, test and production environments in `config/shakapacker.yml` however, in most production apps extra environments are needed as part of the deployment workflow. Shakapacker supports this out of the box from version 3.4.0+ onwards.\n\nYou can choose to define additional environment configurations in shakapacker.yml,\n\n```yml\nstaging:\n  \u003c\u003c: *default\n\n  # Production depends on precompilation of packs prior to booting for performance.\n  compile: false\n\n  # Cache manifest.json for performance\n  cache_manifest: true\n\n  # Compile staging packs to a separate directory\n  public_output_path: packs-staging\n```\n\nOtherwise, Shakapacker will use the production environment as a fallback environment for loading configurations. Please note, `NODE_ENV` can either be set to `production`, `development` or `test`. This means you don't need to create additional environment files inside `config/shakapacker/*` and instead use shakapacker.yml to load different configurations using `RAILS_ENV`.\n\nFor example, the below command will compile assets in production mode but will use staging configurations from `config/shakapacker.yml` if available or use fallback production environment configuration:\n\n```bash\nRAILS_ENV=staging bundle exec rails assets:precompile\n```\n\nAnd, this will compile in development mode and load configuration for the cucumber environment if defined in `shakapacker.yml` or fallback to production configuration\n\n```bash\nRAILS_ENV=cucumber NODE_ENV=development bundle exec rails assets:precompile\n```\n\nPlease note, binstubs compiles in development mode however rake tasks compiles in production mode.\n\n```bash\n# Compiles in development mode unless NODE_ENV is specified, per the binstub source\n./bin/shakapacker\n./bin/shakapacker-dev-server\n\n# Compiles in production mode by default unless NODE_ENV is specified, per `lib/tasks/shakapacker/compile.rake`\nbundle exec rails assets:precompile\nbundle exec rails shakapacker:compile\n```\n\n### Upgrading\n\nYou can run the following commands to upgrade Shakapacker to the latest stable version. This process involves upgrading the gem and related JavaScript packages:\n\n```bash\n# check your Gemfile for version restrictions\nbundle update shakapacker\n\n# overwrite your changes to the default install files and revert any unwanted changes from the install\nrails shakapacker:install\n\n# using npm\nnpm install shakapacker@latest\nnpm install webpack-dev-server@latest\n\n# using yarn classic\nyarn upgrade shakapacker --latest\nyarn upgrade webpack-dev-server --latest\n\n# using yarn berry\nyarn up shakapacker@latest\nyarn up webpack-dev-server@latest\n\n# using pnpm\npnpm up shakapacker@latest\npnpm up webpack-dev-server@latest\n\n# Or to install the latest release (including pre-releases)\nnpm install shakapacker@next\n```\n\nAlso, consult the [CHANGELOG](./CHANGELOG.md) for additional upgrade links.\n\n#### Common Upgrade Scenarios\n\nFor step-by-step guides on common migrations, see the [Common Upgrades Guide](./docs/common-upgrades.md):\n\n- [Migrating Package Managers](./docs/common-upgrades.md#migrating-package-managers) (Yarn ↔ npm, pnpm)\n- [Migrating from Babel to SWC](./docs/common-upgrades.md#migrating-from-babel-to-swc) (20-70x faster builds)\n- [Migrating from Webpack to Rspack](./docs/common-upgrades.md#migrating-from-webpack-to-rspack) (5-10x faster builds)\n\n### Paths\n\nBy default, Shakapacker ships with simple conventions for where the JavaScript app files and compiled webpack bundles will go in your Rails app. All these options are configurable from `config/shakapacker.yml` file.\n\nThe configuration for what webpack is supposed to compile by default rests on the convention that every file in `app/javascript/`**(default)** or whatever path you set for `source_entry_path` in the `shakapacker.yml` configuration is turned into their own output files (or entry points, as webpack calls it). Therefore you don't want to put any file inside `app/javascript` directory that you do not want to be an entry file. As a rule of thumb, put all files you want to link in your views inside \"app/javascript/\" directory and keep everything else under subdirectories like `app/javascript/controllers`.\n\nSuppose you want to change the source directory from `app/javascript` to `frontend` and output to `assets/packs`. This is how you would do it:\n\n```yml\n# config/shakapacker.yml\nsource_path: frontend # packs are the files in frontend/\npublic_output_path: assets/packs # outputs to =\u003e public/assets/packs\n```\n\nFor server-side rendering (SSR) scenarios where you need to generate bundles that should not be served publicly, you can use the `private_output_path` configuration:\n\n```yml\n# config/shakapacker.yml\nprivate_output_path: ssr-generated # outputs to =\u003e ssr-generated/\n```\n\nThis is particularly useful when working with libraries like React on Rails where server bundles need to be kept separate from client bundles.\n\n#### Migration Guide for React on Rails Users\n\nIf you're using React on Rails with separate client and server bundles, you can now leverage the `private_output_path` configuration instead of using custom webpack configurations:\n\n1. Update your `config/shakapacker.yml`:\n\n   ```yml\n   # Before: both client and server bundles in public/\n   # After: separate directories\n   public_output_path: packs # Client bundles (publicly served)\n   private_output_path: ssr-bundles # Server bundles (not publicly served)\n   ```\n\n2. Update your webpack configuration to use the appropriate output path based on the bundle type\n3. The validation ensures `private_output_path` and `public_output_path` are different to prevent configuration errors\n\nSimilarly, you can also control and configure `webpack-dev-server` settings from `config/shakapacker.yml` file:\n\n```yml\n# config/shakapacker.yml\ndevelopment:\n  dev_server:\n    host: localhost\n    port: 3035\n```\n\nIf you have `hmr` turned to true and `inline_css` is not false, then the `stylesheet_pack_tag` generates no output, as you will want to configure your styles to be inlined in your JavaScript for hot reloading. During production and testing, the `stylesheet_pack_tag` will create the appropriate HTML tags.\n\nIf you want to have HMR and separate link tags, set `hmr: true` and `inline_css: false`. This will cause styles to be extracted and reloaded with the `mini-css-extract-plugin` loader. Note that in this scenario, you do not need to include style-loader in your project dependencies.\n\n### Additional paths\n\nIf you are adding Shakapacker to an existing app that has most of the assets inside `app/assets` or inside an engine, and you want to share that with webpack modules, you can use the `additional_paths` option available in `config/shakapacker.yml`. This lets you\nadd additional paths that webpack should look up when resolving modules:\n\n```yml\nadditional_paths: [\"app/assets\", \"vendor/assets\"]\n```\n\nYou can then import these items inside your modules like so:\n\n```js\n// Note it's relative to parent directory i.e. app/assets\nimport \"stylesheets/main\"\nimport \"images/rails.png\"\n```\n\nAssets put in these folders will also have their path stripped just like with the `source_path`.\n\nExample:\n\nA file in `app/assets/images/image.svg` with `additional_paths: ['app/assets']` will result in `static/images/image.svg`\n\n**Note:** Please be careful when adding paths here otherwise it will make the compilation slow, consider adding specific paths instead of the whole parent directory if you just need to reference one or two modules\n\n**Also note:** While importing assets living outside your `source_path` defined in shakapacker.yml (like, for instance, assets under `app/assets`) from within your packs using _relative_ paths like `import '../../assets/javascripts/file.js'` will work in development, Shakapacker won't recompile the bundle in production unless a file that lives in one of it's watched paths has changed (check out `Shakapacker::MtimeStrategy#latest_modified_timestamp` or `Shakapacker::DigestStrategy#watched_files_digest` depending on strategy configured by `compiler_strategy` option in `shakapacker.yml`). That's why you'd need to add `app/assets` to the additional_paths as stated above and use `import 'javascripts/file.js'` instead.\n\n## Deployment\n\nShakapacker hooks up a new `shakapacker:compile` task to `assets:precompile`, which gets run whenever you run `assets:precompile`. If you are not using Sprockets, `shakapacker:compile` is automatically aliased to `assets:precompile`. Similar to sprockets both rake tasks will compile packs in production mode but will use `RAILS_ENV` to load configuration from `config/shakapacker.yml` (if available).\n\nThis behavior is optional \u0026 can be disabled by either setting a `SHAKAPACKER_PRECOMPILE` environment variable to `false`, `no`, `n`, or `f`, or by setting a `shakapacker_precompile` key in your `shakapacker.yml` to `false`. ([source code](./lib/shakapacker/configuration.rb#L34))\n\nWhen compiling assets for production on a remote server, such as a continuous integration environment, it's recommended to ensure the exact versions specified in your lockfile are installed:\n\n```\n# using npm\nnpm ci\n\n# using yarn classic\nyarn install --frozen-lockfile\n\n# using yarn berry\nyarn install --immutable\n\n# using pnpm\npnpm install --frozen-lockfile\n\n# using bun\nbun install --frozen-lockfile\n```\n\n### CDN\n\nShakapacker supports serving JavaScript bundles and assets from a CDN. The key configuration is setting the `SHAKAPACKER_ASSET_HOST` environment variable (NOT the Rails `ASSET_HOST` variable).\n\nFor detailed CDN setup instructions, including CloudFlare configuration, troubleshooting, and advanced setups, see the [CDN Setup Guide](./docs/cdn_setup.md).\n\n**Quick example:**\n\n```bash\nexport SHAKAPACKER_ASSET_HOST=https://cdn.example.com\nRAILS_ENV=production bundle exec rails assets:precompile\n```\n\nFor more deployment documentation, see [Deployment](./docs/deployment.md).\n\n## Example Apps\n\n- [React on Rails Tutorial With SSR, HMR fast refresh, and TypeScript](https://github.com/shakacode/react_on_rails_tutorial_with_ssr_and_hmr_fast_refresh)\n\n## Troubleshooting\n\nSee the doc page for [Troubleshooting](./docs/troubleshooting.md).\n\n## Contributing\n\nWe encourage you to contribute to Shakapacker! See [CONTRIBUTING](CONTRIBUTING.md) for guidelines about how to proceed. We have a [Slack discussion channel](https://reactrails.slack.com/join/shared_invite/enQtNjY3NTczMjczNzYxLTlmYjdiZmY3MTVlMzU2YWE0OWM0MzNiZDI0MzdkZGFiZTFkYTFkOGVjODBmOWEyYWQ3MzA2NGE1YWJjNmVlMGE).\n\n## License\n\nShakapacker is released under the [MIT License](https://opensource.org/licenses/MIT).\n\n## Supporters\n\nThe following companies support our Open Source projects, and ShakaCode uses their products!\n\n\u003cbr /\u003e\n\u003cbr /\u003e\n\n\u003ca href=\"https://jb.gg/OpenSource\" style=\"margin-right: 20px;\"\u003e\n  \u003cimg src=\"https://resources.jetbrains.com/storage/products/company/brand/logos/jetbrains.png\" alt=\"JetBrains\" height=\"120px\"\u003e\n\u003c/a\u003e\n\u003ca href=\"https://scoutapp.com\"\u003e\n  \u003cpicture\u003e\n    \u003csource media=\"(prefers-color-scheme: dark)\" srcset=\"https://user-images.githubusercontent.com/4244251/184881147-0d077438-3978-40da-ace9-4f650d2efe2e.png\"\u003e\n    \u003csource media=\"(prefers-color-scheme: light)\" srcset=\"https://user-images.githubusercontent.com/4244251/184881152-9f2d8fba-88ac-4ba6-873b-22387f8711c5.png\"\u003e\n    \u003cimg alt=\"ScoutAPM\" src=\"https://user-images.githubusercontent.com/4244251/184881152-9f2d8fba-88ac-4ba6-873b-22387f8711c5.png\" height=\"120px\"\u003e\n  \u003c/picture\u003e\n\u003c/a\u003e\n\u003ca href=\"https://shakacode.controlplane.com\"\u003e\n  \u003cpicture\u003e\n    \u003cimg alt=\"Control Plane\" src=\"https://github.com/shakacode/.github/assets/20628911/90babd87-62c4-4de3-baa4-3d78ef4bec25\" height=\"120px\"\u003e\n  \u003c/picture\u003e\n\u003c/a\u003e\n\u003cbr /\u003e\n\u003ca href=\"https://www.browserstack.com\"\u003e\n  \u003cpicture\u003e\n    \u003csource media=\"(prefers-color-scheme: dark)\" srcset=\"https://user-images.githubusercontent.com/4244251/184881122-407dcc29-df78-4b20-a9ad-f597b56f6cdb.png\"\u003e\n    \u003csource media=\"(prefers-color-scheme: light)\" srcset=\"https://user-images.githubusercontent.com/4244251/184881129-e1edf4b7-3ae1-4ea8-9e6d-3595cf01609e.png\"\u003e\n    \u003cimg alt=\"BrowserStack\" src=\"https://user-images.githubusercontent.com/4244251/184881129-e1edf4b7-3ae1-4ea8-9e6d-3595cf01609e.png\" height=\"55px\"\u003e\n  \u003c/picture\u003e\n\u003c/a\u003e\n\u003ca href=\"https://railsautoscale.com\"\u003e\n  \u003cimg src=\"https://user-images.githubusercontent.com/4244251/184881144-95c2c25c-9879-4069-864d-4e67d6ed39d2.png\" alt=\"Rails Autoscale\" height=\"55px\"\u003e\n\u003c/a\u003e\n\u003ca href=\"https://www.honeybadger.io\"\u003e\n  \u003cimg src=\"https://user-images.githubusercontent.com/4244251/184881133-79ee9c3c-8165-4852-958e-31687b9536f4.png\" alt=\"Honeybadger\" height=\"55px\"\u003e\n\u003c/a\u003e\n\u003ca href=\"https://reviewable.io\"\u003e\n  \u003cimg src=\"https://user-images.githubusercontent.com/20628911/230848305-c94510a4-82d7-468f-bf9f-eeb81d3f2ce0.png\" alt=\"Reviewable\" height=\"55px\"\u003e\n\u003c/a\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshakacode%2Fshakapacker","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fshakacode%2Fshakapacker","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshakacode%2Fshakapacker/lists"}