@ruby2js/webpack-loader

2.0.2 • Public • Published

@ruby2js/webpack-loader

npm node

Webpack loader to compile Ruby2JS (.js.rb) files to JavaScript.

Fun fact: this loader itself is written in Ruby and compiles via Ruby2JS + Babel. 😁

Installation

npm install --save-dev @ruby2js/webpack-loader
# or
yarn add -D @ruby2js/webpack-loader

Documentation

  • Visit ruby2js.com for detailed instructions and examples. Users of Ruby on Rails may wish to start with the Rails introduction which describes how to use the rake tasks provided to get up and running quickly.

Configuration

There are multiple ways to configure webpack (e.g., webpack.config.js, command line options, or using the node interface. Ruby2JS options can be placed inline within this configuration, or separately in a rb2js.config.rb file or provided via a RUBY2JS_OPTIONS environment variable. Examples of each are provided below:

webpack.config.js

module.exports = {
  entry: "./main.js.rb",

  output: {
    path: __dirname,
    filename: "main.[contenthash].js"
  },

  resolve: {
    extensions: [".rb.js", ".rb"]
  },

  module: {
    rules: [
      {
        test: /\.js\.rb$/,
        use: [
          {
            loader: '@ruby2js/webpack-loader',
            options: {
              eslevel: 2021,
              filters: ['functions']
            }
          },
        ]
      },
    ]
  }
}

rb2js.config.rb

require "ruby2js/filter/functions"

module Ruby2JS
  class Loader
    def self.options
      {eslevel: 2021}
    end
  end
end

RUBY2JS_OPTIONS environment variable

export RUBY2JS_OPTIONS='{"eslevel": 2021, "filters": ["functions"]}'

Testing

git clone https://github.com/ruby2js/ruby2js.git
cd ruby2js/packages/webpack-loader
yarn install
yarn prepare-release
yarn test

Contributing

  1. Fork it (https://github.com/ruby2js/ruby2js/fork)
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

License

MIT

Dependencies (2)

Dev Dependencies (8)

Package Sidebar

Install

npm i @ruby2js/webpack-loader

Weekly Downloads

0

Version

2.0.2

License

MIT

Unpacked Size

7.07 kB

Total Files

8

Last publish

Collaborators

  • rubys
  • jaredwhite