@ruby2js/webpack-loader
v2.0.2
Published
Uses Ruby2JS to convert .js.rb files into .js files for Webpack
Downloads
10
Readme
@ruby2js/webpack-loader
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
- Fork it (https://github.com/ruby2js/ruby2js/fork)
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request
License
MIT