Skip to content

Latest commit

 

History

History

webpack-loader

@ruby2js/webpack-loader

npm node

This package is deprecated and will no longer be supported in future versions of Ruby2JS.

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

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']
            }
          },
        ]
      },
    ]
  }
}

See Ruby2JS Options docs for a list of available options.

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