File tree 8 files changed +70
-38
lines changed
8 files changed +70
-38
lines changed Original file line number Diff line number Diff line change 1
- require 'json'
2
-
3
1
Snowpacker . configure do |snowpacker |
4
2
# Where to find the config file
5
- snowpacker . config_file = Rails . root . join ( 'config' , 'snowpack.config.json ' )
3
+ snowpacker . config_file = Rails . root . join ( 'config' , 'snowpack.config.js ' )
6
4
5
+ # Snowpacker will set these values at runtime via `config/snowpack.config.js`
6
+ snowpacker . output_path = "snowpacks" # => /public/snowpacks
7
7
snowpacker . port = "4035"
8
+
9
+ # Currently, snowpack does not support the hostname option as of version 2.6.4
10
+ # Support should be coming in 2.6.5, so until then, this is just a placeholder.
8
11
snowpacker . hostname = "localhost"
9
12
end
10
13
Original file line number Diff line number Diff line change
1
+ const output_path = process . env [ "SNOWPACKER_OUTPUT_PATH" ]
2
+ const port = process . env [ "SNOWPACKER_PORT" ]
3
+
4
+ // not currently supported
5
+ // const hostname = process.env["SNOWPACKER_HOSTNAME"]
6
+
7
+ const scripts = {
8
+ "mount:web_modules" : `mount web_modules --to /${ output_path } ` ,
9
+ "mount:__snowpack__" : `mount __snowpack__ --to /${ output_path } ` ,
10
+ "mount:snowpacks" : `mount app/javascript --to /${ output_path } `
11
+ }
12
+
13
+ const installOptions = {
14
+ NODE_ENV : true
15
+ }
16
+
17
+ const devOptions = {
18
+ port : parseInt ( port , 10 ) ,
19
+ open : "none" ,
20
+ out : "public"
21
+ }
22
+
23
+ const buildOptions = {
24
+ clean : true ,
25
+ baseUrl : "/"
26
+ }
27
+
28
+ module . exports = {
29
+ scripts,
30
+ plugins : [ "@snowpack/plugin-babel" ] ,
31
+ installOptions,
32
+ devOptions,
33
+ buildOptions
34
+ }
35
+
Load Diff This file was deleted.
Original file line number Diff line number Diff line change @@ -2,9 +2,11 @@ module Snowpacker
2
2
class Configuration
3
3
attr_accessor :config_file
4
4
5
+ attr_accessor :output_path
5
6
attr_accessor :port , :hostname
6
7
7
8
def initialize
9
+ @output_path = "snowpacks"
8
10
@port = "4035"
9
11
@hostname = "localhost"
10
12
end
Original file line number Diff line number Diff line change
1
+ module Snowpacker
2
+ class Env
3
+ ENV_PREFIX = "SNOWPACKER" . freeze
4
+
5
+ class << self
6
+ def set_env_variables
7
+ set_env ( "OUTPUT_PATH" , Snowpacker . config . output_path )
8
+ set_env ( "HOSTNAME" , Snowpacker . config . hostname )
9
+ set_env ( "PORT" , Snowpacker . config . port )
10
+ end
11
+
12
+ private
13
+
14
+ def set_env ( env_var , value )
15
+ ENV [ "#{ ENV_PREFIX } _#{ env_var } " ] = value . to_s
16
+ end
17
+ end
18
+ end
19
+ end
Original file line number Diff line number Diff line change 1
1
# frozen_string_literal: true
2
2
3
3
require 'socket'
4
+ require 'snowpacker/env'
4
5
5
6
module Snowpacker
6
7
module Rails
@@ -9,6 +10,7 @@ class Runner
9
10
10
11
def initialize
11
12
@config_file = Snowpacker . config . config_file
13
+ @env = Env . set_env_variables
12
14
13
15
detect_port!
14
16
Original file line number Diff line number Diff line change @@ -9,7 +9,7 @@ class SnowpackerProxy < Rack::Proxy
9
9
def perform_request ( env )
10
10
request = Rack ::Request . new ( env )
11
11
12
- if request . path =~ %r{^/snowpacks} # && dev_server_running?
12
+ if request . path =~ %r{^/snowpacks} && dev_server_running?
13
13
env [ "HTTP_HOST" ] = host_with_port
14
14
env [ 'HTTP_COOKIE' ] = ''
15
15
super ( env )
@@ -25,10 +25,10 @@ def dev_server_running?
25
25
port = Snowpacker . config . port
26
26
connect_timeout = 0.01
27
27
28
- socket . tcp ( host , port , connect_timeout : connect_timeout ) . close
29
- puts "Dev server running"
28
+ Socket . tcp ( host , port , connect_timeout : connect_timeout ) . close
30
29
true
31
- rescue StandardError
30
+ rescue Errno ::ECONNREFUSED
31
+ puts "Snowpacker is not currently running on #{ host_with_port } "
32
32
false
33
33
end
34
34
Original file line number Diff line number Diff line change 2
2
# Where to find the config file
3
3
snowpacker . config_file = Rails . root . join ( 'config' , 'snowpack.config.json' )
4
4
5
- # Where your javascript is located
6
- snowpacker . source_path = Rails . root . join ( 'app' , 'javascript' )
7
- snowpacker . entry_points = [ File . join ( snowpacker . source_path , 'snowpacks' , 'application.js' ) ]
8
-
9
- # Where to output your files to
10
- snowpacker . out = Rails . root . join ( 'snowpacks' )
11
- snowpacker . javascript = File . join ( snowpacker . out , 'javascript' )
12
- snowpacker . stylesheets = File . join ( snowpacker . out , 'stylesheets' )
13
- snowpacker . assets = File . join ( snowpacker . out , 'assets' )
5
+ snowpacker . port = "4035" # Port to run on
6
+ snowpacker . hostname = "localhost" # hostname to use
14
7
end
15
8
You can’t perform that action at this time.
0 commit comments