webpacker 5.0.1 → 6.0.0.beta
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 +4 -4
- data/.eslintrc.js +8 -8
- data/.github/workflows/jest.yml +38 -0
- data/.github/workflows/js-lint.yml +39 -0
- data/.github/workflows/rubocop.yml +39 -0
- data/.github/workflows/ruby.yml +70 -0
- data/.gitignore +2 -0
- data/.node-version +1 -1
- data/.rubocop.yml +11 -16
- data/6_0_upgrade.md +43 -0
- data/CHANGELOG.md +49 -3
- data/CONTRIBUTING.md +1 -1
- data/Gemfile.lock +91 -85
- data/README.md +233 -133
- 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 +9 -42
- data/lib/install/javascript/packs/application.css +9 -0
- data/lib/install/javascript/packs/application.js +3 -1
- data/lib/install/template.rb +33 -19
- data/lib/tasks/webpacker.rake +2 -11
- data/lib/tasks/webpacker/binstubs.rake +6 -4
- data/lib/tasks/webpacker/check_binstubs.rake +4 -4
- data/lib/tasks/webpacker/check_node.rake +1 -1
- data/lib/tasks/webpacker/check_yarn.rake +2 -3
- 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_install.rake +2 -1
- data/lib/tasks/webpacker/yarn_install.rake +9 -1
- data/lib/webpacker/commands.rb +1 -1
- data/lib/webpacker/compiler.rb +22 -11
- data/lib/webpacker/configuration.rb +7 -27
- data/lib/webpacker/dev_server_proxy.rb +3 -1
- data/lib/webpacker/dev_server_runner.rb +23 -4
- data/lib/webpacker/helper.rb +55 -46
- data/lib/webpacker/manifest.rb +1 -1
- data/lib/webpacker/railtie.rb +0 -43
- data/lib/webpacker/runner.rb +1 -0
- data/lib/webpacker/version.rb +1 -1
- data/lib/webpacker/webpack_runner.rb +7 -2
- data/package.json +27 -43
- data/package/__tests__/config.js +6 -27
- data/package/__tests__/dev_server.js +2 -0
- data/package/__tests__/development.js +18 -7
- data/package/__tests__/env.js +12 -4
- 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 +55 -0
- data/package/config.js +4 -9
- data/package/configPath.js +3 -0
- data/package/dev_server.js +1 -1
- data/package/env.js +9 -4
- data/package/environments/__tests__/base.js +21 -36
- data/package/environments/base.js +63 -127
- data/package/environments/development.js +46 -39
- data/package/environments/production.js +63 -70
- data/package/environments/test.js +2 -2
- data/package/index.js +13 -8
- 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 +19 -18
- data/package/rules/index.js +15 -18
- data/package/rules/less.js +22 -0
- data/package/rules/sass.js +13 -10
- data/package/rules/svg.js +20 -0
- data/package/utils/get_style_rule.js +26 -36
- data/package/utils/helpers.js +26 -35
- data/test/compiler_test.rb +4 -11
- data/test/configuration_test.rb +2 -32
- data/test/dev_server_runner_test.rb +25 -6
- data/test/engine_rake_tasks_test.rb +39 -0
- data/test/helper_test.rb +18 -9
- 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.ru +5 -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/package.json +7 -0
- data/test/rake_tasks_test.rb +1 -10
- data/test/test_app/config/application.rb +0 -1
- data/test/test_app/config/webpacker.yml +3 -21
- data/test/test_app/config/webpacker_public_root.yml +0 -1
- data/test/test_app/public/packs/manifest.json +18 -13
- data/test/test_app/some.config.js +0 -0
- data/test/webpack_runner_test.rb +10 -4
- data/webpacker.gemspec +1 -1
- data/yarn.lock +2657 -6224
- metadata +49 -90
- data/.travis.yml +0 -43
- data/docs/assets.md +0 -119
- data/docs/cloud9.md +0 -310
- data/docs/css.md +0 -253
- data/docs/deployment.md +0 -130
- data/docs/docker.md +0 -68
- data/docs/engines.md +0 -213
- data/docs/env.md +0 -65
- 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/testing.md +0 -137
- data/docs/troubleshooting.md +0 -156
- data/docs/typescript.md +0 -125
- 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 -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.js +0 -7
- 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/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
|
@@ -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,26 +51,18 @@ 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 extract_css?
|
|
79
|
-
fetch(:extract_css)
|
|
80
|
-
end
|
|
81
|
-
|
|
82
66
|
private
|
|
83
67
|
def fetch(key)
|
|
84
68
|
data.fetch(key, defaults[key])
|
|
@@ -106,8 +90,4 @@ class Webpacker::Configuration
|
|
|
106
90
|
@defaults ||= \
|
|
107
91
|
HashWithIndifferentAccess.new(YAML.load_file(File.expand_path("../../install/config/webpacker.yml", __FILE__))[env])
|
|
108
92
|
end
|
|
109
|
-
|
|
110
|
-
def globbed_path_with_extensions(path)
|
|
111
|
-
"#{path}/**/*{#{extensions.join(',')}}"
|
|
112
|
-
end
|
|
113
93
|
end
|
|
@@ -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,11 +8,13 @@ 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
|
|
|
@@ -27,6 +29,7 @@ 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?
|
|
30
33
|
|
|
31
34
|
rescue Errno::ENOENT, NoMethodError
|
|
32
35
|
$stdout.puts "webpack dev_server configuration not found in #{@config.config_path}[#{ENV["RAILS_ENV"]}]."
|
|
@@ -34,6 +37,21 @@ module Webpacker
|
|
|
34
37
|
exit!
|
|
35
38
|
end
|
|
36
39
|
|
|
40
|
+
UNSUPPORTED_SWITCHES = %w[--host --port]
|
|
41
|
+
private_constant :UNSUPPORTED_SWITCHES
|
|
42
|
+
def detect_unsupported_switches!
|
|
43
|
+
unsupported_switches = UNSUPPORTED_SWITCHES & @argv
|
|
44
|
+
if unsupported_switches.any?
|
|
45
|
+
$stdout.puts "The following CLI switches are not supported by Webpacker: #{unsupported_switches.join(' ')}. Please edit your command and try again."
|
|
46
|
+
exit!
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
if @argv.include?("--https") && !@https
|
|
50
|
+
$stdout.puts "Please set https: true in webpacker.yml to use the --https command line flag."
|
|
51
|
+
exit!
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
37
55
|
def detect_port!
|
|
38
56
|
server = TCPServer.new(@hostname, @port)
|
|
39
57
|
server.close
|
|
@@ -45,20 +63,21 @@ module Webpacker
|
|
|
45
63
|
|
|
46
64
|
def execute_cmd
|
|
47
65
|
env = Webpacker::Compiler.env
|
|
66
|
+
env["WEBPACKER_CONFIG"] = @webpacker_config
|
|
48
67
|
|
|
49
68
|
cmd = if node_modules_bin_exist?
|
|
50
|
-
["#{@node_modules_bin_path}/webpack
|
|
69
|
+
["#{@node_modules_bin_path}/webpack", "serve"]
|
|
51
70
|
else
|
|
52
|
-
["yarn", "webpack
|
|
71
|
+
["yarn", "webpack", "serve"]
|
|
53
72
|
end
|
|
54
73
|
|
|
55
|
-
if
|
|
74
|
+
if @argv.include?("--debug-webpacker")
|
|
56
75
|
cmd = [ "node", "--inspect-brk"] + cmd
|
|
57
|
-
ARGV.delete("--debug")
|
|
58
76
|
end
|
|
59
77
|
|
|
60
78
|
cmd += ["--config", @webpack_config]
|
|
61
79
|
cmd += ["--progress", "--color"] if @pretty
|
|
80
|
+
cmd += @argv
|
|
62
81
|
|
|
63
82
|
Dir.chdir(@app_path) do
|
|
64
83
|
Kernel.exec env, *cmd
|
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
|
|
|
@@ -61,7 +73,7 @@ module Webpacker::Helper
|
|
|
61
73
|
end
|
|
62
74
|
|
|
63
75
|
# Creates a script tag that references the named pack file, as compiled by webpack per the entries list
|
|
64
|
-
# in
|
|
76
|
+
# in package/environments/base.js. By default, this list is auto-generated to match everything in
|
|
65
77
|
# app/javascript/packs/*.js. In production mode, the digested reference is automatically looked up.
|
|
66
78
|
#
|
|
67
79
|
# Example:
|
|
@@ -73,10 +85,11 @@ module Webpacker::Helper
|
|
|
73
85
|
end
|
|
74
86
|
|
|
75
87
|
# 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
|
|
88
|
+
# as compiled by webpack per the entries list in package/environments/base.js.
|
|
77
89
|
# By default, this list is auto-generated to match everything in
|
|
78
90
|
# app/javascript/packs/*.js and all the dependent chunks. In production mode, the digested reference is automatically looked up.
|
|
79
91
|
# See: https://webpack.js.org/plugins/split-chunks-plugin/
|
|
92
|
+
#
|
|
80
93
|
# Example:
|
|
81
94
|
#
|
|
82
95
|
# <%= javascript_packs_with_chunks_tag 'calendar', 'map', 'data-turbolinks-track': 'reload' %> # =>
|
|
@@ -85,11 +98,15 @@ module Webpacker::Helper
|
|
|
85
98
|
# <script src="/packs/calendar-1016838bab065ae1e314.chunk.js" data-turbolinks-track="reload"></script>
|
|
86
99
|
# <script src="/packs/map~runtime-16838bab065ae1e314.chunk.js" data-turbolinks-track="reload"></script>
|
|
87
100
|
# <script src="/packs/map-16838bab065ae1e314.chunk.js" data-turbolinks-track="reload"></script>
|
|
101
|
+
#
|
|
88
102
|
# DO:
|
|
89
|
-
#
|
|
103
|
+
#
|
|
104
|
+
# <%= javascript_packs_with_chunks_tag 'calendar', 'map' %>
|
|
105
|
+
#
|
|
90
106
|
# DON'T:
|
|
91
|
-
#
|
|
92
|
-
#
|
|
107
|
+
#
|
|
108
|
+
# <%= javascript_packs_with_chunks_tag 'calendar' %>
|
|
109
|
+
# <%= javascript_packs_with_chunks_tag 'map' %>
|
|
93
110
|
def javascript_packs_with_chunks_tag(*names, **options)
|
|
94
111
|
javascript_include_tag(*sources_from_manifest_entrypoints(names, type: :javascript), **options)
|
|
95
112
|
end
|
|
@@ -97,6 +114,7 @@ module Webpacker::Helper
|
|
|
97
114
|
# Creates a link tag, for preloading, that references a given Webpacker asset.
|
|
98
115
|
# In production mode, the digested reference is automatically looked up.
|
|
99
116
|
# See: https://developer.mozilla.org/en-US/docs/Web/HTML/Preloading_content
|
|
117
|
+
#
|
|
100
118
|
# Example:
|
|
101
119
|
#
|
|
102
120
|
# <%= preload_pack_asset 'fonts/fa-regular-400.woff2' %> # =>
|
|
@@ -110,7 +128,7 @@ module Webpacker::Helper
|
|
|
110
128
|
end
|
|
111
129
|
|
|
112
130
|
# Creates a link tag that references the named pack file, as compiled by webpack per the entries list
|
|
113
|
-
# in
|
|
131
|
+
# in package/environments/base.js. By default, this list is auto-generated to match everything in
|
|
114
132
|
# app/javascript/packs/*.js. In production mode, the digested reference is automatically looked up.
|
|
115
133
|
#
|
|
116
134
|
# Note: If the development server is running and hot module replacement is active, this will return nothing.
|
|
@@ -118,21 +136,14 @@ module Webpacker::Helper
|
|
|
118
136
|
#
|
|
119
137
|
# Examples:
|
|
120
138
|
#
|
|
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
139
|
# <%= stylesheet_pack_tag 'calendar', 'data-turbolinks-track': 'reload' %> # =>
|
|
127
140
|
# <link rel="stylesheet" media="screen" href="/packs/calendar-1016838bab065ae1e122.css" data-turbolinks-track="reload" />
|
|
128
141
|
def stylesheet_pack_tag(*names, **options)
|
|
129
|
-
|
|
130
|
-
stylesheet_link_tag(*sources_from_manifest_entries(names, type: :stylesheet), **options)
|
|
131
|
-
end
|
|
142
|
+
stylesheet_link_tag(*sources_from_manifest_entries(names, type: :stylesheet), **options)
|
|
132
143
|
end
|
|
133
144
|
|
|
134
145
|
# 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
|
|
146
|
+
# as compiled by webpack per the entries list in package/environments/base.js.
|
|
136
147
|
# By default, this list is auto-generated to match everything in
|
|
137
148
|
# app/javascript/packs/*.js and all the dependent chunks. In production mode, the digested reference is automatically looked up.
|
|
138
149
|
# See: https://webpack.js.org/plugins/split-chunks-plugin/
|
|
@@ -143,22 +154,20 @@ module Webpacker::Helper
|
|
|
143
154
|
# <link rel="stylesheet" media="screen" href="/packs/3-8c7ce31a.chunk.css" />
|
|
144
155
|
# <link rel="stylesheet" media="screen" href="/packs/calendar-8c7ce31a.chunk.css" />
|
|
145
156
|
# <link rel="stylesheet" media="screen" href="/packs/map-8c7ce31a.chunk.css" />
|
|
157
|
+
#
|
|
146
158
|
# DO:
|
|
147
|
-
#
|
|
159
|
+
#
|
|
160
|
+
# <%= stylesheet_packs_with_chunks_tag 'calendar', 'map' %>
|
|
161
|
+
#
|
|
148
162
|
# DON'T:
|
|
149
|
-
#
|
|
150
|
-
#
|
|
163
|
+
#
|
|
164
|
+
# <%= stylesheet_packs_with_chunks_tag 'calendar' %>
|
|
165
|
+
# <%= stylesheet_packs_with_chunks_tag 'map' %>
|
|
151
166
|
def stylesheet_packs_with_chunks_tag(*names, **options)
|
|
152
|
-
|
|
153
|
-
stylesheet_link_tag(*sources_from_manifest_entrypoints(names, type: :stylesheet), **options)
|
|
154
|
-
end
|
|
167
|
+
stylesheet_link_tag(*sources_from_manifest_entrypoints(names, type: :stylesheet), **options)
|
|
155
168
|
end
|
|
156
169
|
|
|
157
170
|
private
|
|
158
|
-
def stylesheet?(name)
|
|
159
|
-
File.extname(name) == ".css"
|
|
160
|
-
end
|
|
161
|
-
|
|
162
171
|
def sources_from_manifest_entries(names, type:)
|
|
163
172
|
names.map { |name| current_webpacker_instance.manifest.lookup!(name, type: type) }.flatten
|
|
164
173
|
end
|
|
@@ -167,10 +176,10 @@ module Webpacker::Helper
|
|
|
167
176
|
names.map { |name| current_webpacker_instance.manifest.lookup_pack_with_chunks!(name, type: type) }.flatten.uniq
|
|
168
177
|
end
|
|
169
178
|
|
|
170
|
-
def resolve_path_to_image(name)
|
|
179
|
+
def resolve_path_to_image(name, **options)
|
|
171
180
|
path = name.starts_with?("media/images/") ? name : "media/images/#{name}"
|
|
172
|
-
|
|
181
|
+
path_to_asset(current_webpacker_instance.manifest.lookup!(path), options)
|
|
173
182
|
rescue
|
|
174
|
-
|
|
183
|
+
path_to_asset(current_webpacker_instance.manifest.lookup!(name), options)
|
|
175
184
|
end
|
|
176
185
|
end
|
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
|
data/lib/webpacker/railtie.rb
CHANGED
|
@@ -7,49 +7,6 @@ class Webpacker::Engine < ::Rails::Engine
|
|
|
7
7
|
# Allows Webpacker config values to be set via Rails env config files
|
|
8
8
|
config.webpacker = ActiveSupport::OrderedOptions.new
|
|
9
9
|
|
|
10
|
-
initializer "webpacker.set_configs" do |app|
|
|
11
|
-
if app.config.webpacker.key?(:check_yarn_integrity)
|
|
12
|
-
Webpacker.config.check_yarn_integrity = app.config.webpacker.check_yarn_integrity
|
|
13
|
-
end
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
# ================================
|
|
17
|
-
# Check Yarn Integrity Initializer
|
|
18
|
-
# ================================
|
|
19
|
-
#
|
|
20
|
-
# development (on by default):
|
|
21
|
-
#
|
|
22
|
-
# to turn off:
|
|
23
|
-
# - edit config/environments/development.rb
|
|
24
|
-
# - add `config.webpacker.check_yarn_integrity = false`
|
|
25
|
-
#
|
|
26
|
-
# production (off by default):
|
|
27
|
-
#
|
|
28
|
-
# to turn on:
|
|
29
|
-
# - edit config/environments/production.rb
|
|
30
|
-
# - add `config.webpacker.check_yarn_integrity = true`
|
|
31
|
-
initializer "webpacker.yarn_check" do |app|
|
|
32
|
-
if File.exist?("yarn.lock") && Webpacker.config.config_path.exist? && Webpacker.config.check_yarn_integrity?
|
|
33
|
-
output = `yarn check --integrity && yarn check --verify-tree 2>&1`
|
|
34
|
-
|
|
35
|
-
unless $?.success?
|
|
36
|
-
$stderr.puts "\n\n"
|
|
37
|
-
$stderr.puts "========================================"
|
|
38
|
-
$stderr.puts " Your Yarn packages are out of date!"
|
|
39
|
-
$stderr.puts " Please run `yarn install --check-files` to update."
|
|
40
|
-
$stderr.puts "========================================"
|
|
41
|
-
$stderr.puts "\n\n"
|
|
42
|
-
$stderr.puts "To disable this check, please change `check_yarn_integrity`"
|
|
43
|
-
$stderr.puts "to `false` in your webpacker config file (config/webpacker.yml)."
|
|
44
|
-
$stderr.puts "\n\n"
|
|
45
|
-
$stderr.puts output
|
|
46
|
-
$stderr.puts "\n\n"
|
|
47
|
-
|
|
48
|
-
exit(1)
|
|
49
|
-
end
|
|
50
|
-
end
|
|
51
|
-
end
|
|
52
|
-
|
|
53
10
|
initializer "webpacker.proxy" do |app|
|
|
54
11
|
insert_middleware = Webpacker.config.dev_server.present? rescue nil
|
|
55
12
|
if insert_middleware
|
data/lib/webpacker/runner.rb
CHANGED
|
@@ -12,6 +12,7 @@ module Webpacker
|
|
|
12
12
|
@app_path = File.expand_path(".", Dir.pwd)
|
|
13
13
|
@node_modules_bin_path = ENV["WEBPACKER_NODE_MODULES_BIN_PATH"] || `yarn bin`.chomp
|
|
14
14
|
@webpack_config = File.join(@app_path, "config/webpack/#{ENV["NODE_ENV"]}.js")
|
|
15
|
+
@webpacker_config = File.join(@app_path, "config/webpacker.yml")
|
|
15
16
|
|
|
16
17
|
unless File.exist?(@webpack_config)
|
|
17
18
|
$stderr.puts "webpack config #{@webpack_config} not found, please run 'bundle exec rails webpacker:install' to install Webpacker with default configs or add the missing config file for your custom environment."
|
data/lib/webpacker/version.rb
CHANGED
|
@@ -5,6 +5,7 @@ module Webpacker
|
|
|
5
5
|
class WebpackRunner < Webpacker::Runner
|
|
6
6
|
def run
|
|
7
7
|
env = Webpacker::Compiler.env
|
|
8
|
+
env["WEBPACKER_CONFIG"] = @webpacker_config
|
|
8
9
|
|
|
9
10
|
cmd = if node_modules_bin_exist?
|
|
10
11
|
["#{@node_modules_bin_path}/webpack"]
|
|
@@ -12,9 +13,13 @@ module Webpacker
|
|
|
12
13
|
["yarn", "webpack"]
|
|
13
14
|
end
|
|
14
15
|
|
|
15
|
-
if
|
|
16
|
+
if @argv.include?("--debug-webpacker")
|
|
16
17
|
cmd = [ "node", "--inspect-brk"] + cmd
|
|
17
|
-
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
if @argv.include?("--trace-deprecation")
|
|
21
|
+
cmd = [ "node", "--trace-deprecation"] + cmd
|
|
22
|
+
@argv.delete "--trace-deprecation"
|
|
18
23
|
end
|
|
19
24
|
|
|
20
25
|
cmd += ["--config", @webpack_config] + @argv
|
data/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rails/webpacker",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "6.0.0-beta",
|
|
4
4
|
"description": "Use webpack to manage app-like JavaScript modules in Rails",
|
|
5
5
|
"main": "package/index.js",
|
|
6
6
|
"files": [
|
|
@@ -8,56 +8,40 @@
|
|
|
8
8
|
"lib/install/config/webpacker.yml"
|
|
9
9
|
],
|
|
10
10
|
"engines": {
|
|
11
|
-
"node": ">=10.
|
|
12
|
-
"yarn": ">=1 <
|
|
11
|
+
"node": ">=10.22.1 || ^12 || >=14",
|
|
12
|
+
"yarn": ">=1 <3"
|
|
13
13
|
},
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@babel/core": "^7.9
|
|
16
|
-
"@babel/plugin-proposal-class-properties": "^7.
|
|
17
|
-
"@babel/plugin-
|
|
18
|
-
"@babel/
|
|
19
|
-
"@babel/
|
|
20
|
-
"
|
|
21
|
-
"
|
|
22
|
-
"@babel/preset-env": "^7.9.0",
|
|
23
|
-
"@babel/runtime": "^7.9.2",
|
|
24
|
-
"babel-loader": "^8.1.0",
|
|
25
|
-
"babel-plugin-dynamic-import-node": "^2.3.0",
|
|
26
|
-
"babel-plugin-macros": "^2.8.0",
|
|
15
|
+
"@babel/core": "^7.12.9",
|
|
16
|
+
"@babel/plugin-proposal-class-properties": "^7.12.1",
|
|
17
|
+
"@babel/plugin-transform-runtime": "^7.12.1",
|
|
18
|
+
"@babel/preset-env": "^7.12.11",
|
|
19
|
+
"@babel/runtime": "^7.12.5",
|
|
20
|
+
"babel-loader": "^8.2.2",
|
|
21
|
+
"babel-plugin-macros": "^3.0.1",
|
|
27
22
|
"case-sensitive-paths-webpack-plugin": "^2.3.0",
|
|
28
|
-
"compression-webpack-plugin": "^
|
|
29
|
-
"core-js": "^3.
|
|
30
|
-
"css-loader": "^3.4.2",
|
|
31
|
-
"file-loader": "^6.0.0",
|
|
32
|
-
"flatted": "^2.0.1",
|
|
23
|
+
"compression-webpack-plugin": "^7.1.0",
|
|
24
|
+
"core-js": "^3.8.0",
|
|
33
25
|
"glob": "^7.1.6",
|
|
34
|
-
"js-yaml": "^3.
|
|
35
|
-
"mini-css-extract-plugin": "^0.9.0",
|
|
36
|
-
"node-sass": "^4.13.1",
|
|
37
|
-
"optimize-css-assets-webpack-plugin": "^5.0.3",
|
|
26
|
+
"js-yaml": "^3.14.0",
|
|
38
27
|
"path-complete-extname": "^1.0.0",
|
|
39
28
|
"pnp-webpack-plugin": "^1.6.4",
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
"
|
|
44
|
-
"
|
|
45
|
-
"
|
|
46
|
-
"
|
|
47
|
-
"style-loader": "^1.1.3",
|
|
48
|
-
"terser-webpack-plugin": "^2.3.5",
|
|
49
|
-
"webpack": "^4.42.1",
|
|
50
|
-
"webpack-assets-manifest": "^3.1.1",
|
|
51
|
-
"webpack-cli": "^3.3.11",
|
|
52
|
-
"webpack-sources": "^1.4.3"
|
|
29
|
+
"regenerator-runtime": "^0.13.7",
|
|
30
|
+
"terser-webpack-plugin": "^5.0.3",
|
|
31
|
+
"webpack": "^5.11.0",
|
|
32
|
+
"webpack-assets-manifest": "^5.0.0",
|
|
33
|
+
"webpack-cli": "^4.2.0",
|
|
34
|
+
"webpack-merge": "^5.7.2",
|
|
35
|
+
"webpack-sources": "^2.2.0"
|
|
53
36
|
},
|
|
54
37
|
"devDependencies": {
|
|
55
|
-
"eslint": "^
|
|
56
|
-
"eslint-config-airbnb": "^18.
|
|
57
|
-
"eslint-
|
|
58
|
-
"eslint-plugin-
|
|
59
|
-
"eslint-plugin-
|
|
60
|
-
"
|
|
38
|
+
"eslint": "^7.16.0",
|
|
39
|
+
"eslint-config-airbnb": "^18.2.0",
|
|
40
|
+
"eslint-config-prettier": "^7.1.0",
|
|
41
|
+
"eslint-plugin-import": "^2.22.1",
|
|
42
|
+
"eslint-plugin-jsx-a11y": "^6.3.1",
|
|
43
|
+
"eslint-plugin-react": "^7.21.4",
|
|
44
|
+
"jest": "^26.5.3"
|
|
61
45
|
},
|
|
62
46
|
"jest": {
|
|
63
47
|
"testRegex": "(/__tests__/.*|(\\.|/))\\.jsx?$",
|