webpacker 4.0.7 → 5.0.0
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/.node-version +1 -1
- data/.rubocop.yml +2 -1
- data/.travis.yml +10 -20
- data/CHANGELOG.md +243 -137
- data/Gemfile +1 -0
- data/Gemfile.lock +84 -62
- data/README.md +52 -149
- data/docs/css.md +15 -4
- data/docs/deployment.md +40 -11
- data/docs/docker.md +33 -14
- data/docs/engines.md +53 -3
- data/docs/es6.md +19 -1
- data/docs/integrations.md +220 -0
- data/docs/troubleshooting.md +37 -9
- data/docs/typescript.md +10 -8
- data/docs/webpack-dev-server.md +1 -1
- data/docs/webpack.md +18 -3
- data/gemfiles/{Gemfile-rails.4.2.x → Gemfile-rails.6.0.x} +1 -1
- data/lib/install/bin/webpack +0 -1
- data/lib/install/bin/webpack-dev-server +0 -1
- data/lib/install/coffee.rb +1 -1
- data/lib/install/config/babel.config.js +10 -10
- data/lib/install/config/webpacker.yml +2 -1
- data/lib/install/elm.rb +1 -1
- data/lib/install/erb.rb +2 -2
- data/lib/install/examples/angular/hello_angular/polyfills.ts +2 -2
- data/lib/install/examples/react/babel.config.js +16 -14
- data/lib/install/examples/svelte/app.svelte +11 -0
- data/lib/install/examples/svelte/hello_svelte.js +20 -0
- data/lib/install/loaders/elm.js +9 -6
- data/lib/install/loaders/svelte.js +9 -0
- data/lib/install/loaders/typescript.js +1 -1
- data/lib/install/svelte.rb +29 -0
- data/lib/install/template.rb +2 -2
- data/lib/install/typescript.rb +1 -1
- data/lib/install/vue.rb +1 -1
- data/lib/tasks/installers.rake +1 -0
- data/lib/tasks/webpacker.rake +2 -0
- data/lib/tasks/webpacker/check_node.rake +14 -7
- data/lib/tasks/webpacker/check_yarn.rake +16 -9
- data/lib/tasks/webpacker/clean.rake +25 -0
- data/lib/tasks/webpacker/clobber.rake +8 -4
- data/lib/tasks/webpacker/compile.rake +2 -10
- data/lib/tasks/webpacker/yarn_install.rake +5 -1
- data/lib/webpacker.rb +9 -1
- data/lib/webpacker/commands.rb +53 -1
- data/lib/webpacker/compiler.rb +15 -8
- data/lib/webpacker/configuration.rb +9 -1
- data/lib/webpacker/dev_server.rb +1 -1
- data/lib/webpacker/dev_server_proxy.rb +2 -8
- data/lib/webpacker/dev_server_runner.rb +4 -4
- data/lib/webpacker/env.rb +1 -1
- data/lib/webpacker/helper.rb +39 -13
- data/lib/webpacker/manifest.rb +4 -4
- data/lib/webpacker/railtie.rb +6 -0
- data/lib/webpacker/version.rb +1 -1
- data/package.json +38 -38
- data/package/__tests__/config.js +0 -23
- data/package/config.js +2 -10
- data/package/config_types/config_list.js +3 -3
- data/package/config_types/config_object.js +1 -1
- data/package/environments/__tests__/base.js +10 -0
- data/package/environments/base.js +14 -3
- data/package/environments/development.js +1 -5
- data/package/environments/production.js +12 -0
- data/package/rules/babel.js +1 -1
- data/package/rules/node_modules.js +2 -2
- data/package/rules/sass.js +3 -2
- data/package/utils/__tests__/get_style_rule.js +9 -0
- data/package/utils/deep_merge.js +5 -5
- data/package/utils/get_style_rule.js +7 -12
- data/package/utils/helpers.js +9 -9
- data/test/command_test.rb +6 -0
- data/test/compiler_test.rb +5 -6
- data/test/configuration_test.rb +36 -27
- data/test/dev_server_test.rb +22 -0
- data/test/helper_test.rb +34 -0
- data/test/manifest_test.rb +37 -6
- data/test/rake_tasks_test.rb +17 -0
- data/test/test_app/app/javascript/packs/multi_entry.css +4 -0
- data/test/test_app/app/javascript/packs/multi_entry.js +4 -0
- data/test/test_app/bin/webpack +0 -1
- data/test/test_app/bin/webpack-dev-server +0 -1
- data/test/test_app/config/webpacker.yml +1 -0
- data/test/test_app/public/packs/manifest.json +3 -0
- data/webpacker.gemspec +5 -3
- data/yarn.lock +2684 -1846
- metadata +48 -12
- data/gemfiles/Gemfile-rails.5.0.x +0 -9
- data/gemfiles/Gemfile-rails.5.1.x +0 -9
@@ -5,16 +5,10 @@ class Webpacker::DevServerProxy < Rack::Proxy
|
|
5
5
|
|
6
6
|
def initialize(app = nil, opts = {})
|
7
7
|
@webpacker = opts.delete(:webpacker) || Webpacker.instance
|
8
|
+
opts[:streaming] = false if Rails.env.test? && !opts.key?(:streaming)
|
8
9
|
super
|
9
10
|
end
|
10
11
|
|
11
|
-
def rewrite_response(response)
|
12
|
-
_status, headers, _body = response
|
13
|
-
headers.delete "transfer-encoding"
|
14
|
-
headers.delete "content-length" if dev_server.running? && dev_server.https?
|
15
|
-
response
|
16
|
-
end
|
17
|
-
|
18
12
|
def perform_request(env)
|
19
13
|
if env["PATH_INFO"].start_with?("/#{public_output_uri_path}") && dev_server.running?
|
20
14
|
env["HTTP_HOST"] = env["HTTP_X_FORWARDED_HOST"] = env["HTTP_X_FORWARDED_SERVER"] = dev_server.host_with_port
|
@@ -32,6 +26,6 @@ class Webpacker::DevServerProxy < Rack::Proxy
|
|
32
26
|
|
33
27
|
private
|
34
28
|
def public_output_uri_path
|
35
|
-
config.public_output_path.relative_path_from(config.public_path)
|
29
|
+
config.public_output_path.relative_path_from(config.public_path).to_s + "/"
|
36
30
|
end
|
37
31
|
end
|
@@ -16,20 +16,20 @@ module Webpacker
|
|
16
16
|
def load_config
|
17
17
|
app_root = Pathname.new(@app_path)
|
18
18
|
|
19
|
-
config = Configuration.new(
|
19
|
+
@config = Configuration.new(
|
20
20
|
root_path: app_root,
|
21
21
|
config_path: app_root.join("config/webpacker.yml"),
|
22
22
|
env: ENV["RAILS_ENV"]
|
23
23
|
)
|
24
24
|
|
25
|
-
dev_server = DevServer.new(config)
|
25
|
+
dev_server = DevServer.new(@config)
|
26
26
|
|
27
27
|
@hostname = dev_server.host
|
28
28
|
@port = dev_server.port
|
29
29
|
@pretty = dev_server.pretty?
|
30
30
|
|
31
31
|
rescue Errno::ENOENT, NoMethodError
|
32
|
-
$stdout.puts "webpack dev_server configuration not found in #{config.config_path}[#{ENV["RAILS_ENV"]}]."
|
32
|
+
$stdout.puts "webpack dev_server configuration not found in #{@config.config_path}[#{ENV["RAILS_ENV"]}]."
|
33
33
|
$stdout.puts "Please run bundle exec rails webpacker:install to install Webpacker"
|
34
34
|
exit!
|
35
35
|
end
|
@@ -39,7 +39,7 @@ module Webpacker
|
|
39
39
|
server.close
|
40
40
|
|
41
41
|
rescue Errno::EADDRINUSE
|
42
|
-
$stdout.puts "Another program is running on port #{@port}. Set a new port in #{@
|
42
|
+
$stdout.puts "Another program is running on port #{@port}. Set a new port in #{@config.config_path} for dev_server"
|
43
43
|
exit!
|
44
44
|
end
|
45
45
|
|
data/lib/webpacker/env.rb
CHANGED
data/lib/webpacker/helper.rb
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
module Webpacker::Helper
|
2
|
-
# Returns current Webpacker instance.
|
2
|
+
# Returns the current Webpacker instance.
|
3
3
|
# Could be overridden to use multiple Webpacker
|
4
|
-
# configurations within the same app (e.g. with engines)
|
4
|
+
# configurations within the same app (e.g. with engines).
|
5
5
|
def current_webpacker_instance
|
6
6
|
Webpacker.instance
|
7
7
|
end
|
8
8
|
|
9
9
|
# Computes the relative path for a given Webpacker asset.
|
10
|
-
#
|
10
|
+
# Returns the relative path using manifest.json and passes it to asset_path helper.
|
11
11
|
# This will use asset_path internally, so most of their behaviors will be the same.
|
12
12
|
#
|
13
13
|
# Example:
|
@@ -19,12 +19,12 @@ module Webpacker::Helper
|
|
19
19
|
# <%= asset_pack_path 'calendar.css' %> # => "/packs/calendar-1016838bab065ae1e122.css"
|
20
20
|
def asset_pack_path(name, **options)
|
21
21
|
if current_webpacker_instance.config.extract_css? || !stylesheet?(name)
|
22
|
-
asset_path(current_webpacker_instance.manifest.lookup!(name),
|
22
|
+
asset_path(current_webpacker_instance.manifest.lookup!(name), options)
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
26
26
|
# Computes the absolute path for a given Webpacker asset.
|
27
|
-
#
|
27
|
+
# Returns the absolute path using manifest.json and passes it to asset_url helper.
|
28
28
|
# This will use asset_url internally, so most of their behaviors will be the same.
|
29
29
|
#
|
30
30
|
# Example:
|
@@ -36,18 +36,28 @@ module Webpacker::Helper
|
|
36
36
|
# <%= asset_pack_url 'calendar.css' %> # => "http://example.com/packs/calendar-1016838bab065ae1e122.css"
|
37
37
|
def asset_pack_url(name, **options)
|
38
38
|
if current_webpacker_instance.config.extract_css? || !stylesheet?(name)
|
39
|
-
asset_url(current_webpacker_instance.manifest.lookup!(name),
|
39
|
+
asset_url(current_webpacker_instance.manifest.lookup!(name), options)
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
43
|
-
# Creates
|
43
|
+
# Creates an image tag that references the named pack file.
|
44
44
|
#
|
45
45
|
# Example:
|
46
46
|
#
|
47
47
|
# <%= image_pack_tag 'application.png', size: '16x10', alt: 'Edit Entry' %>
|
48
48
|
# <img alt='Edit Entry' src='/packs/application-k344a6d59eef8632c9d1.png' width='16' height='10' />
|
49
49
|
def image_pack_tag(name, **options)
|
50
|
-
image_tag(resolve_path_to_image(name),
|
50
|
+
image_tag(resolve_path_to_image(name), options)
|
51
|
+
end
|
52
|
+
|
53
|
+
# Creates a link tag for a favicon that references the named pack file.
|
54
|
+
#
|
55
|
+
# Example:
|
56
|
+
#
|
57
|
+
# <%= favicon_pack_tag 'mb-icon.png', rel: 'apple-touch-icon', type: 'image/png' %>
|
58
|
+
# <link href="/packs/mb-icon-k344a6d59eef8632c9d1.png" rel="apple-touch-icon" type="image/png" />
|
59
|
+
def favicon_pack_tag(name, **options)
|
60
|
+
favicon_link_tag(resolve_path_to_image(name), options)
|
51
61
|
end
|
52
62
|
|
53
63
|
# Creates a script tag that references the named pack file, as compiled by webpack per the entries list
|
@@ -62,7 +72,7 @@ module Webpacker::Helper
|
|
62
72
|
javascript_include_tag(*sources_from_manifest_entries(names, type: :javascript), **options)
|
63
73
|
end
|
64
74
|
|
65
|
-
# Creates script tags that
|
75
|
+
# Creates script tags that reference the js chunks from entrypoints when using split chunks API,
|
66
76
|
# as compiled by webpack per the entries list in config/webpack/shared.js.
|
67
77
|
# By default, this list is auto-generated to match everything in
|
68
78
|
# app/javascript/packs/*.js and all the dependent chunks. In production mode, the digested reference is automatically looked up.
|
@@ -78,12 +88,27 @@ module Webpacker::Helper
|
|
78
88
|
# DO:
|
79
89
|
# <%= javascript_packs_with_chunks_tag 'calendar', 'map' %>
|
80
90
|
# DON'T:
|
81
|
-
#
|
91
|
+
# <%= javascript_packs_with_chunks_tag 'calendar' %>
|
82
92
|
# <%= javascript_packs_with_chunks_tag 'map' %>
|
83
93
|
def javascript_packs_with_chunks_tag(*names, **options)
|
84
94
|
javascript_include_tag(*sources_from_manifest_entrypoints(names, type: :javascript), **options)
|
85
95
|
end
|
86
96
|
|
97
|
+
# Creates a link tag, for preloading, that references a given Webpacker asset.
|
98
|
+
# In production mode, the digested reference is automatically looked up.
|
99
|
+
# See: https://developer.mozilla.org/en-US/docs/Web/HTML/Preloading_content
|
100
|
+
# Example:
|
101
|
+
#
|
102
|
+
# <%= preload_pack_asset 'fonts/fa-regular-400.woff2' %> # =>
|
103
|
+
# <link rel="preload" href="/packs/fonts/fa-regular-400-944fb546bd7018b07190a32244f67dc9.woff2" as="font" type="font/woff2" crossorigin="anonymous">
|
104
|
+
def preload_pack_asset(name, **options)
|
105
|
+
if self.class.method_defined?(:preload_link_tag)
|
106
|
+
preload_link_tag(current_webpacker_instance.manifest.lookup!(name), options)
|
107
|
+
else
|
108
|
+
raise "You need Rails >= 5.2 to use this tag."
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
87
112
|
# Creates a link tag that references the named pack file, as compiled by webpack per the entries list
|
88
113
|
# in config/webpack/shared.js. By default, this list is auto-generated to match everything in
|
89
114
|
# app/javascript/packs/*.js. In production mode, the digested reference is automatically looked up.
|
@@ -106,12 +131,13 @@ module Webpacker::Helper
|
|
106
131
|
end
|
107
132
|
end
|
108
133
|
|
109
|
-
# Creates link tags that
|
134
|
+
# Creates link tags that reference the css chunks from entrypoints when using split chunks API,
|
110
135
|
# as compiled by webpack per the entries list in config/webpack/shared.js.
|
111
136
|
# By default, this list is auto-generated to match everything in
|
112
137
|
# app/javascript/packs/*.js and all the dependent chunks. In production mode, the digested reference is automatically looked up.
|
113
138
|
# See: https://webpack.js.org/plugins/split-chunks-plugin/
|
114
|
-
#
|
139
|
+
#
|
140
|
+
# Examples:
|
115
141
|
#
|
116
142
|
# <%= stylesheet_packs_with_chunks_tag 'calendar', 'map' %> # =>
|
117
143
|
# <link rel="stylesheet" media="screen" href="/packs/3-8c7ce31a.chunk.css" />
|
@@ -120,7 +146,7 @@ module Webpacker::Helper
|
|
120
146
|
# DO:
|
121
147
|
# <%= stylesheet_packs_with_chunks_tag 'calendar', 'map' %>
|
122
148
|
# DON'T:
|
123
|
-
#
|
149
|
+
# <%= stylesheet_packs_with_chunks_tag 'calendar' %>
|
124
150
|
# <%= stylesheet_packs_with_chunks_tag 'map' %>
|
125
151
|
def stylesheet_packs_with_chunks_tag(*names, **options)
|
126
152
|
if current_webpacker_instance.config.extract_css?
|
data/lib/webpacker/manifest.rb
CHANGED
@@ -29,7 +29,7 @@ class Webpacker::Manifest
|
|
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
|
data/lib/webpacker/railtie.rb
CHANGED
@@ -89,4 +89,10 @@ class Webpacker::Engine < ::Rails::Engine
|
|
89
89
|
end
|
90
90
|
end
|
91
91
|
end
|
92
|
+
|
93
|
+
initializer "webpacker.set_source" do |app|
|
94
|
+
if Webpacker.config.config_path.exist?
|
95
|
+
app.config.javascript_path = Webpacker.config.source_path.relative_path_from(Rails.root.join("app")).to_s
|
96
|
+
end
|
97
|
+
end
|
92
98
|
end
|
data/lib/webpacker/version.rb
CHANGED
data/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@rails/webpacker",
|
3
|
-
"version": "
|
3
|
+
"version": "5.0.0",
|
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,56 @@
|
|
8
8
|
"lib/install/config/webpacker.yml"
|
9
9
|
],
|
10
10
|
"engines": {
|
11
|
-
"node": ">=
|
12
|
-
"yarn": ">=1
|
11
|
+
"node": ">=10.13.0",
|
12
|
+
"yarn": ">=1 <2"
|
13
13
|
},
|
14
14
|
"dependencies": {
|
15
|
-
"@babel/core": "^7.
|
16
|
-
"@babel/plugin-proposal-class-properties": "^7.
|
17
|
-
"@babel/plugin-proposal-object-rest-spread": "^7.
|
18
|
-
"@babel/plugin-syntax-dynamic-import": "^7.
|
19
|
-
"@babel/plugin-transform-destructuring": "^7.
|
20
|
-
"@babel/plugin-transform-regenerator": "^7.
|
21
|
-
"@babel/plugin-transform-runtime": "^7.
|
22
|
-
"@babel/preset-env": "^7.
|
23
|
-
"@babel/runtime": "^7.
|
15
|
+
"@babel/core": "^7.8.7",
|
16
|
+
"@babel/plugin-proposal-class-properties": "^7.8.3",
|
17
|
+
"@babel/plugin-proposal-object-rest-spread": "^7.8.3",
|
18
|
+
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
|
19
|
+
"@babel/plugin-transform-destructuring": "^7.8.8",
|
20
|
+
"@babel/plugin-transform-regenerator": "^7.8.7",
|
21
|
+
"@babel/plugin-transform-runtime": "^7.8.3",
|
22
|
+
"@babel/preset-env": "^7.8.7",
|
23
|
+
"@babel/runtime": "^7.8.7",
|
24
24
|
"babel-loader": "^8.0.6",
|
25
|
-
"babel-plugin-dynamic-import-node": "^2.
|
26
|
-
"babel-plugin-macros": "^2.
|
25
|
+
"babel-plugin-dynamic-import-node": "^2.3.0",
|
26
|
+
"babel-plugin-macros": "^2.8.0",
|
27
27
|
"case-sensitive-paths-webpack-plugin": "^2.2.0",
|
28
|
-
"compression-webpack-plugin": "^
|
29
|
-
"core-js": "^3.
|
30
|
-
"css-loader": "^
|
31
|
-
"file-loader": "^
|
32
|
-
"flatted": "^2.0.
|
33
|
-
"glob": "^7.1.
|
28
|
+
"compression-webpack-plugin": "^3.0.1",
|
29
|
+
"core-js": "^3.6.4",
|
30
|
+
"css-loader": "^3.4.1",
|
31
|
+
"file-loader": "^5.0.2",
|
32
|
+
"flatted": "^2.0.1",
|
33
|
+
"glob": "^7.1.6",
|
34
34
|
"js-yaml": "^3.13.1",
|
35
|
-
"mini-css-extract-plugin": "^0.
|
36
|
-
"node-sass": "^4.
|
37
|
-
"optimize-css-assets-webpack-plugin": "^5.0.
|
35
|
+
"mini-css-extract-plugin": "^0.9.0",
|
36
|
+
"node-sass": "^4.13.1",
|
37
|
+
"optimize-css-assets-webpack-plugin": "^5.0.3",
|
38
38
|
"path-complete-extname": "^1.0.0",
|
39
|
-
"pnp-webpack-plugin": "^1.
|
39
|
+
"pnp-webpack-plugin": "^1.5.0",
|
40
40
|
"postcss-flexbugs-fixes": "^4.1.0",
|
41
41
|
"postcss-import": "^12.0.1",
|
42
42
|
"postcss-loader": "^3.0.0",
|
43
|
-
"postcss-preset-env": "^6.
|
43
|
+
"postcss-preset-env": "^6.7.0",
|
44
44
|
"postcss-safe-parser": "^4.0.1",
|
45
|
-
"regenerator-runtime": "^0.13.
|
46
|
-
"sass-loader": "^7.1
|
47
|
-
"style-loader": "^
|
48
|
-
"terser-webpack-plugin": "^
|
49
|
-
"webpack": "^4.
|
45
|
+
"regenerator-runtime": "^0.13.3",
|
46
|
+
"sass-loader": "^7.3.1",
|
47
|
+
"style-loader": "^1.1.2",
|
48
|
+
"terser-webpack-plugin": "^2.3.5",
|
49
|
+
"webpack": "^4.42.0",
|
50
50
|
"webpack-assets-manifest": "^3.1.1",
|
51
|
-
"webpack-cli": "^3.3.
|
52
|
-
"webpack-sources": "^1.3
|
51
|
+
"webpack-cli": "^3.3.10",
|
52
|
+
"webpack-sources": "^1.4.3"
|
53
53
|
},
|
54
54
|
"devDependencies": {
|
55
|
-
"eslint": "^
|
56
|
-
"eslint-config-airbnb": "^
|
57
|
-
"eslint-plugin-import": "^2.
|
58
|
-
"eslint-plugin-jsx-a11y": "^6.2.
|
59
|
-
"eslint-plugin-react": "^7.
|
60
|
-
"jest": "^24.
|
55
|
+
"eslint": "^6.8.0",
|
56
|
+
"eslint-config-airbnb": "^18.0.1",
|
57
|
+
"eslint-plugin-import": "^2.19.1",
|
58
|
+
"eslint-plugin-jsx-a11y": "^6.2.3",
|
59
|
+
"eslint-plugin-react": "^7.17.0",
|
60
|
+
"jest": "^24.9.0"
|
61
61
|
},
|
62
62
|
"jest": {
|
63
63
|
"testRegex": "(/__tests__/.*|(\\.|/))\\.jsx?$",
|
data/package/__tests__/config.js
CHANGED
@@ -16,29 +16,6 @@ describe('Config', () => {
|
|
16
16
|
expect(config.publicPath).toEqual('/packs/')
|
17
17
|
})
|
18
18
|
|
19
|
-
// also tests removal of extra slashes
|
20
|
-
test('public path with relative root', () => {
|
21
|
-
process.env.RAILS_ENV = 'development'
|
22
|
-
process.env.RAILS_RELATIVE_URL_ROOT = '/foo'
|
23
|
-
const config = require('../config')
|
24
|
-
expect(config.publicPath).toEqual('/foo/packs/')
|
25
|
-
})
|
26
|
-
|
27
|
-
test('public path with relative root without slash', () => {
|
28
|
-
process.env.RAILS_ENV = 'development'
|
29
|
-
process.env.RAILS_RELATIVE_URL_ROOT = 'foo'
|
30
|
-
const config = require('../config')
|
31
|
-
expect(config.publicPath).toEqual('/foo/packs/')
|
32
|
-
})
|
33
|
-
|
34
|
-
test('public path with asset host and relative root', () => {
|
35
|
-
process.env.RAILS_ENV = 'development'
|
36
|
-
process.env.RAILS_RELATIVE_URL_ROOT = '/foo/'
|
37
|
-
process.env.WEBPACKER_ASSET_HOST = 'http://foo.com/'
|
38
|
-
const config = require('../config')
|
39
|
-
expect(config.publicPath).toEqual('http://foo.com/foo/packs/')
|
40
|
-
})
|
41
|
-
|
42
19
|
test('public path with asset host', () => {
|
43
20
|
process.env.RAILS_ENV = 'development'
|
44
21
|
process.env.WEBPACKER_ASSET_HOST = 'http://foo.com/'
|
data/package/config.js
CHANGED
@@ -27,16 +27,8 @@ config.outputPath = resolve(config.public_root_path, config.public_output_path)
|
|
27
27
|
// Ensure that the publicPath includes our asset host so dynamic imports
|
28
28
|
// (code-splitting chunks and static assets) load from the CDN instead of a relative path.
|
29
29
|
const getPublicPath = () => {
|
30
|
-
const rootUrl = process.env.WEBPACKER_ASSET_HOST || '/'
|
31
|
-
|
32
|
-
// Add relative root prefix to pack path.
|
33
|
-
if (process.env.RAILS_RELATIVE_URL_ROOT) {
|
34
|
-
let relativeRoot = process.env.RAILS_RELATIVE_URL_ROOT
|
35
|
-
relativeRoot = relativeRoot.startsWith('/') ? relativeRoot.substr(1) : relativeRoot
|
36
|
-
packPath = `${ensureTrailingSlash(relativeRoot)}${packPath}`
|
37
|
-
}
|
38
|
-
|
39
|
-
return ensureTrailingSlash(rootUrl) + packPath
|
30
|
+
const rootUrl = ensureTrailingSlash(process.env.WEBPACKER_ASSET_HOST || '/')
|
31
|
+
return `${rootUrl}${config.public_output_path}/`
|
40
32
|
}
|
41
33
|
|
42
34
|
config.publicPath = getPublicPath()
|
@@ -38,7 +38,7 @@ class ConfigList extends Array {
|
|
38
38
|
}
|
39
39
|
|
40
40
|
getIndex(key, shouldThrow = false) {
|
41
|
-
const index = this.findIndex(entry => (
|
41
|
+
const index = this.findIndex((entry) => (
|
42
42
|
entry === key
|
43
43
|
|| entry.key === key
|
44
44
|
|| (entry.constructor && entry.constructor.name === key)
|
@@ -64,11 +64,11 @@ class ConfigList extends Array {
|
|
64
64
|
}
|
65
65
|
|
66
66
|
values() {
|
67
|
-
return this.map(item => item.value)
|
67
|
+
return this.map((item) => item.value)
|
68
68
|
}
|
69
69
|
|
70
70
|
keys() {
|
71
|
-
return this.map(item => item.key)
|
71
|
+
return this.map((item) => item.key)
|
72
72
|
}
|
73
73
|
}
|
74
74
|
|
@@ -42,7 +42,7 @@ class ConfigObject extends Object {
|
|
42
42
|
toObject() {
|
43
43
|
const object = {}
|
44
44
|
/* eslint no-return-assign: 0 */
|
45
|
-
Object.keys(this).forEach(key => (object[key] = this[key]))
|
45
|
+
Object.keys(this).forEach((key) => (object[key] = this[key]))
|
46
46
|
return object
|
47
47
|
}
|
48
48
|
|
@@ -29,6 +29,16 @@ describe('Environment', () => {
|
|
29
29
|
)
|
30
30
|
})
|
31
31
|
|
32
|
+
test('should return multi file entry points', () => {
|
33
|
+
const config = environment.toWebpackConfig()
|
34
|
+
expect(config.entry.multi_entry.sort()).toEqual(
|
35
|
+
[
|
36
|
+
resolve('app', 'javascript', 'packs', 'multi_entry.css'),
|
37
|
+
resolve('app', 'javascript', 'packs', 'multi_entry.js')
|
38
|
+
]
|
39
|
+
)
|
40
|
+
})
|
41
|
+
|
32
42
|
test('should return output', () => {
|
33
43
|
const config = environment.toWebpackConfig()
|
34
44
|
expect(config.output.filename).toEqual('js/[name]-[contenthash].js')
|
@@ -22,7 +22,7 @@ const config = require('../config')
|
|
22
22
|
|
23
23
|
const getLoaderList = () => {
|
24
24
|
const result = new ConfigList()
|
25
|
-
Object.keys(rules).forEach(key => result.append(key, rules[key]))
|
25
|
+
Object.keys(rules).forEach((key) => result.append(key, rules[key]))
|
26
26
|
return result
|
27
27
|
}
|
28
28
|
|
@@ -65,7 +65,18 @@ const getEntryObject = () => {
|
|
65
65
|
paths.forEach((path) => {
|
66
66
|
const namespace = relative(join(rootPath), dirname(path))
|
67
67
|
const name = join(namespace, basename(path, extname(path)))
|
68
|
-
|
68
|
+
let assetPaths = resolve(path)
|
69
|
+
|
70
|
+
// Allows for multiple filetypes per entry (https://webpack.js.org/guides/entry-advanced/)
|
71
|
+
// Transforms the config object value to an array with all values under the same name
|
72
|
+
let previousPaths = result.get(name)
|
73
|
+
if (previousPaths) {
|
74
|
+
previousPaths = Array.isArray(previousPaths) ? previousPaths : [previousPaths]
|
75
|
+
previousPaths.push(assetPaths)
|
76
|
+
assetPaths = previousPaths
|
77
|
+
}
|
78
|
+
|
79
|
+
result.set(name, assetPaths)
|
69
80
|
})
|
70
81
|
return result
|
71
82
|
}
|
@@ -74,7 +85,7 @@ const getModulePaths = () => {
|
|
74
85
|
const result = new ConfigList()
|
75
86
|
result.append('source', resolve(config.source_path))
|
76
87
|
if (config.resolved_paths) {
|
77
|
-
config.resolved_paths.forEach(path => result.append(path, resolve(path)))
|
88
|
+
config.resolved_paths.forEach((path) => result.append(path, resolve(path)))
|
78
89
|
}
|
79
90
|
result.append('node_modules', 'node_modules')
|
80
91
|
return result
|