snowpacker 0.0.4.alpha1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.codeclimate.yml +3 -0
- data/.dockerignore +22 -0
- data/.github/workflows/build.yml +20 -0
- data/.gitignore +65 -0
- data/CHANGELOG.md +28 -0
- data/Dockerfile +38 -0
- data/Gemfile +8 -0
- data/Gemfile.lock +199 -0
- data/LICENSE.txt +21 -0
- data/README.md +156 -0
- data/Rakefile +32 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/docker-compose.yml +17 -0
- data/docker.env +8 -0
- data/examples/rails-without-webpack/.gitignore +34 -0
- data/examples/rails-without-webpack/.ruby-version +1 -0
- data/examples/rails-without-webpack/Gemfile +33 -0
- data/examples/rails-without-webpack/Gemfile.lock +225 -0
- data/examples/rails-without-webpack/README.md +24 -0
- data/examples/rails-without-webpack/Rakefile +6 -0
- data/examples/rails-without-webpack/app/assets/config/manifest.js +2 -0
- data/examples/rails-without-webpack/app/assets/images/.keep +0 -0
- data/examples/rails-without-webpack/app/assets/stylesheets/application.css +15 -0
- data/examples/rails-without-webpack/app/assets/stylesheets/static_pages.scss +3 -0
- data/examples/rails-without-webpack/app/channels/application_cable/channel.rb +4 -0
- data/examples/rails-without-webpack/app/channels/application_cable/connection.rb +4 -0
- data/examples/rails-without-webpack/app/controllers/application_controller.rb +2 -0
- data/examples/rails-without-webpack/app/controllers/concerns/.keep +0 -0
- data/examples/rails-without-webpack/app/controllers/static_pages_controller.rb +4 -0
- data/examples/rails-without-webpack/app/helpers/application_helper.rb +2 -0
- data/examples/rails-without-webpack/app/helpers/static_pages_helper.rb +2 -0
- data/examples/rails-without-webpack/app/javascript/channels/consumer.js +6 -0
- data/examples/rails-without-webpack/app/javascript/channels/index.js +6 -0
- data/examples/rails-without-webpack/app/javascript/packs/application.js +17 -0
- data/examples/rails-without-webpack/app/javascript/stylesheets/index.css +3 -0
- data/examples/rails-without-webpack/app/jobs/application_job.rb +7 -0
- data/examples/rails-without-webpack/app/mailers/application_mailer.rb +4 -0
- data/examples/rails-without-webpack/app/models/application_record.rb +3 -0
- data/examples/rails-without-webpack/app/models/concerns/.keep +0 -0
- data/examples/rails-without-webpack/app/views/layouts/application.html.erb +16 -0
- data/examples/rails-without-webpack/app/views/layouts/mailer.html.erb +13 -0
- data/examples/rails-without-webpack/app/views/layouts/mailer.text.erb +1 -0
- data/examples/rails-without-webpack/app/views/static_pages/index.html.erb +2 -0
- data/examples/rails-without-webpack/bin/bundle +114 -0
- data/examples/rails-without-webpack/bin/rails +9 -0
- data/examples/rails-without-webpack/bin/rake +9 -0
- data/examples/rails-without-webpack/bin/setup +36 -0
- data/examples/rails-without-webpack/bin/spring +17 -0
- data/examples/rails-without-webpack/bin/yarn +9 -0
- data/examples/rails-without-webpack/config.ru +5 -0
- data/examples/rails-without-webpack/config/application.rb +20 -0
- data/examples/rails-without-webpack/config/boot.rb +4 -0
- data/examples/rails-without-webpack/config/cable.yml +10 -0
- data/examples/rails-without-webpack/config/credentials.yml.enc +1 -0
- data/examples/rails-without-webpack/config/database.yml +25 -0
- data/examples/rails-without-webpack/config/environment.rb +5 -0
- data/examples/rails-without-webpack/config/environments/development.rb +62 -0
- data/examples/rails-without-webpack/config/environments/production.rb +112 -0
- data/examples/rails-without-webpack/config/environments/test.rb +49 -0
- data/examples/rails-without-webpack/config/initializers/application_controller_renderer.rb +8 -0
- data/examples/rails-without-webpack/config/initializers/assets.rb +14 -0
- data/examples/rails-without-webpack/config/initializers/backtrace_silencers.rb +7 -0
- data/examples/rails-without-webpack/config/initializers/content_security_policy.rb +31 -0
- data/examples/rails-without-webpack/config/initializers/cookies_serializer.rb +5 -0
- data/examples/rails-without-webpack/config/initializers/filter_parameter_logging.rb +4 -0
- data/examples/rails-without-webpack/config/initializers/inflections.rb +16 -0
- data/examples/rails-without-webpack/config/initializers/mime_types.rb +4 -0
- data/examples/rails-without-webpack/config/initializers/snowpacker.rb +19 -0
- data/examples/rails-without-webpack/config/initializers/wrap_parameters.rb +14 -0
- data/examples/rails-without-webpack/config/locales/en.yml +33 -0
- data/examples/rails-without-webpack/config/puma.rb +38 -0
- data/examples/rails-without-webpack/config/routes.rb +4 -0
- data/examples/rails-without-webpack/config/snowpacker/.browserslistrc +1 -0
- data/examples/rails-without-webpack/config/snowpacker/babel.config.js +76 -0
- data/examples/rails-without-webpack/config/snowpacker/postcss.config.js +12 -0
- data/examples/rails-without-webpack/config/snowpacker/snowpack.config.js +42 -0
- data/examples/rails-without-webpack/config/spring.rb +6 -0
- data/examples/rails-without-webpack/config/storage.yml +34 -0
- data/examples/rails-without-webpack/db/seeds.rb +7 -0
- data/examples/rails-without-webpack/lib/assets/.keep +0 -0
- data/examples/rails-without-webpack/lib/tasks/.keep +0 -0
- data/examples/rails-without-webpack/package.json +33 -0
- data/examples/rails-without-webpack/storage/.keep +0 -0
- data/examples/rails-without-webpack/test/application_system_test_case.rb +5 -0
- data/examples/rails-without-webpack/test/channels/application_cable/connection_test.rb +11 -0
- data/examples/rails-without-webpack/test/controllers/.keep +0 -0
- data/examples/rails-without-webpack/test/controllers/static_pages_controller_test.rb +8 -0
- data/examples/rails-without-webpack/test/fixtures/.keep +0 -0
- data/examples/rails-without-webpack/test/fixtures/files/.keep +0 -0
- data/examples/rails-without-webpack/test/helpers/.keep +0 -0
- data/examples/rails-without-webpack/test/integration/.keep +0 -0
- data/examples/rails-without-webpack/test/mailers/.keep +0 -0
- data/examples/rails-without-webpack/test/models/.keep +0 -0
- data/examples/rails-without-webpack/test/system/.keep +0 -0
- data/examples/rails-without-webpack/test/test_helper.rb +13 -0
- data/examples/rails-without-webpack/tmp/.keep +0 -0
- data/examples/rails-without-webpack/tmp/pids/.keep +0 -0
- data/examples/rails-without-webpack/vendor/.keep +0 -0
- data/examples/rails-without-webpack/yarn.lock +4254 -0
- data/lib/snowpacker.rb +24 -0
- data/lib/snowpacker/configuration.rb +19 -0
- data/lib/snowpacker/engine.rb +9 -0
- data/lib/snowpacker/env.rb +23 -0
- data/lib/snowpacker/runner.rb +51 -0
- data/lib/snowpacker/snowpacker_generator.rb +58 -0
- data/lib/snowpacker/snowpacker_proxy.rb +48 -0
- data/lib/snowpacker/templates/babel.config.js +76 -0
- data/lib/snowpacker/templates/postcss.config.js +12 -0
- data/lib/snowpacker/templates/snowpack.config.js +42 -0
- data/lib/snowpacker/templates/snowpacker.rb +19 -0
- data/lib/snowpacker/version.rb +5 -0
- data/lib/tasks/snowpacker_tasks.rake +30 -0
- data/snowpacker.gemspec +45 -0
- data/yarn.lock +6211 -0
- metadata +299 -0
data/lib/snowpacker.rb
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "snowpacker/configuration"
|
|
4
|
+
require "snowpacker/snowpacker_proxy"
|
|
5
|
+
|
|
6
|
+
module Snowpacker
|
|
7
|
+
class << self
|
|
8
|
+
attr_accessor :config
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def self.config_location
|
|
12
|
+
Rails.root.join("config", "snowpack.config.json")
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def self.configure
|
|
16
|
+
self.config ||= Configuration.new
|
|
17
|
+
yield(config)
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
require "snowpacker/version"
|
|
22
|
+
require "snowpacker/snowpacker_generator" if defined?(Rails)
|
|
23
|
+
require "snowpacker/runner" if defined?(Rails)
|
|
24
|
+
require "snowpacker/engine" if defined?(Rails)
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
module Snowpacker
|
|
2
|
+
class Configuration
|
|
3
|
+
attr_accessor :config_dir
|
|
4
|
+
attr_accessor :config_file
|
|
5
|
+
attr_accessor :babel_config_file
|
|
6
|
+
attr_accessor :postcss_config_file
|
|
7
|
+
attr_accessor :build_dir
|
|
8
|
+
attr_accessor :mount_dir
|
|
9
|
+
attr_accessor :output_path
|
|
10
|
+
attr_accessor :port, :hostname
|
|
11
|
+
|
|
12
|
+
def initialize
|
|
13
|
+
@output_path = "snowpacks"
|
|
14
|
+
@mount_dir = File.join("app", "javascript")
|
|
15
|
+
@port = "4035"
|
|
16
|
+
@hostname = "localhost"
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
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
|
+
set_env("BUILD_DIR", Snowpacker.config.build_dir)
|
|
11
|
+
set_env("MOUNT_DIR", Snowpacker.config.mount_dir)
|
|
12
|
+
set_env("BABEL_CONFIG_FILE", Snowpacker.config.babel_config_file)
|
|
13
|
+
set_env("POSTCSS_CONFIG_FILE", Snowpacker.config.postcss_config_file)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
private
|
|
17
|
+
|
|
18
|
+
def set_env(env_var, value)
|
|
19
|
+
ENV["#{ENV_PREFIX}_#{env_var}"] ||= value.to_s
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "socket"
|
|
4
|
+
require "snowpacker/env"
|
|
5
|
+
|
|
6
|
+
module Snowpacker
|
|
7
|
+
module Rails
|
|
8
|
+
class Runner
|
|
9
|
+
attr_reader :config_file
|
|
10
|
+
|
|
11
|
+
def initialize
|
|
12
|
+
@config_file = Snowpacker.config.config_file
|
|
13
|
+
Env.set_env_variables
|
|
14
|
+
rescue Errno::ENOENT, NoMethodError
|
|
15
|
+
$stdout.puts "Snowpacker configuration not found in #{Snowpacker.config_location}"
|
|
16
|
+
$stdout.puts "Please run bundle exec rails generate snowpacker to install Snowpacker"
|
|
17
|
+
exit!
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
# Build for production
|
|
21
|
+
def build
|
|
22
|
+
snowpacker_command(env: :production, cmd: :build)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
# Serve for development
|
|
26
|
+
def dev
|
|
27
|
+
detect_port!
|
|
28
|
+
snowpacker_command(env: :development, cmd: :dev)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
private
|
|
32
|
+
|
|
33
|
+
def snowpacker_command(env: "", cmd: "")
|
|
34
|
+
env = ENV["NODE_ENV"] || env
|
|
35
|
+
command = "NODE_ENV=#{env} yarn run snowpack #{cmd} --config #{@config_file}"
|
|
36
|
+
exec(command)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def detect_port!
|
|
40
|
+
hostname = Snowpacker.config.hostname
|
|
41
|
+
port = Snowpacker.config.port
|
|
42
|
+
server = TCPServer.new(hostname, port)
|
|
43
|
+
server.close
|
|
44
|
+
rescue Errno::EADDRINUSE
|
|
45
|
+
$stdout.puts "Another program is running on port #{port}.\n
|
|
46
|
+
Set a new port in #{Snowpacker.config_path} for devOptions: { port: \"#{port}\" }"
|
|
47
|
+
exit!
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "rails/generators"
|
|
4
|
+
|
|
5
|
+
class SnowpackerGenerator < ::Rails::Generators::Base
|
|
6
|
+
TEMPLATES = File.join(File.expand_path(__dir__), "templates")
|
|
7
|
+
|
|
8
|
+
desc "Generate Snowpacker initializer"
|
|
9
|
+
def create_initializer_file
|
|
10
|
+
initializer "snowpacker.rb" do
|
|
11
|
+
File.read(File.join(TEMPLATES, "snowpacker.rb"))
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
desc "Add snowpack, babel, and postcss to your package.json dependencies"
|
|
16
|
+
def add_snowpack
|
|
17
|
+
%x(yarn add -D snowpack \
|
|
18
|
+
@snowpack/babel-plugin-package-import \
|
|
19
|
+
core-js@3 \
|
|
20
|
+
postcss \
|
|
21
|
+
postcss-cli \
|
|
22
|
+
postcss-import \
|
|
23
|
+
postcss-flexbugs-fixes \
|
|
24
|
+
postcss-preset-env \
|
|
25
|
+
@babel/core \
|
|
26
|
+
@babel/cli \
|
|
27
|
+
@babel/preset-env \
|
|
28
|
+
@babel/plugin-transform-runtime \
|
|
29
|
+
babel-plugin-macros \
|
|
30
|
+
@snowpack/plugin-babel \
|
|
31
|
+
@babel/preset-env \
|
|
32
|
+
babel-plugin-macros \
|
|
33
|
+
@babel/plugin-syntax-dynamic-import \
|
|
34
|
+
babel-plugin-dynamic-import-node \
|
|
35
|
+
@babel/plugin-transform-destructuring \
|
|
36
|
+
@babel/plugin-proposal-class-properties \
|
|
37
|
+
@babel/plugin-proposal-object-rest-spread \
|
|
38
|
+
@babel/plugin-transform-runtime \
|
|
39
|
+
@babel/plugin-transform-regenerator
|
|
40
|
+
)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
desc "Create config files IE: babel.config snowpack.config"
|
|
44
|
+
def create_config_files
|
|
45
|
+
config_files = %w[
|
|
46
|
+
snowpack.config.js
|
|
47
|
+
postcss.config.js
|
|
48
|
+
babel.config.js
|
|
49
|
+
.browserslistrc
|
|
50
|
+
]
|
|
51
|
+
|
|
52
|
+
config_files.each do |filename|
|
|
53
|
+
create_file Rails.root.join("config", "snowpacker", filename) do
|
|
54
|
+
File.read(File.join(TEMPLATES, filename))
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "rack/proxy"
|
|
4
|
+
require "socket"
|
|
5
|
+
|
|
6
|
+
module Snowpacker
|
|
7
|
+
# Proxy server for snowpacker
|
|
8
|
+
class SnowpackerProxy < Rack::Proxy
|
|
9
|
+
def perform_request(env)
|
|
10
|
+
if env["PATH_INFO"].start_with?(%r{/#{Snowpacker.config.output_path}}) && dev_server_running?
|
|
11
|
+
env["HTTP_HOST"] = env["HTTP_X_FORWARDED_HOST"] = Snowpacker.config.hostname
|
|
12
|
+
env["HTTP_X_FORWARDED_SERVER"] = host_with_port
|
|
13
|
+
env["HTTP_PORT"] = env["HTTP_X_FORWARDED_PORT"] = Snowpacker.config.port
|
|
14
|
+
env["HTTP_X_FORWARDED_PROTO"] = env["HTTP_X_FORWARDED_SCHEME"] = "http"
|
|
15
|
+
|
|
16
|
+
# unless dev_server.https?
|
|
17
|
+
env["HTTPS"] = env["HTTP_X_FORWARDED_SSL"] = "off"
|
|
18
|
+
# end
|
|
19
|
+
|
|
20
|
+
env["SCRIPT_NAME"] = ""
|
|
21
|
+
|
|
22
|
+
super(env)
|
|
23
|
+
else
|
|
24
|
+
@app.call(env)
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
private
|
|
29
|
+
|
|
30
|
+
def dev_server_running?
|
|
31
|
+
host = Snowpacker.config.hostname
|
|
32
|
+
port = Snowpacker.config.port
|
|
33
|
+
connect_timeout = 0.01
|
|
34
|
+
|
|
35
|
+
Socket.tcp(host, port, connect_timeout: connect_timeout).close
|
|
36
|
+
true
|
|
37
|
+
rescue Errno::ECONNREFUSED
|
|
38
|
+
puts "Snowpacker is not currently running on #{host_with_port}"
|
|
39
|
+
false
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def host_with_port
|
|
43
|
+
hostname = Snowpacker.config.hostname
|
|
44
|
+
port = Snowpacker.config.port
|
|
45
|
+
"#{hostname}:#{port}"
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
module.exports = function(api) {
|
|
2
|
+
const validEnv = ['development', 'test', 'production']
|
|
3
|
+
const currentEnv = process.env.NODE_ENV
|
|
4
|
+
const isDevelopmentEnv = (currentEnv === "development")
|
|
5
|
+
const isProductionEnv = (currentEnv === 'production')
|
|
6
|
+
const isTestEnv = (currentEnv === 'test')
|
|
7
|
+
|
|
8
|
+
if (!validEnv.includes(currentEnv)) {
|
|
9
|
+
throw new Error(
|
|
10
|
+
'Please specify a valid `NODE_ENV` or ' +
|
|
11
|
+
'`BABEL_ENV` environment variables. Valid values are "development", ' +
|
|
12
|
+
'"test", and "production". Instead, received: ' +
|
|
13
|
+
JSON.stringify(currentEnv) +
|
|
14
|
+
'.'
|
|
15
|
+
)
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// Cached based on the value of some function. If this function returns a value different from
|
|
19
|
+
// a previously-encountered value, the plugins will re-evaluate.
|
|
20
|
+
api.cache(() => currentEnv);
|
|
21
|
+
|
|
22
|
+
return {
|
|
23
|
+
presets: [
|
|
24
|
+
isTestEnv && [
|
|
25
|
+
'@babel/preset-env',
|
|
26
|
+
{
|
|
27
|
+
targets: {
|
|
28
|
+
node: 'current'
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
],
|
|
32
|
+
(isProductionEnv || isDevelopmentEnv) && [
|
|
33
|
+
'@babel/preset-env',
|
|
34
|
+
{
|
|
35
|
+
forceAllTransforms: true,
|
|
36
|
+
useBuiltIns: 'entry',
|
|
37
|
+
corejs: 3,
|
|
38
|
+
modules: false,
|
|
39
|
+
exclude: ['transform-typeof-symbol']
|
|
40
|
+
}
|
|
41
|
+
]
|
|
42
|
+
].filter(Boolean),
|
|
43
|
+
plugins: [
|
|
44
|
+
'babel-plugin-macros',
|
|
45
|
+
'@babel/plugin-syntax-dynamic-import',
|
|
46
|
+
isTestEnv && 'babel-plugin-dynamic-import-node',
|
|
47
|
+
'@babel/plugin-transform-destructuring',
|
|
48
|
+
[
|
|
49
|
+
'@babel/plugin-proposal-class-properties',
|
|
50
|
+
{
|
|
51
|
+
loose: true
|
|
52
|
+
}
|
|
53
|
+
],
|
|
54
|
+
[
|
|
55
|
+
'@babel/plugin-proposal-object-rest-spread',
|
|
56
|
+
{
|
|
57
|
+
useBuiltIns: true
|
|
58
|
+
}
|
|
59
|
+
],
|
|
60
|
+
[
|
|
61
|
+
'@babel/plugin-transform-runtime',
|
|
62
|
+
{
|
|
63
|
+
helpers: false,
|
|
64
|
+
regenerator: true,
|
|
65
|
+
corejs: false
|
|
66
|
+
}
|
|
67
|
+
],
|
|
68
|
+
[
|
|
69
|
+
'@babel/plugin-transform-regenerator',
|
|
70
|
+
{
|
|
71
|
+
async: false
|
|
72
|
+
}
|
|
73
|
+
]
|
|
74
|
+
].filter(Boolean)
|
|
75
|
+
}
|
|
76
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
const output_path = process.env["SNOWPACKER_OUTPUT_PATH"]
|
|
2
|
+
const port = process.env["SNOWPACKER_PORT"]
|
|
3
|
+
const build_dir = process.env["SNOWPACKER_BUILD_DIR"]
|
|
4
|
+
const mount_dir = process.env["SNOWPACKER_MOUNT_DIR"]
|
|
5
|
+
const babel_config = process.env["SNOWPACKER_BABEL_CONFIG_FILE"]
|
|
6
|
+
const postcss_config = process.env["SNOWPACKER_POSTCSS_CONFIG_FILE"]
|
|
7
|
+
|
|
8
|
+
// not currently supported
|
|
9
|
+
// const hostname = process.env["SNOWPACKER_HOSTNAME"]
|
|
10
|
+
|
|
11
|
+
const scripts = {
|
|
12
|
+
"mount:web_modules": `mount $WEB_MODULES --to /${output_path}/web_modules`,
|
|
13
|
+
"mount:snowpacks": `mount ${mount_dir} --to /${output_path}`,
|
|
14
|
+
"build:css": `postcss --config ${postcss_config}`,
|
|
15
|
+
"build:js,jsx,ts,tsx": `babel --config-file ${babel_config} \
|
|
16
|
+
${mount_dir}`
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const installOptions = {
|
|
20
|
+
NODE_ENV: true
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const devOptions = {
|
|
24
|
+
port: parseInt(port, 10),
|
|
25
|
+
open: "none",
|
|
26
|
+
out: build_dir
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const buildOptions = {
|
|
30
|
+
clean: true,
|
|
31
|
+
baseUrl: "/",
|
|
32
|
+
metaDir: `${output_path}/__snowpack__`
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
module.exports = {
|
|
36
|
+
scripts,
|
|
37
|
+
plugins: [],
|
|
38
|
+
installOptions,
|
|
39
|
+
devOptions,
|
|
40
|
+
buildOptions
|
|
41
|
+
}
|
|
42
|
+
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
Rails.application.config.middleware.use Snowpacker::SnowpackerProxy, {ssl_verify_none: true}
|
|
2
|
+
|
|
3
|
+
Snowpacker.configure do |snowpacker|
|
|
4
|
+
# Where to find the config file
|
|
5
|
+
snowpacker.config_dir = Rails.root.join("config", "snowpacker")
|
|
6
|
+
snowpacker.config_file = File.join(snowpacker.config_dir, "snowpack.config.js")
|
|
7
|
+
|
|
8
|
+
snowpacker.babel_config_file = File.join(snowpacker.config_dir, "babel.config.js")
|
|
9
|
+
snowpacker.postcss_config_file = File.join(snowpacker.config_dir, "postcss.config.js")
|
|
10
|
+
|
|
11
|
+
snowpacker.mount_dir = File.join("app", "javascript")
|
|
12
|
+
snowpacker.build_dir = "public"
|
|
13
|
+
snowpacker.output_path = "snowpacks" # => /public/snowpacks
|
|
14
|
+
snowpacker.port = "4035"
|
|
15
|
+
|
|
16
|
+
# Currently, snowpack does not support the hostname option as of version 2.6.4
|
|
17
|
+
# Support should be coming in 2.6.5, so until then, this is just a placeholder.
|
|
18
|
+
snowpacker.hostname = "localhost"
|
|
19
|
+
end
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
namespace :snowpacker do
|
|
2
|
+
desc "Compiles assets using snowpack bundler"
|
|
3
|
+
task build: :environment do
|
|
4
|
+
Snowpacker::Rails::Runner.new.build
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
desc "Compiles assets using snowpack bundler"
|
|
8
|
+
task compile: :build
|
|
9
|
+
|
|
10
|
+
desc "Run a snowpack dev server"
|
|
11
|
+
task dev: :environment do
|
|
12
|
+
Snowpacker::Rails::Runner.new.dev
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
desc "Removes compiled assets"
|
|
16
|
+
task clobber: :environment do
|
|
17
|
+
command = "rm -rf #{::Rails.application.config.snowpacker.destination}"
|
|
18
|
+
logger = Logger.new(STDOUT)
|
|
19
|
+
logger.info(command)
|
|
20
|
+
exec(command)
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
Rake::Task["assets:precompile"].enhance do
|
|
25
|
+
Rake::Task["snowpacker:build"].invoke
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
Rake::Task["assets:clobber"].enhance do
|
|
29
|
+
Rake::Task["snowpacker:clobber"].invoke
|
|
30
|
+
end
|
data/snowpacker.gemspec
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
$:.push File.expand_path("lib", __dir__)
|
|
4
|
+
|
|
5
|
+
# Maintain your gem's version:
|
|
6
|
+
require "snowpacker/version"
|
|
7
|
+
|
|
8
|
+
Gem::Specification.new do |spec|
|
|
9
|
+
spec.name = "snowpacker"
|
|
10
|
+
spec.version = Snowpacker::VERSION
|
|
11
|
+
spec.authors = ["Konnor Rogers"]
|
|
12
|
+
spec.email = ["konnor7414@gmail.com"]
|
|
13
|
+
|
|
14
|
+
spec.summary = "Rails integration of Snowpack"
|
|
15
|
+
spec.description = "Rails integration of Snowpack"
|
|
16
|
+
spec.homepage = "http://github.com/paramagicdev/snowpacker"
|
|
17
|
+
spec.license = "MIT"
|
|
18
|
+
|
|
19
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
|
20
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
|
21
|
+
if spec.respond_to?(:metadata)
|
|
22
|
+
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
|
23
|
+
else
|
|
24
|
+
raise "RubyGems 2.0 or newer is required to protect against " \
|
|
25
|
+
"public gem pushes."
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
|
29
|
+
f.match(%r{^(test|spec|features)/})
|
|
30
|
+
end
|
|
31
|
+
spec.bindir = "exe"
|
|
32
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
33
|
+
spec.require_paths = ["lib"]
|
|
34
|
+
|
|
35
|
+
spec.add_runtime_dependency "rack-proxy", "~> 0.6.4"
|
|
36
|
+
spec.add_development_dependency "bundler", "~> 2"
|
|
37
|
+
spec.add_development_dependency "conventional-changelog", "~> 1.2"
|
|
38
|
+
spec.add_development_dependency "minitest", "~> 5.14"
|
|
39
|
+
spec.add_development_dependency "pry", "~> 0.12"
|
|
40
|
+
spec.add_development_dependency "rails", "~> 6"
|
|
41
|
+
spec.add_development_dependency "rake", "~> 13.0"
|
|
42
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
|
43
|
+
spec.add_development_dependency "standardrb"
|
|
44
|
+
spec.add_development_dependency "yard"
|
|
45
|
+
end
|