Configure Stimulus with esbuild and Babel — Rails & Javascript

This page summarizes the projects mentioned and recommended in the original post on dev.to

Our great sponsors
  • SurveyJS - Open-Source JSON Form Builder to Create Dynamic Forms Right in Your App
  • InfluxDB - Power Real-Time Data Analytics at Scale
  • WorkOS - The modern identity platform for B2B SaaS
  • jsbundling-rails

    Bundle and transpile JavaScript in Rails with esbuild, rollup.js, or Webpack.

  • Rails applications are bundler-agnostic. They do not care how you bundle your javascript code. It just expects whatever comes from the bundler to be placed under app/assets, so the asset pipeline processes it. We can see this in the official jsbundling-rails gem, which consists of scripts to install different bundlers and configure a default npm build command to generate our bundles—no interaction whatsoever with the Rails configuration. This black-box bundler logic allows us to change and update our bundler system without tuning any other aspect of our Rails application.

  • esbuild-rails

    Esbuild Rails plugin (by excid3)

  • // config/esbuild.mjs import path from 'path' import esbuild from 'esbuild' import rails from 'esbuild-rails' import babel from 'esbuild-plugin-babel' esbuild .build({ bundle: true, // Path to application.js folder absWorkingDir: path.join(process.cwd(), 'app/javascript'), // Application.js file, used by Rails to bundle all JS Rails code entryPoints: ['application.js'], // Destination of JS bundle, points to the Rails JS Asset folder outdir: path.join(process.cwd(), 'app/assets/builds'), // Enables watch option. Will regenerate JS bundle if files are changed watch: process.argv.includes('--watch'), // Split option is disabled, only needed when using multiple input files // More information: https://esbuild.github.io/api/#splitting (change it if using multiple inputs) splitting: false, chunkNames: 'chunks/[name]-[hash]', // Remove unused JS methods treeShaking: true, // Adds mapping information so web browser console can map bundle errors to the corresponding // code line and column in the real code // More information: https://esbuild.github.io/api/#sourcemap sourcemap: process.argv.includes('--development'), // Compresses bundle // More information: https://esbuild.github.io/api/#minify minify: process.argv.includes('--production'), // Removes all console lines from bundle // More information: https://esbuild.github.io/api/#drop drop: process.argv.includes('--production') ? ['console'] : [], // Build command log output: https://esbuild.github.io/api/#log-level logLevel: 'info', // Set of ESLint plugins plugins: [ // Plugin to easily import Rails JS files, such as Stimulus controllers and channels // https://github.com/excid3/esbuild-rails rails(), // Configures bundle with Babel. Babel configuration defined in babel.config.js // Babel translates JS code to make it compatible with older JS versions. // https://github.com/nativew/esbuild-plugin-babel babel() ] }) .catch(() => process.exit(1))

  • SurveyJS

    Open-Source JSON Form Builder to Create Dynamic Forms Right in Your App. With SurveyJS form UI libraries, you can build and style forms in a fully-integrated drag & drop form builder, render them in your JS app, and store form submission data in any backend, inc. PHP, ASP.NET Core, and Node.js.

    SurveyJS logo
  • Stimulus

    A modest JavaScript framework for the HTML you already have

  • Stimulus: A modest JavaScript framework for the HTML you already have.

  • esbuild-plugin-babel

    Discontinued Babel plugin for esbuild.

  • // config/esbuild.mjs import path from 'path' import esbuild from 'esbuild' import rails from 'esbuild-rails' import babel from 'esbuild-plugin-babel' esbuild .build({ bundle: true, // Path to application.js folder absWorkingDir: path.join(process.cwd(), 'app/javascript'), // Application.js file, used by Rails to bundle all JS Rails code entryPoints: ['application.js'], // Destination of JS bundle, points to the Rails JS Asset folder outdir: path.join(process.cwd(), 'app/assets/builds'), // Enables watch option. Will regenerate JS bundle if files are changed watch: process.argv.includes('--watch'), // Split option is disabled, only needed when using multiple input files // More information: https://esbuild.github.io/api/#splitting (change it if using multiple inputs) splitting: false, chunkNames: 'chunks/[name]-[hash]', // Remove unused JS methods treeShaking: true, // Adds mapping information so web browser console can map bundle errors to the corresponding // code line and column in the real code // More information: https://esbuild.github.io/api/#sourcemap sourcemap: process.argv.includes('--development'), // Compresses bundle // More information: https://esbuild.github.io/api/#minify minify: process.argv.includes('--production'), // Removes all console lines from bundle // More information: https://esbuild.github.io/api/#drop drop: process.argv.includes('--production') ? ['console'] : [], // Build command log output: https://esbuild.github.io/api/#log-level logLevel: 'info', // Set of ESLint plugins plugins: [ // Plugin to easily import Rails JS files, such as Stimulus controllers and channels // https://github.com/excid3/esbuild-rails rails(), // Configures bundle with Babel. Babel configuration defined in babel.config.js // Babel translates JS code to make it compatible with older JS versions. // https://github.com/nativew/esbuild-plugin-babel babel() ] }) .catch(() => process.exit(1))

  • esbuild

    An extremely fast bundler for the web

  • // config/esbuild.mjs import path from 'path' import esbuild from 'esbuild' import rails from 'esbuild-rails' import babel from 'esbuild-plugin-babel' esbuild .build({ bundle: true, // Path to application.js folder absWorkingDir: path.join(process.cwd(), 'app/javascript'), // Application.js file, used by Rails to bundle all JS Rails code entryPoints: ['application.js'], // Destination of JS bundle, points to the Rails JS Asset folder outdir: path.join(process.cwd(), 'app/assets/builds'), // Enables watch option. Will regenerate JS bundle if files are changed watch: process.argv.includes('--watch'), // Split option is disabled, only needed when using multiple input files // More information: https://esbuild.github.io/api/#splitting (change it if using multiple inputs) splitting: false, chunkNames: 'chunks/[name]-[hash]', // Remove unused JS methods treeShaking: true, // Adds mapping information so web browser console can map bundle errors to the corresponding // code line and column in the real code // More information: https://esbuild.github.io/api/#sourcemap sourcemap: process.argv.includes('--development'), // Compresses bundle // More information: https://esbuild.github.io/api/#minify minify: process.argv.includes('--production'), // Removes all console lines from bundle // More information: https://esbuild.github.io/api/#drop drop: process.argv.includes('--production') ? ['console'] : [], // Build command log output: https://esbuild.github.io/api/#log-level logLevel: 'info', // Set of ESLint plugins plugins: [ // Plugin to easily import Rails JS files, such as Stimulus controllers and channels // https://github.com/excid3/esbuild-rails rails(), // Configures bundle with Babel. Babel configuration defined in babel.config.js // Babel translates JS code to make it compatible with older JS versions. // https://github.com/nativew/esbuild-plugin-babel babel() ] }) .catch(() => process.exit(1))

  • core-js

    Standard Library

  • const presets = [ [ // Javascript 2015+ syntax transpiler '@babel/preset-env', // Javascript Polyfill { useBuiltIns: 'usage', // Make sure version number matches the Core.js version installed in your project corejs: '3.28.0' } ] ] module.exports = { presets, // Fixes Core-JS $ issue: https://github.com/zloirock/core-js/issues/912 exclude: ['./node_modules'] }

  • browserslist

    🦔 Share target browsers between different front-end tools, like Autoprefixer, Stylelint and babel-preset-env

  • # .browserslist.rc # Babel Preset configuration # -------------------------- # Defines web-browser compatibility parameters for Babel to transpile your JS code. # This configuration is used by babel.config.js. # More information in here. # https://github.com/browserslist/browserslist # Support browsers with a market share higher than 5% >10%

  • InfluxDB

    Power Real-Time Data Analytics at Scale. Get real-time insights from all types of time series data with InfluxDB. Ingest, query, and analyze billions of data points in real-time with unbounded cardinality.

    InfluxDB logo
NOTE: The number of mentions on this list indicates mentions on common posts plus user suggested alternatives. Hence, a higher number means a more popular project.

Suggest a related project

Related posts