Skip to content

Commit

Permalink
Add js_config_path option
Browse files Browse the repository at this point in the history
  • Loading branch information
SDRACK committed Oct 9, 2023
1 parent cbacf01 commit 7715c86
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 4 deletions.
4 changes: 3 additions & 1 deletion vite_ruby/default.vite.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{
"additionalEntrypoints": ["~/{assets,fonts,icons,images}/**/*"],
"additionalEntrypoints": [
"~/{assets,fonts,icons,images}/**/*"
],
"assetHost": null,
"assetsDir": "assets",
"autoBuild": false,
Expand Down
7 changes: 6 additions & 1 deletion vite_ruby/lib/vite_ruby/cli/vite.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ def self.executable_options
option(:mode, default: self::DEFAULT_ENV, values: %w[development production test], aliases: ['m'], desc: 'The build mode for Vite')
option(:inspect, desc: 'Run Vite in a debugging session with node --inspect-brk', aliases: ['inspect-brk'], type: :boolean)
option(:trace_deprecation, desc: 'Run Vite in debugging mode with node --trace-deprecation', aliases: ['trace-deprecation'], type: :boolean)
option(:js_config_path, desc: 'Provide path to vite.config.js', aliases: ['c'], type: :string)
end

def self.shared_options
Expand All @@ -15,10 +16,14 @@ def self.shared_options
option(:clobber, desc: 'Clear cache and previous builds', type: :boolean, aliases: %w[clean clear])
end

def call(mode:, args: [], clobber: false, **boolean_opts)
def call(mode:, args: [], clobber: false, js_config_path: nil, **boolean_opts)
ViteRuby.env['VITE_RUBY_MODE'] = mode
ViteRuby.env['VITE_RUBY_JS_CONFIG_PATH'] = js_config_path

ViteRuby.commands.clobber if clobber

boolean_opts.map { |name, value| args << "--#{ name }" if value }

yield(args)
end
end
2 changes: 1 addition & 1 deletion vite_ruby/lib/vite_ruby/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ def config_from_file(path, mode:)
NOT_CONFIGURABLE_WITH_ENV = %w[additional_entrypoints watch_additional_paths].freeze

# Internal: Configuration options that can be provided as env vars.
CONFIGURABLE_WITH_ENV = (DEFAULT_CONFIG.keys + %w[mode root] - NOT_CONFIGURABLE_WITH_ENV).freeze
CONFIGURABLE_WITH_ENV = (DEFAULT_CONFIG.keys + %w[mode root js_config_path] - NOT_CONFIGURABLE_WITH_ENV).freeze

# Internal: If any of these files is modified the build won't be skipped.
DEFAULT_WATCHED_PATHS = %w[
Expand Down
8 changes: 7 additions & 1 deletion vite_ruby/lib/vite_ruby/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,19 @@ def run(argv, exec: false)

# Internal: Returns an Array with the command to run.
def command_for(args)
[config.to_env(env)].tap do |cmd|
env_args = config.to_env(env)

[env_args].tap do |cmd|
args = args.clone

cmd.push('node', '--inspect-brk') if args.delete('--inspect')
cmd.push('node', '--trace-deprecation') if args.delete('--trace_deprecation')
cmd.push(*vite_executable)
cmd.push(*args)
cmd.push('--mode', config.mode) unless args.include?('--mode') || args.include?('-m')
if (config_path = env_args["VITE_RUBY_JS_CONFIG_PATH"])
cmd.push("--config", config_path)
end
end
end

Expand Down

0 comments on commit 7715c86

Please sign in to comment.