Skip to main content

Node Package API

Shakapacker ships a Node package that exposes configuration and helper utilities for both webpack and rspack.

Import Paths

// Webpack entrypoint
const shakapacker = require("shakapacker")

// Rspack entrypoint
const rspack = require("shakapacker/rspack")

Webpack Exports (shakapacker)

ExportTypeDescription
configobjectParsed config/shakapacker.yml plus computed fields
devServerobjectDev server configuration
generateWebpackConfig(extraConfig?)functionGenerates final webpack config and merges optional overrides
baseConfigobjectBase config object from package/environments/base
envobjectEnvironment metadata (railsEnv, nodeEnv, booleans)
rulesarrayLoader rules for current bundler
moduleExists(name)functionReturns whether module can be resolved
canProcess(rule, fn)functionRuns callback only if loader dependency is available
inliningCssbooleanWhether CSS should be inlined in current dev-server mode
merge, mergeWithCustomize, mergeWithRules, uniquefunctionsRe-exported from webpack-merge

Rspack Exports (shakapacker/rspack)

ExportTypeDescription
configobjectParsed config/shakapacker.yml plus computed fields
devServerobjectDev server configuration
generateRspackConfig(extraConfig?)functionGenerates final rspack config and merges optional overrides
baseConfigobjectBase config object
envobjectEnvironment metadata (railsEnv, nodeEnv, booleans)
rulesarrayRspack loader rules
moduleExists(name)functionReturns whether module can be resolved
canProcess(rule, fn)functionRuns callback only if loader dependency is available
inliningCssbooleanWhether CSS should be inlined in current dev-server mode
merge, mergeWithCustomize, mergeWithRules, uniquefunctionsRe-exported from webpack-merge

config Object

config includes:

  • Raw values from config/shakapacker.yml (source_path, public_output_path, javascript_transpiler, etc.)
  • Computed absolute paths (outputPath, publicPath, manifestPath, publicPathWithoutCDN)
  • Optional sections like dev_server and integrity

For the full key list and types, see:

Built-in Third-Party Support

Installer defaults include support for:

  • Bundlers: webpack, rspack
  • JavaScript transpilers: SWC (default), Babel, esbuild
  • Common style/tooling loaders: css, sass, less, stylus, file/raw rules
  • Common optimization/plugins for webpack/rspack production builds

Dependency presets used by the installer are defined in: