Skip to content

Support PNPM #181

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ You develop using this approach by running the bundler in watch mode in a termin

Whenever the bundler detects changes to any of the JavaScript files in your project, it'll bundle `app/javascript/application.js` into `app/assets/builds/application.js` (and all other entry points configured). You can refer to the build output in your layout using the standard asset pipeline approach with `<%= javascript_include_tag "application", defer: true %>`.

When you deploy your application to production, the `javascript:build` task attaches to the `assets:precompile` task to ensure that all your package dependencies from `package.json` have been installed via your javascript package manager (bun or yarn), and then runs the build script defined in `package.json` to process all the entry points, as it would in development. The latter files are then picked up by the asset pipeline, digested, and copied into public/assets, as any other asset pipeline file.
When you deploy your application to production, the `javascript:build` task attaches to the `assets:precompile` task to ensure that all your package dependencies from `package.json` have been installed via your javascript package manager ([bun](https://bun.sh), [npm](https://www.npmjs.com), [pnpm](https://pnpm.io), or [yarn](https://yarnpkg.com)), and then runs the build script defined in `package.json` to process all the entry points, as it would in development. The latter files are then picked up by the asset pipeline, digested, and copied into public/assets, as any other asset pipeline file.

This also happens in testing where the bundler attaches to the `test:prepare` task to ensure the JavaScript has been bundled before testing commences. If your testing library of choice does not call the `test:prepare` Rake task, ensure that your test suite runs `javascript:build` to bundle JavaScript before testing commences.

Expand All @@ -19,8 +19,7 @@ If you're already using [`webpacker`](https://github.com/rails/webpacker) and yo
If you want to use webpack features like [code splitting](https://webpack.js.org/guides/code-splitting/) and [hot module reloading](https://webpack.js.org/concepts/hot-module-replacement/), consider using the official fork of `webpacker`, [`shakapacker`](https://github.com/shakacode/shakapacker).

## Installation
If you are installing esbuild, rollup, or webpack, you must already have node
and yarn installed on your system. You will also need npx version 7.1.0 or later.
If you are installing esbuild, rollup, or webpack, you must already have node installed on your system. You will also need npx version 7.1.0 or later.

If you are using Bun, then you must have the Bun runtime already installed on
your system.
Expand Down
4 changes: 4 additions & 0 deletions lib/tasks/jsbundling/build.rake
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ module Jsbundling
case tool
when :bun then "bun install"
when :yarn then "yarn install"
when :pnpm then "pnpm install"
when :npm then "npm install"
else raise "jsbundling-rails: No suitable tool found for installing JavaScript dependencies"
end
Expand All @@ -35,6 +36,7 @@ module Jsbundling
case tool
when :bun then "bun run build"
when :yarn then "yarn build"
when :pnpm then "pnpm build"
when :npm then "npm run build"
else raise "jsbundling-rails: No suitable tool found for building JavaScript"
end
Expand All @@ -48,9 +50,11 @@ module Jsbundling
case
when File.exist?('bun.lockb') then :bun
when File.exist?('yarn.lock') then :yarn
when File.exist?('pnpm-lock.yaml') then :pnpm
when File.exist?('package-lock.json') then :npm
when tool_exists?('bun') then :bun
when tool_exists?('yarn') then :yarn
when tool_exists?('pnpm') then :pnpm
when tool_exists?('npm') then :npm
end
end
Expand Down