Uses Ruby2JS to convert .js.rb files into .js files for Webpack
npm install @ruby2js/webpack-loader[![npm][npm]][npm-url]
[![node][node]][node-url]
Webpack loader to compile Ruby2JS (.js.rb) files to JavaScript.
Fun fact: this loader itself is written in Ruby and compiles via Ruby2JS + Babel. 😁
``bash`
npm install --save-dev @ruby2js/webpack-loaderor
yarn add -D @ruby2js/webpack-loader
* 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.
There are multiple ways to configure webpack (e.g., webpack.config.js,rb2js.config.rb
command line options, or using the
node interface. Ruby2JS options can be
placed inline within this configuration, or separately in a RUBY2JS_OPTIONS
file or provided via a environment variable. Examples of
each are provided below:
`javascript
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']
}
},
]
},
]
}
}
`
`ruby
require "ruby2js/filter/functions"
module Ruby2JS
class Loader
def self.options
{eslevel: 2021}
end
end
end
`
``
export RUBY2JS_OPTIONS='{"eslevel": 2021, "filters": ["functions"]}'
``
git clone https://github.com/ruby2js/ruby2js.git
cd ruby2js/packages/webpack-loader
yarn install
yarn prepare-release
yarn test
1. Fork it (https://github.com/ruby2js/ruby2js/fork)
2. Create your feature branch (git checkout -b my-new-feature)git commit -am 'Add some feature'
3. Commit your changes ()git push origin my-new-feature`)
4. Push to the branch (
5. Create a new Pull Request
MIT
[npm]: https://img.shields.io/npm/v/@ruby2js/webpack-loader.svg
[npm-url]: https://npmjs.com/package/@ruby2js/webpack-loader
[node]: https://img.shields.io/node/v/@ruby2js/webpack-loader.svg
[node-url]: https://nodejs.org