webpacker 4.3.0 → 6.0.0.rc.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.eslintrc.js +8 -8
- data/.github/workflows/jest.yml +30 -0
- data/.github/workflows/js-lint.yml +31 -0
- data/.github/workflows/rubocop.yml +39 -0
- data/.github/workflows/ruby.yml +48 -0
- data/.gitignore +2 -0
- data/.node-version +1 -1
- data/.rubocop.yml +117 -16
- data/CHANGELOG.md +91 -5
- data/CONTRIBUTING.md +20 -1
- data/Gemfile +1 -0
- data/Gemfile.lock +121 -109
- data/README.md +365 -387
- data/config/README.md +3 -0
- data/config/webpacker.yml +1 -0
- data/docs/deployment.md +9 -11
- data/docs/developing_webpacker.md +29 -0
- data/docs/troubleshooting.md +64 -26
- data/docs/v6_upgrade.md +113 -0
- data/gemfiles/Gemfile-rails-edge +1 -1
- data/gemfiles/{Gemfile-rails.4.2.x → Gemfile-rails.6.1.x} +4 -1
- data/lib/install/{javascript/packs/application.js → application.js} +2 -5
- data/lib/install/bin/webpack +4 -7
- data/lib/install/bin/yarn +18 -0
- data/lib/install/config/webpack/base.js +3 -0
- data/lib/install/config/webpack/development.js +2 -2
- data/lib/install/config/webpack/production.js +2 -2
- data/lib/install/config/webpack/test.js +2 -2
- data/lib/install/config/webpacker.yml +22 -54
- data/lib/install/package.json +15 -0
- data/lib/install/template.rb +66 -23
- data/lib/tasks/webpacker/binstubs.rake +6 -4
- data/lib/tasks/webpacker/check_binstubs.rake +4 -4
- data/lib/tasks/webpacker/check_node.rake +18 -8
- data/lib/tasks/webpacker/check_yarn.rake +19 -10
- data/lib/tasks/webpacker/clean.rake +12 -6
- data/lib/tasks/webpacker/clobber.rake +9 -5
- data/lib/tasks/webpacker/compile.rake +4 -2
- data/lib/tasks/webpacker/info.rake +12 -10
- data/lib/tasks/webpacker/install.rake +6 -4
- data/lib/tasks/webpacker/verify_config.rake +14 -0
- data/lib/tasks/webpacker/verify_install.rake +1 -10
- data/lib/tasks/webpacker/yarn_install.rake +13 -16
- data/lib/tasks/webpacker.rake +2 -11
- data/lib/tasks/yarn.rake +38 -0
- data/lib/webpacker/commands.rb +40 -11
- data/lib/webpacker/compiler.rb +23 -12
- data/lib/webpacker/configuration.rb +24 -33
- data/lib/webpacker/dev_server.rb +6 -0
- data/lib/webpacker/dev_server_proxy.rb +3 -1
- data/lib/webpacker/dev_server_runner.rb +34 -10
- data/lib/webpacker/env.rb +5 -1
- data/lib/webpacker/helper.rb +72 -87
- data/lib/webpacker/instance.rb +4 -0
- data/lib/webpacker/manifest.rb +6 -7
- data/lib/webpacker/railtie.rb +8 -45
- data/lib/webpacker/runner.rb +1 -0
- data/lib/webpacker/version.rb +1 -1
- data/lib/webpacker/webpack_runner.rb +30 -4
- data/lib/webpacker.rb +1 -1
- data/package/__tests__/config.js +6 -27
- data/package/__tests__/dev_server.js +2 -0
- data/package/__tests__/development.js +18 -13
- data/package/__tests__/env.js +16 -4
- data/package/__tests__/index.js +9 -0
- data/package/__tests__/production.js +6 -6
- data/package/__tests__/staging.js +7 -6
- data/package/__tests__/test.js +4 -5
- data/package/babel/preset.js +54 -0
- data/package/config.js +7 -12
- data/package/configPath.js +3 -0
- data/package/dev_server.js +1 -1
- data/package/env.js +14 -6
- data/package/environments/__tests__/base.js +26 -31
- data/package/environments/base.js +78 -128
- data/package/environments/development.js +47 -43
- data/package/environments/production.js +66 -66
- data/package/environments/test.js +2 -2
- data/package/index.js +15 -8
- data/package/inliningCss.js +7 -0
- data/package/rules/babel.js +20 -11
- data/package/rules/coffee.js +6 -0
- data/package/rules/erb.js +15 -0
- data/package/rules/file.js +21 -18
- data/package/rules/index.js +16 -18
- data/package/rules/less.js +22 -0
- data/package/rules/raw.js +5 -0
- data/package/rules/sass.js +14 -6
- data/package/rules/stylus.js +26 -0
- data/package/utils/get_style_rule.js +28 -36
- data/package/utils/helpers.js +28 -35
- data/package.json +26 -46
- data/test/command_test.rb +76 -0
- data/test/compiler_test.rb +4 -11
- data/test/configuration_test.rb +5 -35
- data/test/dev_server_runner_test.rb +36 -6
- data/test/engine_rake_tasks_test.rb +39 -0
- data/test/helper_test.rb +77 -60
- data/test/manifest_test.rb +53 -6
- data/test/mounted_app/Rakefile +4 -0
- data/test/mounted_app/test/dummy/Rakefile +3 -0
- data/test/mounted_app/test/dummy/bin/rails +3 -0
- data/test/mounted_app/test/dummy/bin/rake +3 -0
- data/test/mounted_app/test/dummy/config/application.rb +10 -0
- data/test/mounted_app/test/dummy/config/environment.rb +3 -0
- data/test/mounted_app/test/dummy/config/webpacker.yml +75 -0
- data/test/mounted_app/test/dummy/config.ru +5 -0
- data/test/mounted_app/test/dummy/package.json +7 -0
- data/test/rake_tasks_test.rb +12 -10
- data/test/test_app/app/{javascript/packs → packs/entrypoints}/application.js +1 -1
- data/test/test_app/app/packs/entrypoints/multi_entry.css +4 -0
- data/test/test_app/app/packs/entrypoints/multi_entry.js +4 -0
- data/test/test_app/config/application.rb +0 -1
- data/test/test_app/config/initializers/inspect_autoload_paths.rb +1 -0
- data/test/test_app/config/webpacker.yml +7 -27
- data/test/test_app/config/webpacker_other_location.yml +79 -0
- data/test/test_app/config/webpacker_public_root.yml +0 -1
- data/test/test_app/public/packs/manifest.json +36 -17
- data/test/test_app/some.config.js +0 -0
- data/test/webpack_runner_test.rb +10 -4
- data/test/webpacker_test.rb +21 -0
- data/webpacker.gemspec +5 -4
- data/yarn.lock +3387 -6898
- metadata +90 -99
- data/.travis.yml +0 -57
- data/docs/assets.md +0 -119
- data/docs/cloud9.md +0 -310
- data/docs/css.md +0 -254
- data/docs/docker.md +0 -68
- data/docs/engines.md +0 -200
- data/docs/env.md +0 -65
- data/docs/es6.md +0 -72
- data/docs/folder-structure.md +0 -66
- data/docs/misc.md +0 -23
- data/docs/props.md +0 -223
- data/docs/testing.md +0 -137
- data/docs/typescript.md +0 -126
- data/docs/v4-upgrade.md +0 -142
- data/docs/webpack-dev-server.md +0 -92
- data/docs/webpack.md +0 -364
- data/docs/yarn.md +0 -23
- data/gemfiles/Gemfile-rails.5.0.x +0 -9
- data/gemfiles/Gemfile-rails.5.1.x +0 -9
- data/lib/install/angular.rb +0 -23
- data/lib/install/coffee.rb +0 -25
- data/lib/install/config/.browserslistrc +0 -1
- data/lib/install/config/babel.config.js +0 -72
- data/lib/install/config/postcss.config.js +0 -12
- data/lib/install/config/webpack/environment.js +0 -3
- data/lib/install/elm.rb +0 -39
- data/lib/install/erb.rb +0 -25
- data/lib/install/examples/angular/hello_angular/app/app.component.ts +0 -9
- data/lib/install/examples/angular/hello_angular/app/app.module.ts +0 -16
- data/lib/install/examples/angular/hello_angular/index.ts +0 -8
- data/lib/install/examples/angular/hello_angular/polyfills.ts +0 -73
- data/lib/install/examples/angular/hello_angular.js +0 -7
- data/lib/install/examples/coffee/hello_coffee.coffee +0 -4
- data/lib/install/examples/elm/Main.elm +0 -55
- data/lib/install/examples/elm/hello_elm.js +0 -16
- data/lib/install/examples/erb/hello_erb.js.erb +0 -6
- data/lib/install/examples/react/babel.config.js +0 -87
- data/lib/install/examples/react/hello_react.jsx +0 -26
- data/lib/install/examples/react/tsconfig.json +0 -20
- data/lib/install/examples/stimulus/application.js +0 -1
- data/lib/install/examples/stimulus/controllers/hello_controller.js +0 -18
- data/lib/install/examples/stimulus/controllers/index.js +0 -9
- data/lib/install/examples/svelte/app.svelte +0 -11
- data/lib/install/examples/svelte/hello_svelte.js +0 -20
- data/lib/install/examples/typescript/hello_typescript.ts +0 -4
- data/lib/install/examples/typescript/tsconfig.json +0 -23
- data/lib/install/examples/vue/app.vue +0 -22
- data/lib/install/examples/vue/hello_vue.js +0 -72
- data/lib/install/loaders/coffee.js +0 -6
- data/lib/install/loaders/elm.js +0 -25
- data/lib/install/loaders/erb.js +0 -11
- data/lib/install/loaders/svelte.js +0 -9
- data/lib/install/loaders/typescript.js +0 -11
- data/lib/install/loaders/vue.js +0 -6
- data/lib/install/react.rb +0 -18
- data/lib/install/stimulus.rb +0 -12
- data/lib/install/svelte.rb +0 -29
- data/lib/install/typescript.rb +0 -46
- data/lib/install/vue.rb +0 -49
- data/lib/tasks/installers.rake +0 -42
- data/package/config_types/__tests__/config_list.js +0 -118
- data/package/config_types/__tests__/config_object.js +0 -43
- data/package/config_types/config_list.js +0 -75
- data/package/config_types/config_object.js +0 -55
- data/package/config_types/index.js +0 -7
- data/package/rules/module.css.js +0 -3
- data/package/rules/module.sass.js +0 -8
- data/package/rules/node_modules.js +0 -24
- data/package/utils/__tests__/deep_assign.js +0 -32
- data/package/utils/__tests__/deep_merge.js +0 -10
- data/package/utils/__tests__/get_style_rule.js +0 -65
- data/package/utils/__tests__/objectify.js +0 -9
- data/package/utils/deep_assign.js +0 -22
- data/package/utils/deep_merge.js +0 -22
- data/package/utils/objectify.js +0 -3
data/lib/webpacker/compiler.rb
CHANGED
@@ -4,6 +4,8 @@ require "digest/sha1"
|
|
4
4
|
class Webpacker::Compiler
|
5
5
|
# Additional paths that test compiler needs to watch
|
6
6
|
# Webpacker::Compiler.watched_paths << 'bower_components'
|
7
|
+
#
|
8
|
+
# Deprecated. Use additional_paths in the YAML configuration instead.
|
7
9
|
cattr_accessor(:watched_paths) { [] }
|
8
10
|
|
9
11
|
# Additional environment variables that the compiler is being run with
|
@@ -20,21 +22,20 @@ class Webpacker::Compiler
|
|
20
22
|
if stale?
|
21
23
|
run_webpack.tap do |success|
|
22
24
|
# We used to only record the digest on success
|
23
|
-
# However, the output file is still written on error,
|
24
|
-
#
|
25
|
-
# take place when it should.
|
25
|
+
# However, the output file is still written on error, meaning that the digest should still be updated.
|
26
|
+
# If it's not, you can end up in a situation where a recompile doesn't take place when it should.
|
26
27
|
# See https://github.com/rails/webpacker/issues/2113
|
27
28
|
record_compilation_digest
|
28
29
|
end
|
29
30
|
else
|
30
|
-
logger.
|
31
|
+
logger.debug "Everything's up-to-date. Nothing to do"
|
31
32
|
true
|
32
33
|
end
|
33
34
|
end
|
34
35
|
|
35
36
|
# Returns true if all the compiled packs are up to date with the underlying asset files.
|
36
37
|
def fresh?
|
37
|
-
watched_files_digest
|
38
|
+
last_compilation_digest&.== watched_files_digest
|
38
39
|
end
|
39
40
|
|
40
41
|
# Returns true if the compiled packs are out of date with the underlying asset files.
|
@@ -51,9 +52,12 @@ class Webpacker::Compiler
|
|
51
52
|
end
|
52
53
|
|
53
54
|
def watched_files_digest
|
54
|
-
|
55
|
-
|
56
|
-
|
55
|
+
warn "Webpacker::Compiler.watched_paths has been deprecated. Set additional_paths in webpacker.yml instead." unless watched_paths.empty?
|
56
|
+
Dir.chdir File.expand_path(config.root_path) do
|
57
|
+
files = Dir[*default_watched_paths, *watched_paths].reject { |f| File.directory?(f) }
|
58
|
+
file_ids = files.sort.map { |f| "#{File.basename(f)}/#{Digest::SHA1.file(f).hexdigest}" }
|
59
|
+
Digest::SHA1.hexdigest(file_ids.join("/"))
|
60
|
+
end
|
57
61
|
end
|
58
62
|
|
59
63
|
def record_compilation_digest
|
@@ -61,12 +65,18 @@ class Webpacker::Compiler
|
|
61
65
|
compilation_digest_path.write(watched_files_digest)
|
62
66
|
end
|
63
67
|
|
68
|
+
def optionalRubyRunner
|
69
|
+
bin_webpack_path = config.root_path.join("bin/webpack")
|
70
|
+
first_line = File.readlines(bin_webpack_path).first.chomp
|
71
|
+
/ruby/.match?(first_line) ? RbConfig.ruby : ""
|
72
|
+
end
|
73
|
+
|
64
74
|
def run_webpack
|
65
75
|
logger.info "Compiling..."
|
66
76
|
|
67
77
|
stdout, stderr, status = Open3.capture3(
|
68
78
|
webpack_env,
|
69
|
-
"#{
|
79
|
+
"#{optionalRubyRunner} ./bin/webpack",
|
70
80
|
chdir: File.expand_path(config.root_path)
|
71
81
|
)
|
72
82
|
|
@@ -87,8 +97,8 @@ class Webpacker::Compiler
|
|
87
97
|
|
88
98
|
def default_watched_paths
|
89
99
|
[
|
90
|
-
*config.
|
91
|
-
config.
|
100
|
+
*config.additional_paths,
|
101
|
+
"#{config.source_path}/**/*",
|
92
102
|
"yarn.lock", "package.json",
|
93
103
|
"config/webpack/**/*"
|
94
104
|
].freeze
|
@@ -102,6 +112,7 @@ class Webpacker::Compiler
|
|
102
112
|
return env unless defined?(ActionController::Base)
|
103
113
|
|
104
114
|
env.merge("WEBPACKER_ASSET_HOST" => ENV.fetch("WEBPACKER_ASSET_HOST", ActionController::Base.helpers.compute_asset_host),
|
105
|
-
"WEBPACKER_RELATIVE_URL_ROOT" => ENV.fetch("WEBPACKER_RELATIVE_URL_ROOT", ActionController::Base.relative_url_root)
|
115
|
+
"WEBPACKER_RELATIVE_URL_ROOT" => ENV.fetch("WEBPACKER_RELATIVE_URL_ROOT", ActionController::Base.relative_url_root),
|
116
|
+
"WEBPACKER_CONFIG" => webpacker.config_path.to_s)
|
106
117
|
end
|
107
118
|
end
|
@@ -23,16 +23,8 @@ class Webpacker::Configuration
|
|
23
23
|
root_path.join(fetch(:source_path))
|
24
24
|
end
|
25
25
|
|
26
|
-
def
|
27
|
-
|
28
|
-
end
|
29
|
-
|
30
|
-
def resolved_paths
|
31
|
-
fetch(:resolved_paths)
|
32
|
-
end
|
33
|
-
|
34
|
-
def resolved_paths_globbed
|
35
|
-
resolved_paths.map { |p| globbed_path_with_extensions(p) }
|
26
|
+
def additional_paths
|
27
|
+
fetch(:additional_paths)
|
36
28
|
end
|
37
29
|
|
38
30
|
def source_entry_path
|
@@ -59,38 +51,34 @@ class Webpacker::Configuration
|
|
59
51
|
root_path.join(fetch(:cache_path))
|
60
52
|
end
|
61
53
|
|
62
|
-
def extensions
|
63
|
-
fetch(:extensions)
|
64
|
-
end
|
65
|
-
|
66
54
|
def check_yarn_integrity=(value)
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
55
|
+
warn <<~EOS
|
56
|
+
Webpacker::Configuration#check_yarn_integrity=(value) is obsolete. The integrity
|
57
|
+
check has been removed from Webpacker (https://github.com/rails/webpacker/pull/2518)
|
58
|
+
so changing this setting will have no effect.
|
59
|
+
EOS
|
72
60
|
end
|
73
61
|
|
74
62
|
def webpack_compile_output?
|
75
63
|
fetch(:webpack_compile_output)
|
76
64
|
end
|
77
65
|
|
78
|
-
def
|
79
|
-
fetch(
|
66
|
+
def fetch(key)
|
67
|
+
data.fetch(key, defaults[key])
|
80
68
|
end
|
81
69
|
|
82
70
|
private
|
83
|
-
def fetch(key)
|
84
|
-
data.fetch(key, defaults[key])
|
85
|
-
end
|
86
|
-
|
87
71
|
def data
|
88
72
|
@data ||= load
|
89
73
|
end
|
90
74
|
|
91
75
|
def load
|
92
|
-
|
93
|
-
|
76
|
+
config = begin
|
77
|
+
YAML.load_file(config_path.to_s, aliases: true)
|
78
|
+
rescue ArgumentError
|
79
|
+
YAML.load_file(config_path.to_s)
|
80
|
+
end
|
81
|
+
config[env].deep_symbolize_keys
|
94
82
|
rescue Errno::ENOENT => e
|
95
83
|
raise "Webpacker configuration file not found #{config_path}. " \
|
96
84
|
"Please run rails webpacker:install " \
|
@@ -103,11 +91,14 @@ class Webpacker::Configuration
|
|
103
91
|
end
|
104
92
|
|
105
93
|
def defaults
|
106
|
-
@defaults ||=
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
94
|
+
@defaults ||= begin
|
95
|
+
path = File.expand_path("../../install/config/webpacker.yml", __FILE__)
|
96
|
+
config = begin
|
97
|
+
YAML.load_file(path, aliases: true)
|
98
|
+
rescue ArgumentError
|
99
|
+
YAML.load_file(path)
|
100
|
+
end
|
101
|
+
HashWithIndifferentAccess.new(config[env])
|
102
|
+
end
|
112
103
|
end
|
113
104
|
end
|
data/lib/webpacker/dev_server.rb
CHANGED
@@ -51,12 +51,18 @@ class Webpacker::DevServer
|
|
51
51
|
fetch(:pretty)
|
52
52
|
end
|
53
53
|
|
54
|
+
def hmr?
|
55
|
+
fetch(:hmr)
|
56
|
+
end
|
57
|
+
|
54
58
|
def env_prefix
|
55
59
|
config.dev_server.fetch(:env_prefix, DEFAULT_ENV_PREFIX)
|
56
60
|
end
|
57
61
|
|
58
62
|
private
|
59
63
|
def fetch(key)
|
64
|
+
return nil unless config.dev_server.present?
|
65
|
+
|
60
66
|
ENV["#{env_prefix}_#{key.upcase}"] || config.dev_server.fetch(key, defaults[key])
|
61
67
|
end
|
62
68
|
|
@@ -11,7 +11,9 @@ class Webpacker::DevServerProxy < Rack::Proxy
|
|
11
11
|
|
12
12
|
def perform_request(env)
|
13
13
|
if env["PATH_INFO"].start_with?("/#{public_output_uri_path}") && dev_server.running?
|
14
|
-
env["HTTP_HOST"] = env["HTTP_X_FORWARDED_HOST"] =
|
14
|
+
env["HTTP_HOST"] = env["HTTP_X_FORWARDED_HOST"] = dev_server.host
|
15
|
+
env["HTTP_X_FORWARDED_SERVER"] = dev_server.host_with_port
|
16
|
+
env["HTTP_PORT"] = env["HTTP_X_FORWARDED_PORT"] = dev_server.port.to_s
|
15
17
|
env["HTTP_X_FORWARDED_PROTO"] = env["HTTP_X_FORWARDED_SCHEME"] = dev_server.protocol
|
16
18
|
unless dev_server.https?
|
17
19
|
env["HTTPS"] = env["HTTP_X_FORWARDED_SSL"] = "off"
|
@@ -8,58 +8,82 @@ module Webpacker
|
|
8
8
|
class DevServerRunner < Webpacker::Runner
|
9
9
|
def run
|
10
10
|
load_config
|
11
|
+
detect_unsupported_switches!
|
11
12
|
detect_port!
|
12
13
|
execute_cmd
|
13
14
|
end
|
14
15
|
|
15
16
|
private
|
17
|
+
|
16
18
|
def load_config
|
17
19
|
app_root = Pathname.new(@app_path)
|
18
20
|
|
19
|
-
config = Configuration.new(
|
21
|
+
@config = Configuration.new(
|
20
22
|
root_path: app_root,
|
21
|
-
config_path:
|
23
|
+
config_path: Pathname.new(@webpacker_config),
|
22
24
|
env: ENV["RAILS_ENV"]
|
23
25
|
)
|
24
26
|
|
25
|
-
dev_server = DevServer.new(config)
|
27
|
+
dev_server = DevServer.new(@config)
|
26
28
|
|
27
29
|
@hostname = dev_server.host
|
28
30
|
@port = dev_server.port
|
29
31
|
@pretty = dev_server.pretty?
|
32
|
+
@https = dev_server.https?
|
33
|
+
@hot = dev_server.hmr?
|
30
34
|
|
31
35
|
rescue Errno::ENOENT, NoMethodError
|
32
|
-
$stdout.puts "webpack dev_server configuration not found in #{config.config_path}[#{ENV["RAILS_ENV"]}]."
|
36
|
+
$stdout.puts "webpack dev_server configuration not found in #{@config.config_path}[#{ENV["RAILS_ENV"]}]."
|
33
37
|
$stdout.puts "Please run bundle exec rails webpacker:install to install Webpacker"
|
34
38
|
exit!
|
35
39
|
end
|
36
40
|
|
41
|
+
UNSUPPORTED_SWITCHES = %w[--host --port]
|
42
|
+
private_constant :UNSUPPORTED_SWITCHES
|
43
|
+
def detect_unsupported_switches!
|
44
|
+
unsupported_switches = UNSUPPORTED_SWITCHES & @argv
|
45
|
+
if unsupported_switches.any?
|
46
|
+
$stdout.puts "The following CLI switches are not supported by Webpacker: #{unsupported_switches.join(' ')}. Please edit your command and try again."
|
47
|
+
exit!
|
48
|
+
end
|
49
|
+
|
50
|
+
if @argv.include?("--https") && !@https
|
51
|
+
$stdout.puts "Please set https: true in webpacker.yml to use the --https command line flag."
|
52
|
+
exit!
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
37
56
|
def detect_port!
|
38
57
|
server = TCPServer.new(@hostname, @port)
|
39
58
|
server.close
|
40
59
|
|
41
60
|
rescue Errno::EADDRINUSE
|
42
|
-
$stdout.puts "Another program is running on port #{@port}. Set a new port in #{@
|
61
|
+
$stdout.puts "Another program is running on port #{@port}. Set a new port in #{@config.config_path} for dev_server"
|
43
62
|
exit!
|
44
63
|
end
|
45
64
|
|
46
65
|
def execute_cmd
|
47
66
|
env = Webpacker::Compiler.env
|
67
|
+
env["WEBPACKER_CONFIG"] = @webpacker_config
|
68
|
+
env["WEBPACK_SERVE"] = "true"
|
48
69
|
|
49
70
|
cmd = if node_modules_bin_exist?
|
50
|
-
["#{@node_modules_bin_path}/webpack
|
71
|
+
["#{@node_modules_bin_path}/webpack", "serve"]
|
51
72
|
else
|
52
|
-
["yarn", "webpack
|
73
|
+
["yarn", "webpack", "serve"]
|
53
74
|
end
|
54
75
|
|
55
|
-
if
|
56
|
-
cmd = [ "node", "--inspect-brk"] + cmd
|
57
|
-
|
76
|
+
if @argv.include?("--debug-webpacker")
|
77
|
+
cmd = [ "node", "--inspect-brk", "--trace-warnings" ] + cmd
|
78
|
+
@argv.delete "--debug-webpacker"
|
58
79
|
end
|
59
80
|
|
60
81
|
cmd += ["--config", @webpack_config]
|
61
82
|
cmd += ["--progress", "--color"] if @pretty
|
62
83
|
|
84
|
+
cmd += ["--hot"] if @hot
|
85
|
+
cmd += @argv
|
86
|
+
|
63
87
|
Dir.chdir(@app_path) do
|
64
88
|
Kernel.exec env, *cmd
|
65
89
|
end
|
data/lib/webpacker/env.rb
CHANGED
@@ -27,7 +27,11 @@ class Webpacker::Env
|
|
27
27
|
|
28
28
|
def available_environments
|
29
29
|
if config_path.exist?
|
30
|
-
|
30
|
+
begin
|
31
|
+
YAML.load_file(config_path.to_s, aliases: true)
|
32
|
+
rescue ArgumentError
|
33
|
+
YAML.load_file(config_path.to_s)
|
34
|
+
end
|
31
35
|
else
|
32
36
|
[].freeze
|
33
37
|
end
|
data/lib/webpacker/helper.rb
CHANGED
@@ -7,37 +7,40 @@ module Webpacker::Helper
|
|
7
7
|
end
|
8
8
|
|
9
9
|
# Computes the relative path for a given Webpacker asset.
|
10
|
-
# Returns the relative path using manifest.json and passes it to
|
11
|
-
# This will use
|
10
|
+
# Returns the relative path using manifest.json and passes it to path_to_asset helper.
|
11
|
+
# This will use path_to_asset internally, so most of their behaviors will be the same.
|
12
12
|
#
|
13
13
|
# Example:
|
14
14
|
#
|
15
|
-
# # When extract_css is false in webpacker.yml and the file is a css:
|
16
|
-
# <%= asset_pack_path 'calendar.css' %> # => nil
|
17
|
-
#
|
18
|
-
# # When extract_css is true in webpacker.yml or the file is not a css:
|
19
15
|
# <%= asset_pack_path 'calendar.css' %> # => "/packs/calendar-1016838bab065ae1e122.css"
|
20
16
|
def asset_pack_path(name, **options)
|
21
|
-
|
22
|
-
asset_path(current_webpacker_instance.manifest.lookup!(name), options)
|
23
|
-
end
|
17
|
+
path_to_asset(current_webpacker_instance.manifest.lookup!(name), options)
|
24
18
|
end
|
25
19
|
|
26
20
|
# Computes the absolute path for a given Webpacker asset.
|
27
|
-
# Returns the absolute path using manifest.json and passes it to
|
28
|
-
# This will use
|
21
|
+
# Returns the absolute path using manifest.json and passes it to url_to_asset helper.
|
22
|
+
# This will use url_to_asset internally, so most of their behaviors will be the same.
|
29
23
|
#
|
30
24
|
# Example:
|
31
25
|
#
|
32
|
-
# # When extract_css is false in webpacker.yml and the file is a css:
|
33
|
-
# <%= asset_pack_url 'calendar.css' %> # => nil
|
34
|
-
#
|
35
|
-
# # When extract_css is true in webpacker.yml or the file is not a css:
|
36
26
|
# <%= asset_pack_url 'calendar.css' %> # => "http://example.com/packs/calendar-1016838bab065ae1e122.css"
|
37
27
|
def asset_pack_url(name, **options)
|
38
|
-
|
39
|
-
|
40
|
-
|
28
|
+
url_to_asset(current_webpacker_instance.manifest.lookup!(name), options)
|
29
|
+
end
|
30
|
+
|
31
|
+
# Computes the relative path for a given Webpacker image with the same automated processing as image_pack_tag.
|
32
|
+
# Returns the relative path using manifest.json and passes it to path_to_asset helper.
|
33
|
+
# This will use path_to_asset internally, so most of their behaviors will be the same.
|
34
|
+
def image_pack_path(name, **options)
|
35
|
+
resolve_path_to_image(name, **options)
|
36
|
+
end
|
37
|
+
|
38
|
+
# Computes the absolute path for a given Webpacker image with the same automated
|
39
|
+
# processing as image_pack_tag. Returns the relative path using manifest.json
|
40
|
+
# and passes it to path_to_asset helper. This will use path_to_asset internally,
|
41
|
+
# so most of their behaviors will be the same.
|
42
|
+
def image_pack_url(name, **options)
|
43
|
+
resolve_path_to_image(name, **options.merge(protocol: :request))
|
41
44
|
end
|
42
45
|
|
43
46
|
# Creates an image tag that references the named pack file.
|
@@ -46,7 +49,16 @@ module Webpacker::Helper
|
|
46
49
|
#
|
47
50
|
# <%= image_pack_tag 'application.png', size: '16x10', alt: 'Edit Entry' %>
|
48
51
|
# <img alt='Edit Entry' src='/packs/application-k344a6d59eef8632c9d1.png' width='16' height='10' />
|
52
|
+
#
|
53
|
+
# <%= image_pack_tag 'picture.png', srcset: { 'picture-2x.png' => '2x' } %>
|
54
|
+
# <img srcset= "/packs/picture-2x-7cca48e6cae66ec07b8e.png 2x" src="/packs/picture-c38deda30895059837cf.png" >
|
49
55
|
def image_pack_tag(name, **options)
|
56
|
+
if options[:srcset] && !options[:srcset].is_a?(String)
|
57
|
+
options[:srcset] = options[:srcset].map do |src_name, size|
|
58
|
+
"#{resolve_path_to_image(src_name)} #{size}"
|
59
|
+
end.join(", ")
|
60
|
+
end
|
61
|
+
|
50
62
|
image_tag(resolve_path_to_image(name), options)
|
51
63
|
end
|
52
64
|
|
@@ -60,43 +72,37 @@ module Webpacker::Helper
|
|
60
72
|
favicon_link_tag(resolve_path_to_image(name), options)
|
61
73
|
end
|
62
74
|
|
63
|
-
# Creates a script tag that references the named pack file, as compiled by webpack per the entries list
|
64
|
-
# in config/webpack/shared.js. By default, this list is auto-generated to match everything in
|
65
|
-
# app/javascript/packs/*.js. In production mode, the digested reference is automatically looked up.
|
66
|
-
#
|
67
|
-
# Example:
|
68
|
-
#
|
69
|
-
# <%= javascript_pack_tag 'calendar', 'data-turbolinks-track': 'reload' %> # =>
|
70
|
-
# <script src="/packs/calendar-1016838bab065ae1e314.js" data-turbolinks-track="reload"></script>
|
71
|
-
def javascript_pack_tag(*names, **options)
|
72
|
-
javascript_include_tag(*sources_from_manifest_entries(names, type: :javascript), **options)
|
73
|
-
end
|
74
|
-
|
75
75
|
# Creates script tags that reference the js chunks from entrypoints when using split chunks API,
|
76
|
-
# as compiled by webpack per the entries list in
|
76
|
+
# as compiled by webpack per the entries list in package/environments/base.js.
|
77
77
|
# By default, this list is auto-generated to match everything in
|
78
|
-
# app/
|
78
|
+
# app/packs/entrypoints/*.js and all the dependent chunks. In production mode, the digested reference is automatically looked up.
|
79
79
|
# See: https://webpack.js.org/plugins/split-chunks-plugin/
|
80
|
+
#
|
80
81
|
# Example:
|
81
82
|
#
|
82
|
-
# <%=
|
83
|
-
# <script src="/packs/vendor-16838bab065ae1e314.chunk.js" data-turbolinks-track="reload"></script>
|
84
|
-
# <script src="/packs/calendar~runtime-16838bab065ae1e314.chunk.js" data-turbolinks-track="reload"></script>
|
85
|
-
# <script src="/packs/calendar-1016838bab065ae1e314.chunk.js" data-turbolinks-track="reload"></script>
|
86
|
-
# <script src="/packs/map~runtime-16838bab065ae1e314.chunk.js" data-turbolinks-track="reload"></script>
|
87
|
-
# <script src="/packs/map-16838bab065ae1e314.chunk.js" data-turbolinks-track="reload"></script>
|
83
|
+
# <%= javascript_pack_tag 'calendar', 'map', 'data-turbolinks-track': 'reload' %> # =>
|
84
|
+
# <script src="/packs/vendor-16838bab065ae1e314.chunk.js" data-turbolinks-track="reload" defer="true"></script>
|
85
|
+
# <script src="/packs/calendar~runtime-16838bab065ae1e314.chunk.js" data-turbolinks-track="reload" defer="true"></script>
|
86
|
+
# <script src="/packs/calendar-1016838bab065ae1e314.chunk.js" data-turbolinks-track="reload" defer="true"></script>
|
87
|
+
# <script src="/packs/map~runtime-16838bab065ae1e314.chunk.js" data-turbolinks-track="reload" defer="true"></script>
|
88
|
+
# <script src="/packs/map-16838bab065ae1e314.chunk.js" data-turbolinks-track="reload" defer="true"></script>
|
89
|
+
#
|
88
90
|
# DO:
|
89
|
-
#
|
91
|
+
#
|
92
|
+
# <%= javascript_pack_tag 'calendar', 'map' %>
|
93
|
+
#
|
90
94
|
# DON'T:
|
91
|
-
#
|
92
|
-
#
|
93
|
-
|
94
|
-
|
95
|
+
#
|
96
|
+
# <%= javascript_pack_tag 'calendar' %>
|
97
|
+
# <%= javascript_pack_tag 'map' %>
|
98
|
+
def javascript_pack_tag(*names, defer: true, **options)
|
99
|
+
javascript_include_tag(*sources_from_manifest_entrypoints(names, type: :javascript), **options.tap { |o| o[:defer] = defer })
|
95
100
|
end
|
96
101
|
|
97
102
|
# Creates a link tag, for preloading, that references a given Webpacker asset.
|
98
103
|
# In production mode, the digested reference is automatically looked up.
|
99
104
|
# See: https://developer.mozilla.org/en-US/docs/Web/HTML/Preloading_content
|
105
|
+
#
|
100
106
|
# Example:
|
101
107
|
#
|
102
108
|
# <%= preload_pack_asset 'fonts/fa-regular-400.woff2' %> # =>
|
@@ -109,68 +115,47 @@ module Webpacker::Helper
|
|
109
115
|
end
|
110
116
|
end
|
111
117
|
|
112
|
-
# Creates a link tag that references the named pack file, as compiled by webpack per the entries list
|
113
|
-
# in config/webpack/shared.js. By default, this list is auto-generated to match everything in
|
114
|
-
# app/javascript/packs/*.js. In production mode, the digested reference is automatically looked up.
|
115
|
-
#
|
116
|
-
# Note: If the development server is running and hot module replacement is active, this will return nothing.
|
117
|
-
# In that setup you need to configure your styles to be inlined in your JavaScript for hot reloading.
|
118
|
-
#
|
119
|
-
# Examples:
|
120
|
-
#
|
121
|
-
# # When extract_css is false in webpacker.yml:
|
122
|
-
# <%= stylesheet_pack_tag 'calendar', 'data-turbolinks-track': 'reload' %> # =>
|
123
|
-
# nil
|
124
|
-
#
|
125
|
-
# # When extract_css is true in webpacker.yml:
|
126
|
-
# <%= stylesheet_pack_tag 'calendar', 'data-turbolinks-track': 'reload' %> # =>
|
127
|
-
# <link rel="stylesheet" media="screen" href="/packs/calendar-1016838bab065ae1e122.css" data-turbolinks-track="reload" />
|
128
|
-
def stylesheet_pack_tag(*names, **options)
|
129
|
-
if current_webpacker_instance.config.extract_css?
|
130
|
-
stylesheet_link_tag(*sources_from_manifest_entries(names, type: :stylesheet), **options)
|
131
|
-
end
|
132
|
-
end
|
133
|
-
|
134
118
|
# Creates link tags that reference the css chunks from entrypoints when using split chunks API,
|
135
|
-
# as compiled by webpack per the entries list in
|
119
|
+
# as compiled by webpack per the entries list in package/environments/base.js.
|
136
120
|
# By default, this list is auto-generated to match everything in
|
137
|
-
# app/
|
121
|
+
# app/packs/entrypoints/*.js and all the dependent chunks. In production mode, the digested reference is automatically looked up.
|
138
122
|
# See: https://webpack.js.org/plugins/split-chunks-plugin/
|
139
123
|
#
|
140
124
|
# Examples:
|
141
125
|
#
|
142
|
-
# <%=
|
126
|
+
# <%= stylesheet_pack_tag 'calendar', 'map' %> # =>
|
143
127
|
# <link rel="stylesheet" media="screen" href="/packs/3-8c7ce31a.chunk.css" />
|
144
128
|
# <link rel="stylesheet" media="screen" href="/packs/calendar-8c7ce31a.chunk.css" />
|
145
129
|
# <link rel="stylesheet" media="screen" href="/packs/map-8c7ce31a.chunk.css" />
|
130
|
+
#
|
131
|
+
# When using the webpack-dev-server, CSS is inlined so HMR can be turned on for CSS,
|
132
|
+
# including CSS modules
|
133
|
+
# <%= stylesheet_pack_tag 'calendar', 'map' %> # => nil
|
134
|
+
#
|
146
135
|
# DO:
|
147
|
-
#
|
136
|
+
#
|
137
|
+
# <%= stylesheet_pack_tag 'calendar', 'map' %>
|
138
|
+
#
|
148
139
|
# DON'T:
|
149
|
-
#
|
150
|
-
#
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
140
|
+
#
|
141
|
+
# <%= stylesheet_pack_tag 'calendar' %>
|
142
|
+
# <%= stylesheet_pack_tag 'map' %>
|
143
|
+
def stylesheet_pack_tag(*names, **options)
|
144
|
+
return "" if Webpacker.inlining_css?
|
145
|
+
|
146
|
+
stylesheet_link_tag(*sources_from_manifest_entrypoints(names, type: :stylesheet), **options)
|
155
147
|
end
|
156
148
|
|
157
149
|
private
|
158
|
-
def stylesheet?(name)
|
159
|
-
File.extname(name) == ".css"
|
160
|
-
end
|
161
|
-
|
162
|
-
def sources_from_manifest_entries(names, type:)
|
163
|
-
names.map { |name| current_webpacker_instance.manifest.lookup!(name, type: type) }.flatten
|
164
|
-
end
|
165
150
|
|
166
151
|
def sources_from_manifest_entrypoints(names, type:)
|
167
|
-
names.map { |name| current_webpacker_instance.manifest.lookup_pack_with_chunks!(name, type: type) }.flatten.uniq
|
152
|
+
names.map { |name| current_webpacker_instance.manifest.lookup_pack_with_chunks!(name.to_s, type: type) }.flatten.uniq
|
168
153
|
end
|
169
154
|
|
170
|
-
def resolve_path_to_image(name)
|
171
|
-
path = name.starts_with?("
|
172
|
-
|
155
|
+
def resolve_path_to_image(name, **options)
|
156
|
+
path = name.starts_with?("static/") ? name : "static/#{name}"
|
157
|
+
path_to_asset(current_webpacker_instance.manifest.lookup!(path), options)
|
173
158
|
rescue
|
174
|
-
|
159
|
+
path_to_asset(current_webpacker_instance.manifest.lookup!(name), options)
|
175
160
|
end
|
176
161
|
end
|
data/lib/webpacker/instance.rb
CHANGED
data/lib/webpacker/manifest.rb
CHANGED
@@ -23,13 +23,13 @@ class Webpacker::Manifest
|
|
23
23
|
|
24
24
|
manifest_pack_type = manifest_type(pack_type[:type])
|
25
25
|
manifest_pack_name = manifest_name(name, manifest_pack_type)
|
26
|
-
find("entrypoints")[manifest_pack_name][manifest_pack_type]
|
26
|
+
find("entrypoints")[manifest_pack_name]["assets"][manifest_pack_type]
|
27
27
|
rescue NoMethodError
|
28
28
|
nil
|
29
29
|
end
|
30
30
|
|
31
31
|
def lookup_pack_with_chunks!(name, pack_type = {})
|
32
|
-
lookup_pack_with_chunks(name, pack_type) || handle_missing_entry(name)
|
32
|
+
lookup_pack_with_chunks(name, pack_type) || handle_missing_entry(name, pack_type)
|
33
33
|
end
|
34
34
|
|
35
35
|
# Computes the relative path for a given Webpacker asset using manifest.json.
|
@@ -46,7 +46,7 @@ class Webpacker::Manifest
|
|
46
46
|
|
47
47
|
# Like lookup, except that if no asset is found, raises a Webpacker::Manifest::MissingEntryError.
|
48
48
|
def lookup!(name, pack_type = {})
|
49
|
-
lookup(name, pack_type) || handle_missing_entry(name)
|
49
|
+
lookup(name, pack_type) || handle_missing_entry(name, pack_type)
|
50
50
|
end
|
51
51
|
|
52
52
|
private
|
@@ -75,8 +75,8 @@ class Webpacker::Manifest
|
|
75
75
|
"#{name}.#{manifest_type(pack_type)}"
|
76
76
|
end
|
77
77
|
|
78
|
-
def handle_missing_entry(name)
|
79
|
-
raise Webpacker::Manifest::MissingEntryError, missing_file_from_manifest_error(name)
|
78
|
+
def handle_missing_entry(name, pack_type)
|
79
|
+
raise Webpacker::Manifest::MissingEntryError, missing_file_from_manifest_error(full_pack_name(name, pack_type[:type]))
|
80
80
|
end
|
81
81
|
|
82
82
|
def load
|
@@ -91,8 +91,7 @@ class Webpacker::Manifest
|
|
91
91
|
# manifest hash the entrypoints are defined by their pack name without the extension.
|
92
92
|
# When the user provides a name with a file extension, we want to try to strip it off.
|
93
93
|
def manifest_name(name, pack_type)
|
94
|
-
|
95
|
-
File.basename(name, pack_type)
|
94
|
+
name.chomp(".#{pack_type}")
|
96
95
|
end
|
97
96
|
|
98
97
|
def manifest_type(pack_type)
|