Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@ruby2js/vite-plugin

ruby2js5MIT0.0.3

ruby2js plugin for vite

ruby2js, vite, vite-plugin

readme

@ruby2js/vite-plugin

Integration between Vite and Ruby2JS

Description

Since Vite supports both rollup and vite plugins, this plugin can be used interchangeably with the Ruby2JS Rollup plugin with if there the use of a refresh plugin is not needed.

What this plugin does is integrate Ruby2JS with the refresh process. In order to do this, the refresh plugin you would normally use needs to be passed as an option to the Ruby2JS plugin rather than included as a separate plugin. An example of this usage follows below.

Installation

npm install --save-dev @ruby2js/vite-plugin
# or
yarn add -D @ruby2js/vite-plugin

Usage

The following is a example of a vite.config.js file configured for use with the React refresh plugin. Note the addition of .rb and .js.rb extensions to resolve.extensions and the passing of the reactRefresh plugin as a refresh option to the @ruby2js/vite-plugin.

import { defineConfig } from 'vite'
import reactRefresh from '@vitejs/plugin-react-refresh'
import ruby2js from '@ruby2js/vite-plugin';

export default defineConfig({
  resolve: {
    extensions: ['.rb', '.js.rb'].concat(
      ['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json']
    )
  },

  plugins: [
    ruby2js({
      refresh: reactRefresh(),
      eslevel: 2021,
      autoexports: 'default',
      filters: ['react', 'esm', 'functions']
    })
  ]
})

changelog

Changelog

All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.

Unreleased

Breaking Changes

  • Default ES level is now ES2020 - Ruby2JS now defaults to ES2020 instead of ES5. This means output will use modern JavaScript features like let/const, arrow functions, template literals, classes, spread syntax, optional chaining, and nullish coalescing by default. To restore previous behavior, explicitly set eslevel: 2015 or lower.
  • Removed support for ES levels prior to ES2020 as the default target
  • New or option with :auto as default - Ruby's || is now handled based on context:
    • :auto (default): || in boolean contexts, ?? in value contexts
    • :nullish: always use ?? (except for boolean expressions)
    • :logical: always use || This gives the best of both worlds by default - conditions work naturally while assignments preserve 0 and "".
  • Preset now targets ES2022 - The preset option now defaults to ES2022 (was ES2021). ES2022 features include private fields (#x), the at() method, and static class fields.

Changed

  • Update regexp_parser dependency

[5.1.2] - 2024-05-11

  • Fix for super optional args, downcase / upcase string methods [#215]

[5.1.1] - 2024-01-05

  • Don't provide the config file option in a web context

[5.1.0] - 2023-02-20

  • Many filters and other project features deprecated for future maintainability (see blog announcement).
  • The Vite and Rollup JS packages are looking for a new maintainer. Please let us know in the community GitHub Discussions if you'd like to contribute.
  • The Node version of Ruby2JS will require minimum version 14
  • Create a preset option to set sane default behavior [#178]
  • New configuration DSL and per-file magic comments [#182]
  • esbuild: change to use Ruby platform for Ruby2JS compilation [#183]
  • fix haml filter and update spec to include interpolation [#198]

[5.0.1] - 2022-05-14

Fixed

  • Revert back to Opal 1.1.1 for compilation Any newer version of Opal results in compilation errors when emoji (and perhaps other unicode chars) are present in code
  • Ensure Nokogiri filter's create_element uses textContent instead of content

[5.0.0] - 2022-05-14

Added

  • Support for Ruby 3.1's shorthand hash syntax: hash => {a:, b:} => let {a, b} = hash
  • functions filter: chars
  • functions filter: "string" * length => "string".repeat(length) for ES2015+

Changed

  • Improvements to the monorepo to ensure both the Ruby and the Node compiler versions always match and can get tested and released simultaneously. (Run bundle exec rake release_core.)
  • Ruby 2.7 is now the minimum supported version of Ruby.

[4.2.2] - 2021-12-07

  • leave index as a property alone

[4.2.1] - 2021-11-12

  • functions filter: index, rindex, and round
  • functions filter: obj.to_json => JSON.stringify(obj)
  • support numbered parameters (numblocks)
  • Array.new(size, default) => new Array(size).fill(default)

[4.2.0] - 2021-10-11

  • Additional lit filter updates (PR #141)
    • Allow snake case custom_element in addition to customElement
    • Process the render function even when it contains multiple statements
    • Fix a properties vs styles typo for <es2022
    • Automatically add the html tagged literal return when necessary for any method, not just render
    • Ensure any ivars prefixed with _ will not turn into reactive properties (if you truly need to maintain private internal state).
  • ruby2js cli interface added
  • esm autoimports & defs: fix Opal-based parser to handle hash generated by Ruby
  • esm filter: convert top level requires into imports
  • lit filter: updates from polymer LitElement to Lit v2. added: customElements, es2022 syntax for properties, query, queryAll, queryAsync inherited methods: performUpdate, requestUpdate inherited properties: hasUpdated, renderRoot, shadowRoot, updateComplete

[4.1.7] - 2021-09-20

  • take, drop, min, max, each_slice added to underscore filter
  • import stimulus => import @hotwired/stimulus
  • rails stimulus rake tasks and instructions were update to match the latest hotwired/stimulus-rails changes

[4.1.6] - 2021-08-19

  • Fix es2020 optional chaining optimization when arguments are present

[4.1.5] - 2021-08-14

  • Fix camelCase bug on methods ending in ? or !
  • Add chomp, delete_prefix, and delete_suffix support via ActiveFunctions
  • Support React stateless components
  • es2022 at method support
  • fix es2020 bug where operators were converted to optional chaining
  • fix es5 merge regression with complex LHS

[4.1.4] - 2021-05-08

  • Add camelCase support for keyword arguments (aka destructured object arg)

[4.1.3] - 2021-04-11

  • Add camelCase support for => assignment operator
  • Fix bugs related to is_a? and instance_of?

[4.1.2] - 2021-04-11

  • support => as a right side assignment operator
  • sourcemap: add names; add missing first token; fix first column of every line

[4.1.1] - 2021-03-26

  • fix a number of lit-element filter edge cases
  • more cjs export support: constants, classes, modules, autoexports
  • React/Preact hooks

[4.1.0] - 2021-03-17

  • ES2021 support for replaceAll
  • Preact support added to the React filter

[4.0.5] - 2021-03-11

  • move testrails directory outside of the gem

[4.0.4] - 2021-03-10

  • add install tasks for Webpacker (naked) and React

[4.0.3] - 2021-03-09

  • don't autobind instance methods within tagged literals
  • rails install tasks

[4.0.2] - 2021-03-02

  • next within a block can return a value
  • handle scans that return zero results with ESLevel < 2020
  • redo
  • add rand to filter functions
  • sprockets support

[4.0.1] - 2021-02-23

  • handle block arguments
  • filter now supports .call, but requires an explicit include option
  • require with esm now always produces relative path links
  • support added for is_a? kind_of and instance_of?
  • provide default for all optional kwargs; handle undefined as default
  • pin version of regexp_parser pending resolution of #101

[4.0.0] - 2021-02-10

  • Support static method calls with blocks in es2015+
  • Auto-bind instance methods referenced as properties within a class
  • New defs option to add definitions for autoimported classes/methods
  • Open classes/modules, inheritance, and module include of props/methods
  • Handle begin, if, and case as expressions
  • Handle modules with exactly one method
  • Handle empty edge cases like `#{}` and ()
  • Live demo based on Opal (see here)
  • Demo: Hidden AST syntax enables copy/paste of syntactically correct AST
  • Anonymous classes via Class.new
  • Autoexport :default option
  • Support both default and named imports on same import statement
  • requires for modules containing exports statements generate import statements
  • require_recursive option

[3.6.1] - 2020-12-31

  • Bugfix: ensure ActiveFunctions autoimports aren't included multiple times
  • Chained method bugfix in Nokogiri filter
  • continued demo upgrades (see here)
    • dropdowns and checkbox updates are applied immediately
    • more options supported and increased test coverage
    • auto launch a browser when --port is specified
  • no need for spread syntax for .max and .min if target is a literal array

[3.6.0] - 2020-12-26

  • New project logos!
  • Large overhaul of the Ruby2JS Demo application (see here)
  • New active_functions filter which will provide methods inspired by ActiveSupport
  • The rb2js-loader package has been merged into the repo, now webpack-loader
  • path and os imports added to the node filter
  • Numeric separator support added for ES2021 (aka 10_000_000)
  • method_missing enabled via the Proxy object in ES2015+
  • .sum added to the functions filter
  • Autoimport configuration is now available when using the esm filter