Class: Inertia::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/inertia/configuration.rb

Overview

Stores global configuration options for the Inertia integration.

Examples:

Configure via block

Inertia.configure do |config|
  config.frontend_path = "client"
  config.build_path = "public/dist"
  config.build_on_start = false

  config.dev_server.host = "0.0.0.0"
  config.dev_server.port = 3000
end

Defined Under Namespace

Classes: DevServer

Instance Method Summary collapse

Instance Method Details

#build_on_start=(value) ⇒ Object

Set whether to build frontend assets on server start.

Parameters:

  • value (Boolean)

See Also:



27
28
29
# File 'lib/inertia/configuration.rb', line 27

def build_on_start=(value)
  @build_on_start = value
end

#build_on_start?Boolean

Returns whether frontend assets should be built when the server starts.

Defaults to true in non-development environments.

Returns:

  • (Boolean)


36
37
38
# File 'lib/inertia/configuration.rb', line 36

def build_on_start?
  !!@build_on_start
end

#build_pathPathname?

Returns the configured build output path.

Returns:

  • (Pathname, nil)

See Also:



62
63
64
# File 'lib/inertia/configuration.rb', line 62

def build_path
  @build_path
end

#build_path=(path) ⇒ Object

Note:

This setting should be paired with updating the build.outDir option in your Vite config.

Sets the path where built frontend assets are located.

When set, this overrides the default dist directory inside #frontend_path. The path should be relative to the application root.

Building directly into public/ is not supported because a root-level index.html would intercept all requests to the application's / endpoint. Use a nested directory instead, e.g., public/dist.

Parameters:

  • path (String)

    path relative to the application root

Raises:

  • (ArgumentError)

    if path resolves to the public directory root



78
79
80
81
82
83
84
# File 'lib/inertia/configuration.rb', line 78

def build_path=(path)
  @build_path = Rage.root.join(path)

  if @build_path == Rage.root.join("public")
    raise ArgumentError, "build_path cannot be set to public/; use a nested directory instead, e.g., public/dist"
  end
end

#dev_serverDevServer

Returns the dev server configuration.

Returns:

  • (DevServer)

    the dev server configuration object



89
90
91
# File 'lib/inertia/configuration.rb', line 89

def dev_server
  @dev_server ||= DevServer.new
end

#frontend_pathPathname?

Returns the configured frontend directory path.

Returns:

  • (Pathname, nil)

See Also:



44
45
46
# File 'lib/inertia/configuration.rb', line 44

def frontend_path
  @frontend_path
end

#frontend_path=(path) ⇒ Object

Sets the path to the frontend application directory.

When set, this overrides automatic Vite config detection. The path should be relative to the application root.

Parameters:

  • path (String)

    path relative to the application root



54
55
56
# File 'lib/inertia/configuration.rb', line 54

def frontend_path=(path)
  @frontend_path = Rage.root.join(path)
end