Ruby. • A wholesome server-side feast of technology, best spiced with small “sprinkles” of JavaScript? • The perfect server-side compliment for a JavaScript SPA (Single Page Application)? WHAT IS RAILS? mature
a dependency graph of modules an application needs and packages those dependencies into one or more bundles. • Built around Four Core Concepts: entry, output, loaders, plugins. WHAT IS WEBPACK? https://webpack.js.org/concepts/
.jpg e.t.c.) as a potentially valid module. • However, by itself it only understands JavaScript. • Loaders understand these other file formats and transform them into JavaScript modules that Webpack can understand. LOADERS & PLUGINS https://webpack.js.org/concepts/
can perform actions and apply custom functionality to “compilations” or “chunks” of bundled modules. • There many loaders and plugins available. Webpack itself comes with many built-in plugins. LOADERS & PLUGINS https://webpack.js.org/concepts/
Rails and Webpack. • Version 1.0 support shipped with Rails 5.1. Now up to version 3.0.1, and has evolved significantly since 1.0. • Billed as a complement to the asset pipeline, rather than a replacement. https://github.com/rails/webpacker
provided generators: // Creating a new Rails app with webpacker: $ rails new example-app --webpack // There is additional support for setting up popular frameworks: $ rails new example-app --webpack=react $ rails new example-app --webpack=angular $ rails new example-app --webpack=vue $ rails new example-app --webpack=elm // Adding to an existing app: $ bundle exec rails webpacker:install $ bundle exec rails webpacker:install:[react, angular, vue and elm]
in app/javascript/packs is an entry point for webpack. A couple of executables are provided. config/webpack contains webpack configuration information (specifying loaders, plugins e.t.c) webpacker.yml is for webpacker specific configuration .babelrc contains configuration for Babel (JS transpiler) .postcssrc.yml contains configuration for PostCSS (a CSS post processor) Yarn creates a yarn.lock from package.json.
elm-webpack-loader, elm-hot-loader Transpiles Elm rails-erb-loader Compiles and executes ERB files (!!) file-loader Bundles static files (images, font files) and outputs to the bundle with digested filenames style-loader, css-loader, postcss-loader, sass-loader Bundles and transpires SASS/SCSS/CSS ts-loader Transpiles and type checks TypeScript vue-loader Supports transpiling *.vue component files for Vue.js Default webpack loaders for webpacker:
them under process.env.ENV_NAME ExtractTextPlugin all Extracts all compiled CSS into a separate .css file ManifestPlugin all Produces a manifest of output files - used by webpacker to figure out if files have changed. HotModuleReplacementPlugin development (HMR) Part of allowing modules to update in realtime without a page reload. NamedModulesPlugin development (HMR) Used in HMR to allow updated module names to be listed. ModuleConcatenationPlugin production Simplifies the way modules are bundled together, for faster execution performance. UglifyJSPlugin production Uses UglifyJS to minify JavaScript. CompressionPlugin production Produces compressed (e.g. gzipped) versions of assets. Default webpack plugins for webpacker: