webpacker 5.4.1 → 6.0.0.rc.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.eslintrc.js +1 -1
- data/.github/workflows/jest.yml +5 -2
- data/.github/workflows/js-lint.yml +5 -2
- data/.github/workflows/rubocop.yml +1 -1
- data/.github/workflows/ruby.yml +19 -4
- data/.gitignore +2 -0
- data/.node-version +1 -1
- data/.rubocop.yml +4 -3
- data/CHANGELOG.md +24 -6
- data/CONTRIBUTING.md +1 -1
- data/Gemfile.lock +82 -82
- data/README.md +377 -172
- 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 +57 -25
- data/docs/v6_upgrade.md +75 -0
- data/gemfiles/Gemfile-rails.6.1.x +12 -0
- 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 +20 -50
- data/lib/install/package.json +17 -0
- data/lib/install/{javascript/packs → packs/entrypoints}/application.js +4 -3
- data/lib/install/template.rb +54 -28
- data/lib/tasks/webpacker/binstubs.rake +6 -4
- data/lib/tasks/webpacker/check_binstubs.rake +4 -4
- data/lib/tasks/webpacker/check_node.rake +3 -0
- data/lib/tasks/webpacker/check_yarn.rake +3 -0
- data/lib/tasks/webpacker/clobber.rake +1 -1
- 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 +9 -7
- data/lib/tasks/webpacker.rake +2 -11
- data/lib/tasks/yarn.rake +36 -0
- data/lib/webpacker/commands.rb +21 -16
- data/lib/webpacker/compiler.rb +16 -9
- data/lib/webpacker/configuration.rb +8 -32
- data/lib/webpacker/dev_server.rb +6 -0
- data/lib/webpacker/dev_server_runner.rb +28 -4
- data/lib/webpacker/helper.rb +47 -81
- data/lib/webpacker/instance.rb +4 -0
- data/lib/webpacker/manifest.rb +2 -3
- data/lib/webpacker/railtie.rb +1 -2
- data/lib/webpacker/runner.rb +1 -1
- data/lib/webpacker/version.rb +1 -1
- data/lib/webpacker/webpack_runner.rb +6 -0
- data/lib/webpacker.rb +1 -1
- data/package/__tests__/config.js +5 -37
- data/package/__tests__/development.js +14 -15
- 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 +6 -14
- data/package/env.js +13 -4
- data/package/environments/__tests__/base.js +20 -52
- data/package/environments/base.js +68 -128
- data/package/environments/development.js +50 -44
- data/package/environments/production.js +66 -64
- data/package/environments/test.js +2 -2
- data/package/index.js +15 -8
- data/package/inliningCss.js +7 -0
- data/package/rules/babel.js +10 -8
- data/package/rules/coffee.js +6 -0
- data/package/rules/erb.js +15 -0
- data/package/rules/file.js +21 -19
- 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 +9 -10
- 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 +12 -32
- data/test/command_test.rb +76 -0
- data/test/compiler_test.rb +0 -12
- data/test/configuration_test.rb +4 -35
- data/test/dev_server_runner_test.rb +36 -6
- data/test/engine_rake_tasks_test.rb +39 -0
- data/test/helper_test.rb +79 -77
- data/test/manifest_test.rb +16 -0
- 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 +1 -10
- data/test/test_app/app/{javascript/packs → packs/entrypoints}/application.js +1 -1
- data/test/test_app/app/{javascript/packs → packs/entrypoints}/multi_entry.css +0 -0
- data/test/test_app/app/{javascript/packs → packs/entrypoints}/multi_entry.js +0 -0
- data/test/test_app/config/webpacker.yml +5 -31
- 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 -18
- data/test/test_app/some.config.js +0 -0
- data/test/webpack_runner_test.rb +9 -3
- data/test/webpacker_test.rb +17 -0
- data/webpacker.gemspec +1 -1
- data/yarn.lock +1050 -3966
- metadata +59 -91
- data/.travis.yml +0 -43
- data/docs/assets.md +0 -119
- data/docs/cloud9.md +0 -310
- data/docs/css.md +0 -308
- data/docs/docker.md +0 -68
- data/docs/engines.md +0 -213
- data/docs/env.md +0 -63
- data/docs/es6.md +0 -72
- data/docs/folder-structure.md +0 -66
- data/docs/integrations.md +0 -220
- data/docs/misc.md +0 -23
- data/docs/props.md +0 -223
- data/docs/target.md +0 -22
- data/docs/testing.md +0 -136
- data/docs/typescript.md +0 -190
- 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/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 -76
- 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 -93
- data/lib/install/examples/react/hello_react.jsx +0 -26
- data/lib/install/examples/react/tsconfig.json +0 -21
- 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 -24
- 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/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 -39
- 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 -22
- 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
@@ -28,14 +28,14 @@ class Webpacker::Compiler
|
|
28
28
|
record_compilation_digest
|
29
29
|
end
|
30
30
|
else
|
31
|
-
logger.
|
31
|
+
logger.debug "Everything's up-to-date. Nothing to do"
|
32
32
|
true
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
36
36
|
# Returns true if all the compiled packs are up to date with the underlying asset files.
|
37
37
|
def fresh?
|
38
|
-
watched_files_digest
|
38
|
+
last_compilation_digest&.== watched_files_digest
|
39
39
|
end
|
40
40
|
|
41
41
|
# Returns true if the compiled packs are out of date with the underlying asset files.
|
@@ -53,10 +53,11 @@ class Webpacker::Compiler
|
|
53
53
|
|
54
54
|
def watched_files_digest
|
55
55
|
warn "Webpacker::Compiler.watched_paths has been deprecated. Set additional_paths in webpacker.yml instead." unless watched_paths.empty?
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
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
|
60
61
|
end
|
61
62
|
|
62
63
|
def record_compilation_digest
|
@@ -64,12 +65,18 @@ class Webpacker::Compiler
|
|
64
65
|
compilation_digest_path.write(watched_files_digest)
|
65
66
|
end
|
66
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
|
+
|
67
74
|
def run_webpack
|
68
75
|
logger.info "Compiling..."
|
69
76
|
|
70
77
|
stdout, stderr, status = Open3.capture3(
|
71
78
|
webpack_env,
|
72
|
-
"#{
|
79
|
+
"#{optionalRubyRunner} ./bin/webpack",
|
73
80
|
chdir: File.expand_path(config.root_path)
|
74
81
|
)
|
75
82
|
|
@@ -90,8 +97,8 @@ class Webpacker::Compiler
|
|
90
97
|
|
91
98
|
def default_watched_paths
|
92
99
|
[
|
93
|
-
*config.
|
94
|
-
config.
|
100
|
+
*config.additional_paths,
|
101
|
+
"#{config.source_path}/**/*",
|
95
102
|
"yarn.lock", "package.json",
|
96
103
|
"config/webpack/**/*"
|
97
104
|
].freeze
|
@@ -23,16 +23,8 @@ class Webpacker::Configuration
|
|
23
23
|
root_path.join(fetch(:source_path))
|
24
24
|
end
|
25
25
|
|
26
|
-
def source_path_globbed
|
27
|
-
globbed_path_with_extensions(source_path.relative_path_from(root_path))
|
28
|
-
end
|
29
|
-
|
30
26
|
def additional_paths
|
31
|
-
fetch(:additional_paths)
|
32
|
-
end
|
33
|
-
|
34
|
-
def additional_paths_globbed
|
35
|
-
additional_paths.map { |p| globbed_path_with_extensions(p) }
|
27
|
+
fetch(:additional_paths)
|
36
28
|
end
|
37
29
|
|
38
30
|
def source_entry_path
|
@@ -59,35 +51,23 @@ 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
|
-
warn
|
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
|
68
60
|
end
|
69
61
|
|
70
62
|
def webpack_compile_output?
|
71
63
|
fetch(:webpack_compile_output)
|
72
64
|
end
|
73
65
|
|
74
|
-
def
|
75
|
-
fetch(
|
66
|
+
def fetch(key)
|
67
|
+
data.fetch(key, defaults[key])
|
76
68
|
end
|
77
69
|
|
78
70
|
private
|
79
|
-
def resolved_paths
|
80
|
-
paths = data.fetch(:resolved_paths, [])
|
81
|
-
|
82
|
-
warn "The resolved_paths option has been deprecated. Use additional_paths instead." unless paths.empty?
|
83
|
-
|
84
|
-
paths
|
85
|
-
end
|
86
|
-
|
87
|
-
def fetch(key)
|
88
|
-
data.fetch(key, defaults[key])
|
89
|
-
end
|
90
|
-
|
91
71
|
def data
|
92
72
|
@data ||= load
|
93
73
|
end
|
@@ -121,8 +101,4 @@ class Webpacker::Configuration
|
|
121
101
|
HashWithIndifferentAccess.new(config[env])
|
122
102
|
end
|
123
103
|
end
|
124
|
-
|
125
|
-
def globbed_path_with_extensions(path)
|
126
|
-
"#{path}/**/*{#{extensions.join(',')}}"
|
127
|
-
end
|
128
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
|
|
@@ -8,17 +8,19 @@ 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
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
|
|
@@ -27,6 +29,8 @@ module Webpacker
|
|
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
36
|
$stdout.puts "webpack dev_server configuration not found in #{@config.config_path}[#{ENV["RAILS_ENV"]}]."
|
@@ -34,6 +38,21 @@ module 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
|
@@ -46,20 +65,25 @@ module Webpacker
|
|
46
65
|
def execute_cmd
|
47
66
|
env = Webpacker::Compiler.env
|
48
67
|
env["WEBPACKER_CONFIG"] = @webpacker_config
|
68
|
+
env["WEBPACK_SERVE"] = "true"
|
49
69
|
|
50
70
|
cmd = if node_modules_bin_exist?
|
51
|
-
["#{@node_modules_bin_path}/webpack
|
71
|
+
["#{@node_modules_bin_path}/webpack", "serve"]
|
52
72
|
else
|
53
|
-
["yarn", "webpack
|
73
|
+
["yarn", "webpack", "serve"]
|
54
74
|
end
|
55
75
|
|
56
76
|
if @argv.include?("--debug-webpacker")
|
57
|
-
cmd = [ "node", "--inspect-brk"] + cmd
|
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/helper.rb
CHANGED
@@ -12,15 +12,9 @@ module Webpacker::Helper
|
|
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
|
-
path_to_asset(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.
|
@@ -29,15 +23,24 @@ module Webpacker::Helper
|
|
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.
|
@@ -69,43 +72,31 @@ module Webpacker::Helper
|
|
69
72
|
favicon_link_tag(resolve_path_to_image(name), options)
|
70
73
|
end
|
71
74
|
|
72
|
-
# Creates a script tag that references the named pack file, as compiled by webpack per the entries list
|
73
|
-
# in package/environments/base.js. By default, this list is auto-generated to match everything in
|
74
|
-
# app/javascript/packs/*.js. In production mode, the digested reference is automatically looked up.
|
75
|
-
#
|
76
|
-
# Example:
|
77
|
-
#
|
78
|
-
# <%= javascript_pack_tag 'calendar', 'data-turbolinks-track': 'reload' %> # =>
|
79
|
-
# <script src="/packs/calendar-1016838bab065ae1e314.js" data-turbolinks-track="reload"></script>
|
80
|
-
def javascript_pack_tag(*names, **options)
|
81
|
-
javascript_include_tag(*sources_from_manifest_entries(names, type: :javascript), **options)
|
82
|
-
end
|
83
|
-
|
84
75
|
# Creates script tags that reference the js chunks from entrypoints when using split chunks API,
|
85
76
|
# as compiled by webpack per the entries list in package/environments/base.js.
|
86
77
|
# By default, this list is auto-generated to match everything in
|
87
|
-
# app/
|
78
|
+
# app/packs/entrypoints/*.js and all the dependent chunks. In production mode, the digested reference is automatically looked up.
|
88
79
|
# See: https://webpack.js.org/plugins/split-chunks-plugin/
|
89
80
|
#
|
90
81
|
# Example:
|
91
82
|
#
|
92
|
-
# <%=
|
93
|
-
# <script src="/packs/vendor-16838bab065ae1e314.chunk.js" data-turbolinks-track="reload"></script>
|
94
|
-
# <script src="/packs/calendar~runtime-16838bab065ae1e314.chunk.js" data-turbolinks-track="reload"></script>
|
95
|
-
# <script src="/packs/calendar-1016838bab065ae1e314.chunk.js" data-turbolinks-track="reload"></script>
|
96
|
-
# <script src="/packs/map~runtime-16838bab065ae1e314.chunk.js" data-turbolinks-track="reload"></script>
|
97
|
-
# <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>
|
98
89
|
#
|
99
90
|
# DO:
|
100
91
|
#
|
101
|
-
# <%=
|
92
|
+
# <%= javascript_pack_tag 'calendar', 'map' %>
|
102
93
|
#
|
103
94
|
# DON'T:
|
104
95
|
#
|
105
|
-
# <%=
|
106
|
-
# <%=
|
107
|
-
def
|
108
|
-
javascript_include_tag(*sources_from_manifest_entrypoints(names, type: :javascript), **options)
|
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 })
|
109
100
|
end
|
110
101
|
|
111
102
|
# Creates a link tag, for preloading, that references a given Webpacker asset.
|
@@ -124,72 +115,47 @@ module Webpacker::Helper
|
|
124
115
|
end
|
125
116
|
end
|
126
117
|
|
127
|
-
# Creates a link tag that references the named pack file, as compiled by webpack per the entries list
|
128
|
-
# in package/environments/base.js. By default, this list is auto-generated to match everything in
|
129
|
-
# app/javascript/packs/*.js. In production mode, the digested reference is automatically looked up.
|
130
|
-
#
|
131
|
-
# Note: If the development server is running and hot module replacement is active, this will return nothing.
|
132
|
-
# In that setup you need to configure your styles to be inlined in your JavaScript for hot reloading.
|
133
|
-
#
|
134
|
-
# Examples:
|
135
|
-
#
|
136
|
-
# # When extract_css is false in webpacker.yml:
|
137
|
-
# <%= stylesheet_pack_tag 'calendar', 'data-turbolinks-track': 'reload' %> # =>
|
138
|
-
# nil
|
139
|
-
#
|
140
|
-
# # When extract_css is true in webpacker.yml:
|
141
|
-
# <%= stylesheet_pack_tag 'calendar', 'data-turbolinks-track': 'reload' %> # =>
|
142
|
-
# <link rel="stylesheet" media="screen" href="/packs/calendar-1016838bab065ae1e122.css" data-turbolinks-track="reload" />
|
143
|
-
def stylesheet_pack_tag(*names, **options)
|
144
|
-
if current_webpacker_instance.config.extract_css?
|
145
|
-
stylesheet_link_tag(*sources_from_manifest_entries(names, type: :stylesheet), **options)
|
146
|
-
end
|
147
|
-
end
|
148
|
-
|
149
118
|
# Creates link tags that reference the css chunks from entrypoints when using split chunks API,
|
150
119
|
# as compiled by webpack per the entries list in package/environments/base.js.
|
151
120
|
# By default, this list is auto-generated to match everything in
|
152
|
-
# app/
|
121
|
+
# app/packs/entrypoints/*.js and all the dependent chunks. In production mode, the digested reference is automatically looked up.
|
153
122
|
# See: https://webpack.js.org/plugins/split-chunks-plugin/
|
154
123
|
#
|
155
124
|
# Examples:
|
156
125
|
#
|
157
|
-
# <%=
|
126
|
+
# <%= stylesheet_pack_tag 'calendar', 'map' %> # =>
|
158
127
|
# <link rel="stylesheet" media="screen" href="/packs/3-8c7ce31a.chunk.css" />
|
159
128
|
# <link rel="stylesheet" media="screen" href="/packs/calendar-8c7ce31a.chunk.css" />
|
160
129
|
# <link rel="stylesheet" media="screen" href="/packs/map-8c7ce31a.chunk.css" />
|
161
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
|
+
#
|
162
135
|
# DO:
|
163
136
|
#
|
164
|
-
# <%=
|
137
|
+
# <%= stylesheet_pack_tag 'calendar', 'map' %>
|
165
138
|
#
|
166
139
|
# DON'T:
|
167
140
|
#
|
168
|
-
# <%=
|
169
|
-
# <%=
|
170
|
-
def
|
171
|
-
if
|
172
|
-
|
173
|
-
|
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)
|
174
147
|
end
|
175
148
|
|
176
149
|
private
|
177
|
-
def stylesheet?(name)
|
178
|
-
File.extname(name) == ".css"
|
179
|
-
end
|
180
|
-
|
181
|
-
def sources_from_manifest_entries(names, type:)
|
182
|
-
names.map { |name| current_webpacker_instance.manifest.lookup!(name, type: type) }.flatten
|
183
|
-
end
|
184
150
|
|
185
151
|
def sources_from_manifest_entrypoints(names, type:)
|
186
|
-
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
|
187
153
|
end
|
188
154
|
|
189
|
-
def resolve_path_to_image(name)
|
190
|
-
path = name.starts_with?("
|
191
|
-
path_to_asset(current_webpacker_instance.manifest.lookup!(path))
|
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)
|
192
158
|
rescue
|
193
|
-
path_to_asset(current_webpacker_instance.manifest.lookup!(name))
|
159
|
+
path_to_asset(current_webpacker_instance.manifest.lookup!(name), options)
|
194
160
|
end
|
195
161
|
end
|
data/lib/webpacker/instance.rb
CHANGED
data/lib/webpacker/manifest.rb
CHANGED
@@ -23,7 +23,7 @@ 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
|
@@ -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)
|