webpacker 5.4.4 → 6.0.0.rc.6
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 +1 -1
- data/.github/workflows/jest.yml +7 -15
- data/.github/workflows/js-lint.yml +7 -15
- data/.github/workflows/rubocop.yml +1 -1
- data/.github/workflows/ruby.yml +18 -16
- data/.gitignore +2 -0
- data/.node-version +1 -1
- data/.rubocop.yml +5 -7
- data/CHANGELOG.md +30 -12
- data/CONTRIBUTING.md +20 -1
- data/Gemfile.lock +83 -83
- data/README.md +389 -179
- 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 +61 -25
- data/docs/v6_upgrade.md +113 -0
- data/gemfiles/Gemfile-rails.6.1.x +12 -0
- 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 +21 -49
- data/lib/install/package.json +15 -0
- data/lib/install/template.rb +64 -29
- 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 +38 -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 +8 -2
- data/lib/webpacker/runner.rb +1 -1
- data/lib/webpacker/version.rb +1 -1
- data/lib/webpacker/webpack_runner.rb +29 -3
- data/lib/webpacker.rb +1 -1
- data/package/__tests__/config.js +5 -37
- data/package/__tests__/development.js +13 -21
- 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 +49 -47
- 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 +18 -38
- 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/config/initializers/inspect_autoload_paths.rb +1 -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 +21 -0
- data/webpacker.gemspec +2 -2
- data/yarn.lock +1277 -4620
- metadata +63 -92
- 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 -82
- 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 -99
- 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/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
|
@@ -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)
|
data/lib/webpacker/railtie.rb
CHANGED
|
@@ -8,8 +8,7 @@ class Webpacker::Engine < ::Rails::Engine
|
|
|
8
8
|
config.webpacker = ActiveSupport::OrderedOptions.new
|
|
9
9
|
|
|
10
10
|
initializer "webpacker.proxy" do |app|
|
|
11
|
-
|
|
12
|
-
if insert_middleware
|
|
11
|
+
if (Webpacker.config.dev_server.present? rescue nil)
|
|
13
12
|
app.middleware.insert_before 0,
|
|
14
13
|
Rails::VERSION::MAJOR >= 5 ?
|
|
15
14
|
Webpacker::DevServerProxy : "Webpacker::DevServerProxy", ssl_verify_none: true
|
|
@@ -52,4 +51,11 @@ class Webpacker::Engine < ::Rails::Engine
|
|
|
52
51
|
app.config.javascript_path = Webpacker.config.source_path.relative_path_from(Rails.root.join("app")).to_s
|
|
53
52
|
end
|
|
54
53
|
end
|
|
54
|
+
|
|
55
|
+
initializer "webpacker.remove_app_packs_from_the_autoload_paths" do
|
|
56
|
+
Rails.application.config.before_initialize do
|
|
57
|
+
source_path = Webpacker.config.source_path.to_s
|
|
58
|
+
ActiveSupport::Dependencies.autoload_paths.delete(source_path)
|
|
59
|
+
end
|
|
60
|
+
end
|
|
55
61
|
end
|
data/lib/webpacker/runner.rb
CHANGED
|
@@ -12,7 +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
|
+
@webpacker_config = ENV["WEBPACKER_CONFIG"] || File.join(@app_path, "config/webpacker.yml")
|
|
16
16
|
|
|
17
17
|
unless File.exist?(@webpack_config)
|
|
18
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
|
@@ -3,6 +3,19 @@ require "webpacker/runner"
|
|
|
3
3
|
|
|
4
4
|
module Webpacker
|
|
5
5
|
class WebpackRunner < Webpacker::Runner
|
|
6
|
+
WEBPACK_COMMANDS = [
|
|
7
|
+
"help",
|
|
8
|
+
"h",
|
|
9
|
+
"--help",
|
|
10
|
+
"-h",
|
|
11
|
+
"version",
|
|
12
|
+
"v",
|
|
13
|
+
"--version",
|
|
14
|
+
"-v",
|
|
15
|
+
"info",
|
|
16
|
+
"i"
|
|
17
|
+
].freeze
|
|
18
|
+
|
|
6
19
|
def run
|
|
7
20
|
env = Webpacker::Compiler.env
|
|
8
21
|
env["WEBPACKER_CONFIG"] = @webpacker_config
|
|
@@ -13,11 +26,24 @@ module Webpacker
|
|
|
13
26
|
["yarn", "webpack"]
|
|
14
27
|
end
|
|
15
28
|
|
|
16
|
-
if @argv.
|
|
17
|
-
cmd = [
|
|
29
|
+
if @argv.delete "--debug-webpacker"
|
|
30
|
+
cmd = ["node", "--inspect-brk"] + cmd
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
if @argv.delete "--trace-deprecation"
|
|
34
|
+
cmd = ["node", "--trace-deprecation"] + cmd
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
if @argv.delete "--no-deprecation"
|
|
38
|
+
cmd = ["node", "--no-deprecation"] + cmd
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
# Webpack commands are not compatible with --config option.
|
|
42
|
+
if (@argv & WEBPACK_COMMANDS).empty?
|
|
43
|
+
cmd += ["--config", @webpack_config]
|
|
18
44
|
end
|
|
19
45
|
|
|
20
|
-
cmd +=
|
|
46
|
+
cmd += @argv
|
|
21
47
|
|
|
22
48
|
Dir.chdir(@app_path) do
|
|
23
49
|
Kernel.exec env, *cmd
|
data/lib/webpacker.rb
CHANGED
|
@@ -30,7 +30,7 @@ module Webpacker
|
|
|
30
30
|
Webpacker.logger = old_logger
|
|
31
31
|
end
|
|
32
32
|
|
|
33
|
-
delegate :logger, :logger=, :env, to: :instance
|
|
33
|
+
delegate :logger, :logger=, :env, :inlining_css?, to: :instance
|
|
34
34
|
delegate :config, :compiler, :manifest, :commands, :dev_server, to: :instance
|
|
35
35
|
delegate :bootstrap, :clean, :clobber, :compile, to: :commands
|
|
36
36
|
end
|
data/package/__tests__/config.js
CHANGED
|
@@ -24,43 +24,11 @@ describe('Config', () => {
|
|
|
24
24
|
})
|
|
25
25
|
|
|
26
26
|
test('should return additional paths as listed in app config, with resolved paths', () => {
|
|
27
|
-
expect(config.additional_paths).toEqual(
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
]
|
|
33
|
-
)
|
|
34
|
-
})
|
|
35
|
-
|
|
36
|
-
test('should return extensions as listed in app config', () => {
|
|
37
|
-
expect(config.extensions).toEqual([
|
|
38
|
-
'.mjs',
|
|
39
|
-
'.js',
|
|
40
|
-
'.sass',
|
|
41
|
-
'.scss',
|
|
42
|
-
'.css',
|
|
43
|
-
'.module.sass',
|
|
44
|
-
'.module.scss',
|
|
45
|
-
'.module.css',
|
|
46
|
-
'.png',
|
|
47
|
-
'.svg',
|
|
48
|
-
'.gif',
|
|
49
|
-
'.jpeg',
|
|
50
|
-
'.jpg',
|
|
51
|
-
'.elm'
|
|
52
|
-
])
|
|
53
|
-
})
|
|
54
|
-
|
|
55
|
-
test('should return static assets extensions as listed in app config', () => {
|
|
56
|
-
expect(config.static_assets_extensions).toEqual([
|
|
57
|
-
'.jpg',
|
|
58
|
-
'.jpeg',
|
|
59
|
-
'.png',
|
|
60
|
-
'.gif',
|
|
61
|
-
'.tiff',
|
|
62
|
-
'.ico',
|
|
63
|
-
'.svg',
|
|
27
|
+
expect(config.additional_paths).toEqual([
|
|
28
|
+
'app/assets',
|
|
29
|
+
'/etc/yarn',
|
|
30
|
+
'some.config.js',
|
|
31
|
+
'app/elm'
|
|
64
32
|
])
|
|
65
33
|
})
|
|
66
34
|
})
|
|
@@ -8,36 +8,28 @@ chdirTestApp()
|
|
|
8
8
|
describe('Development environment', () => {
|
|
9
9
|
afterAll(chdirCwd)
|
|
10
10
|
|
|
11
|
-
describe('
|
|
11
|
+
describe('webpackConfig', () => {
|
|
12
12
|
beforeEach(() => jest.resetModules())
|
|
13
13
|
|
|
14
|
-
test('should use development config and environment including devServer if
|
|
14
|
+
test('should use development config and environment including devServer if WEBPACK_SERVE', () => {
|
|
15
15
|
process.env.RAILS_ENV = 'development'
|
|
16
16
|
process.env.NODE_ENV = 'development'
|
|
17
|
-
process.env.
|
|
18
|
-
const {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
expect(
|
|
22
|
-
expect(config.output.publicPath).toEqual('/packs/')
|
|
23
|
-
expect(config).toMatchObject({
|
|
24
|
-
devServer: {
|
|
25
|
-
host: 'localhost',
|
|
26
|
-
port: 3035
|
|
27
|
-
}
|
|
28
|
-
})
|
|
17
|
+
process.env.WEBPACK_SERVE = 'true'
|
|
18
|
+
const { webpackConfig } = require('../index')
|
|
19
|
+
|
|
20
|
+
expect(webpackConfig.output.path).toEqual(resolve('public', 'packs'))
|
|
21
|
+
expect(webpackConfig.output.publicPath).toEqual('/packs/')
|
|
29
22
|
})
|
|
30
23
|
|
|
31
|
-
test('should use development config and environment if
|
|
24
|
+
test('should use development config and environment if WEBPACK_SERVE', () => {
|
|
32
25
|
process.env.RAILS_ENV = 'development'
|
|
33
26
|
process.env.NODE_ENV = 'development'
|
|
34
|
-
process.env.
|
|
35
|
-
const {
|
|
27
|
+
process.env.WEBPACK_SERVE = undefined
|
|
28
|
+
const { webpackConfig } = require('../index')
|
|
36
29
|
|
|
37
|
-
|
|
38
|
-
expect(
|
|
39
|
-
expect(
|
|
40
|
-
expect(config.devServer).toEqual(undefined)
|
|
30
|
+
expect(webpackConfig.output.path).toEqual(resolve('public', 'packs'))
|
|
31
|
+
expect(webpackConfig.output.publicPath).toEqual('/packs/')
|
|
32
|
+
expect(webpackConfig.devServer).toEqual(undefined)
|
|
41
33
|
})
|
|
42
34
|
})
|
|
43
35
|
})
|
data/package/__tests__/env.js
CHANGED
|
@@ -13,7 +13,10 @@ describe('Env', () => {
|
|
|
13
13
|
process.env.NODE_ENV = 'development'
|
|
14
14
|
expect(require('../env')).toEqual({
|
|
15
15
|
railsEnv: 'development',
|
|
16
|
-
nodeEnv: 'development'
|
|
16
|
+
nodeEnv: 'development',
|
|
17
|
+
isProduction: false,
|
|
18
|
+
isDevelopment: true,
|
|
19
|
+
runningWebpackDevServer: false
|
|
17
20
|
})
|
|
18
21
|
})
|
|
19
22
|
|
|
@@ -22,7 +25,10 @@ describe('Env', () => {
|
|
|
22
25
|
delete process.env.NODE_ENV
|
|
23
26
|
expect(require('../env')).toEqual({
|
|
24
27
|
railsEnv: 'development',
|
|
25
|
-
nodeEnv: 'production'
|
|
28
|
+
nodeEnv: 'production',
|
|
29
|
+
isProduction: true,
|
|
30
|
+
isDevelopment: false,
|
|
31
|
+
runningWebpackDevServer: false
|
|
26
32
|
})
|
|
27
33
|
})
|
|
28
34
|
|
|
@@ -31,7 +37,10 @@ describe('Env', () => {
|
|
|
31
37
|
delete process.env.RAILS_ENV
|
|
32
38
|
expect(require('../env')).toEqual({
|
|
33
39
|
railsEnv: 'production',
|
|
34
|
-
nodeEnv: 'production'
|
|
40
|
+
nodeEnv: 'production',
|
|
41
|
+
isProduction: true,
|
|
42
|
+
isDevelopment: false,
|
|
43
|
+
runningWebpackDevServer: false
|
|
35
44
|
})
|
|
36
45
|
})
|
|
37
46
|
|
|
@@ -40,7 +49,10 @@ describe('Env', () => {
|
|
|
40
49
|
process.env.NODE_ENV = 'staging'
|
|
41
50
|
expect(require('../env')).toEqual({
|
|
42
51
|
railsEnv: 'staging',
|
|
43
|
-
nodeEnv: 'production'
|
|
52
|
+
nodeEnv: 'production',
|
|
53
|
+
isProduction: true,
|
|
54
|
+
isDevelopment: false,
|
|
55
|
+
runningWebpackDevServer: false
|
|
44
56
|
})
|
|
45
57
|
})
|
|
46
58
|
})
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
const index = require('../index')
|
|
2
|
+
|
|
3
|
+
describe('index', () => {
|
|
4
|
+
test('exports webpack-merge v5 functions', () => {
|
|
5
|
+
expect(index.merge).toBeInstanceOf(Function)
|
|
6
|
+
expect(index.mergeWithRules).toBeInstanceOf(Function)
|
|
7
|
+
expect(index.mergeWithCustomize).toBeInstanceOf(Function)
|
|
8
|
+
})
|
|
9
|
+
})
|
|
@@ -8,19 +8,19 @@ chdirTestApp()
|
|
|
8
8
|
describe('Production environment', () => {
|
|
9
9
|
afterAll(chdirCwd)
|
|
10
10
|
|
|
11
|
-
describe('
|
|
11
|
+
describe('webpackConfig', () => {
|
|
12
12
|
beforeEach(() => jest.resetModules())
|
|
13
13
|
|
|
14
14
|
test('should use production config and environment', () => {
|
|
15
15
|
process.env.RAILS_ENV = 'production'
|
|
16
16
|
process.env.NODE_ENV = 'production'
|
|
17
17
|
|
|
18
|
-
const {
|
|
19
|
-
const config = environment.toWebpackConfig()
|
|
18
|
+
const { webpackConfig } = require('../index')
|
|
20
19
|
|
|
21
|
-
expect(
|
|
22
|
-
expect(
|
|
23
|
-
|
|
20
|
+
expect(webpackConfig.output.path).toEqual(resolve('public', 'packs'))
|
|
21
|
+
expect(webpackConfig.output.publicPath).toEqual('/packs/')
|
|
22
|
+
|
|
23
|
+
expect(webpackConfig).toMatchObject({
|
|
24
24
|
devtool: 'source-map',
|
|
25
25
|
stats: 'normal'
|
|
26
26
|
})
|
|
@@ -8,19 +8,20 @@ chdirTestApp()
|
|
|
8
8
|
describe('Custom environment', () => {
|
|
9
9
|
afterAll(chdirCwd)
|
|
10
10
|
|
|
11
|
-
describe('
|
|
11
|
+
describe('webpackConfig', () => {
|
|
12
12
|
beforeEach(() => jest.resetModules())
|
|
13
13
|
|
|
14
14
|
test('should use staging config and default production environment', () => {
|
|
15
15
|
process.env.RAILS_ENV = 'staging'
|
|
16
16
|
delete process.env.NODE_ENV
|
|
17
17
|
|
|
18
|
-
const {
|
|
19
|
-
const config = environment.toWebpackConfig()
|
|
18
|
+
const { webpackConfig } = require('../index')
|
|
20
19
|
|
|
21
|
-
expect(
|
|
22
|
-
|
|
23
|
-
|
|
20
|
+
expect(webpackConfig.output.path).toEqual(
|
|
21
|
+
resolve('public', 'packs-staging')
|
|
22
|
+
)
|
|
23
|
+
expect(webpackConfig.output.publicPath).toEqual('/packs-staging/')
|
|
24
|
+
expect(webpackConfig).toMatchObject({
|
|
24
25
|
devtool: 'source-map',
|
|
25
26
|
stats: 'normal'
|
|
26
27
|
})
|
data/package/__tests__/test.js
CHANGED
|
@@ -15,12 +15,11 @@ describe('Test environment', () => {
|
|
|
15
15
|
process.env.RAILS_ENV = 'test'
|
|
16
16
|
process.env.NODE_ENV = 'test'
|
|
17
17
|
|
|
18
|
-
const {
|
|
19
|
-
const config = environment.toWebpackConfig()
|
|
18
|
+
const { webpackConfig } = require('../index')
|
|
20
19
|
|
|
21
|
-
expect(
|
|
22
|
-
expect(
|
|
23
|
-
expect(
|
|
20
|
+
expect(webpackConfig.output.path).toEqual(resolve('public', 'packs-test'))
|
|
21
|
+
expect(webpackConfig.output.publicPath).toEqual('/packs-test/')
|
|
22
|
+
expect(webpackConfig.devServer).toEqual(undefined)
|
|
24
23
|
})
|
|
25
24
|
})
|
|
26
25
|
})
|