webpacker 6.0.0.pre.2 → 6.0.0.rc.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- 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 +17 -14
- data/.node-version +1 -1
- data/.rubocop.yml +106 -0
- data/CHANGELOG.md +36 -9
- data/CONTRIBUTING.md +1 -1
- data/Gemfile.lock +93 -90
- data/README.md +363 -107
- data/config/README.md +3 -0
- data/config/webpacker.yml +1 -0
- data/docs/deployment.md +9 -29
- data/docs/developing_webpacker.md +29 -0
- data/docs/troubleshooting.md +57 -25
- data/docs/v6_upgrade.md +75 -0
- data/gemfiles/Gemfile-rails-edge +1 -1
- data/gemfiles/Gemfile-rails.6.1.x +12 -0
- data/lib/install/config/webpacker.yml +5 -7
- data/lib/install/{javascript/packs → packs/entrypoints}/application.js +4 -3
- data/lib/install/template.rb +17 -10
- data/lib/tasks/webpacker/binstubs.rake +2 -2
- data/lib/tasks/webpacker/check_node.rake +3 -0
- data/lib/tasks/webpacker/check_yarn.rake +4 -1
- data/lib/tasks/webpacker/clobber.rake +1 -1
- data/lib/tasks/webpacker/install.rake +2 -2
- data/lib/tasks/webpacker/verify_config.rake +14 -0
- data/lib/tasks/webpacker/verify_install.rake +1 -11
- data/lib/webpacker.rb +1 -1
- data/lib/webpacker/commands.rb +2 -1
- data/lib/webpacker/compiler.rb +9 -3
- data/lib/webpacker/configuration.rb +19 -8
- data/lib/webpacker/dev_server.rb +6 -0
- data/lib/webpacker/dev_server_runner.rb +7 -2
- data/lib/webpacker/env.rb +5 -1
- data/lib/webpacker/helper.rb +26 -50
- data/lib/webpacker/instance.rb +4 -0
- data/lib/webpacker/manifest.rb +1 -2
- 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 +1 -0
- data/package.json +25 -29
- data/package/__tests__/development.js +3 -2
- data/package/__tests__/env.js +8 -4
- data/package/__tests__/index.js +9 -0
- data/package/babel/preset.js +24 -14
- data/package/env.js +7 -1
- data/package/environments/__tests__/base.js +7 -7
- data/package/environments/base.js +25 -25
- data/package/environments/development.js +7 -8
- data/package/environments/production.js +28 -30
- data/package/index.js +9 -2
- data/package/inliningCss.js +7 -0
- data/package/rules/babel.js +1 -1
- data/package/rules/coffee.js +5 -5
- data/package/rules/erb.js +5 -3
- data/package/rules/file.js +5 -3
- data/package/rules/index.js +9 -17
- data/package/rules/less.js +14 -10
- data/package/rules/raw.js +5 -0
- data/package/rules/sass.js +12 -9
- data/package/rules/stylus.js +26 -0
- data/package/utils/get_style_rule.js +28 -30
- data/package/utils/helpers.js +25 -0
- data/test/configuration_test.rb +3 -3
- data/test/dev_server_runner_test.rb +13 -2
- data/test/helper_test.rb +59 -60
- data/test/manifest_test.rb +16 -0
- data/test/mounted_app/test/dummy/config/webpacker.yml +4 -4
- 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 +4 -6
- data/test/test_app/config/webpacker_other_location.yml +79 -0
- data/test/test_app/public/packs/manifest.json +19 -5
- data/test/webpacker_test.rb +17 -0
- data/yarn.lock +1567 -1039
- metadata +24 -36
- data/docs/assets.md +0 -135
- data/docs/cloud9.md +0 -310
- data/docs/css.md +0 -303
- data/docs/docker.md +0 -68
- data/docs/engines.md +0 -213
- data/docs/env.md +0 -68
- 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 -187
- data/docs/react.md +0 -183
- data/docs/target.md +0 -22
- data/docs/testing.md +0 -147
- data/docs/typescript.md +0 -190
- data/docs/v4-upgrade.md +0 -142
- data/docs/webpack-dev-server.md +0 -94
- data/docs/webpack.md +0 -315
- data/docs/yarn.md +0 -23
- data/lib/install/examples/vue3/app.vue +0 -27
- data/lib/install/examples/vue3/hello_vue.js +0 -15
- data/lib/install/javascript/packs/application.css +0 -9
- data/package/babel/preset-react.js +0 -62
- data/package/rules/svg.js +0 -23
@@ -7,9 +7,9 @@ namespace :webpacker do
|
|
7
7
|
prefix = task.name.split(/#|webpacker:binstubs/).first
|
8
8
|
|
9
9
|
if Rails::VERSION::MAJOR >= 5
|
10
|
-
exec "#{RbConfig.ruby} #{bin_path}/rails #{prefix}app:template LOCATION
|
10
|
+
exec "#{RbConfig.ruby} #{bin_path}/rails #{prefix}app:template LOCATION='#{binstubs_template_path}'"
|
11
11
|
else
|
12
|
-
exec "#{RbConfig.ruby} #{bin_path}/rake #{prefix}rails:template LOCATION
|
12
|
+
exec "#{RbConfig.ruby} #{bin_path}/rake #{prefix}rails:template LOCATION='#{binstubs_template_path}'"
|
13
13
|
end
|
14
14
|
end
|
15
15
|
end
|
@@ -3,6 +3,9 @@ namespace :webpacker do
|
|
3
3
|
desc "Verifies if Node.js is installed"
|
4
4
|
task :check_node do
|
5
5
|
begin
|
6
|
+
which_command = Gem.win_platform? ? "where" : "which"
|
7
|
+
raise Errno::ENOENT if `#{which_command} node || #{which_command} nodejs`.strip.empty?
|
8
|
+
|
6
9
|
node_version = `node -v || nodejs -v`.strip
|
7
10
|
raise Errno::ENOENT if node_version.blank?
|
8
11
|
|
@@ -3,13 +3,16 @@ namespace :webpacker do
|
|
3
3
|
desc "Verifies if Yarn is installed"
|
4
4
|
task :check_yarn do
|
5
5
|
begin
|
6
|
+
which_command = Gem.win_platform? ? "where" : "which"
|
7
|
+
raise Errno::ENOENT if `#{which_command} yarn`.strip.empty?
|
8
|
+
|
6
9
|
yarn_version = `yarn --version`.strip
|
7
10
|
raise Errno::ENOENT if yarn_version.blank?
|
8
11
|
|
9
12
|
pkg_path = Pathname.new("#{__dir__}/../../../package.json").realpath
|
10
13
|
yarn_range = JSON.parse(pkg_path.read)["engines"]["yarn"]
|
11
14
|
is_valid = SemanticRange.satisfies?(yarn_version, yarn_range) rescue false
|
12
|
-
is_unsupported = SemanticRange.satisfies?(yarn_version, ">=
|
15
|
+
is_unsupported = SemanticRange.satisfies?(yarn_version, ">=4.0.0") rescue false
|
13
16
|
|
14
17
|
unless is_valid
|
15
18
|
$stderr.puts "Webpacker requires Yarn \"#{yarn_range}\" and you are using #{yarn_version}"
|
@@ -2,7 +2,7 @@ require "webpacker/configuration"
|
|
2
2
|
|
3
3
|
namespace :webpacker do
|
4
4
|
desc "Remove the webpack compiled output directory"
|
5
|
-
task clobber: ["webpacker:
|
5
|
+
task clobber: ["webpacker:verify_config", :environment] do
|
6
6
|
Webpacker.clobber
|
7
7
|
$stdout.puts "Removed webpack output path directory #{Webpacker.config.public_output_path}"
|
8
8
|
end
|
@@ -7,9 +7,9 @@ namespace :webpacker do
|
|
7
7
|
prefix = task.name.split(/#|webpacker:install/).first
|
8
8
|
|
9
9
|
if Rails::VERSION::MAJOR >= 5
|
10
|
-
exec "#{RbConfig.ruby} #{bin_path}/rails #{prefix}app:template LOCATION
|
10
|
+
exec "#{RbConfig.ruby} #{bin_path}/rails #{prefix}app:template LOCATION='#{install_template_path}'"
|
11
11
|
else
|
12
|
-
exec "#{RbConfig.ruby} #{bin_path}/rake #{prefix}rails:template LOCATION
|
12
|
+
exec "#{RbConfig.ruby} #{bin_path}/rake #{prefix}rails:template LOCATION='#{install_template_path}'"
|
13
13
|
end
|
14
14
|
end
|
15
15
|
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require "webpacker/configuration"
|
2
|
+
|
3
|
+
namespace :webpacker do
|
4
|
+
desc "Verifies if the Webpacker config is present"
|
5
|
+
task :verify_config do
|
6
|
+
unless Webpacker.config.config_path.exist?
|
7
|
+
path = Webpacker.config.config_path.relative_path_from(Pathname.new(pwd)).to_s
|
8
|
+
$stderr.puts "Configuration #{path} file not found. \n"\
|
9
|
+
"Make sure webpacker:install is run successfully before " \
|
10
|
+
"running dependent tasks"
|
11
|
+
exit!
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -1,14 +1,4 @@
|
|
1
|
-
require "webpacker/configuration"
|
2
|
-
|
3
1
|
namespace :webpacker do
|
4
2
|
desc "Verifies if Webpacker is installed"
|
5
|
-
task verify_install: [:check_node, :check_yarn, :check_binstubs]
|
6
|
-
unless Webpacker.config.config_path.exist?
|
7
|
-
path = Webpacker.config.config_path.relative_path_from(Pathname.new(pwd)).to_s
|
8
|
-
$stderr.puts "Configuration #{path} file not found. \n"\
|
9
|
-
"Make sure webpacker:install is run successfully before " \
|
10
|
-
"running dependent tasks"
|
11
|
-
exit!
|
12
|
-
end
|
13
|
-
end
|
3
|
+
task verify_install: [:verify_config, :check_node, :check_yarn, :check_binstubs]
|
14
4
|
end
|
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/lib/webpacker/commands.rb
CHANGED
@@ -64,7 +64,8 @@ class Webpacker::Commands
|
|
64
64
|
|
65
65
|
def current_version
|
66
66
|
packs = manifest.refresh.values.map do |value|
|
67
|
-
|
67
|
+
value = value["src"] if value.is_a?(Hash)
|
68
|
+
next unless value.is_a?(String)
|
68
69
|
|
69
70
|
File.join(config.root_path, "public", "#{value}*")
|
70
71
|
end.compact
|
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.
|
@@ -65,12 +65,18 @@ class Webpacker::Compiler
|
|
65
65
|
compilation_digest_path.write(watched_files_digest)
|
66
66
|
end
|
67
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
|
+
|
68
74
|
def run_webpack
|
69
75
|
logger.info "Compiling..."
|
70
76
|
|
71
77
|
stdout, stderr, status = Open3.capture3(
|
72
78
|
webpack_env,
|
73
|
-
"#{
|
79
|
+
"#{optionalRubyRunner} ./bin/webpack",
|
74
80
|
chdir: File.expand_path(config.root_path)
|
75
81
|
)
|
76
82
|
|
@@ -63,18 +63,22 @@ class Webpacker::Configuration
|
|
63
63
|
fetch(:webpack_compile_output)
|
64
64
|
end
|
65
65
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
end
|
66
|
+
def fetch(key)
|
67
|
+
data.fetch(key, defaults[key])
|
68
|
+
end
|
70
69
|
|
70
|
+
private
|
71
71
|
def data
|
72
72
|
@data ||= load
|
73
73
|
end
|
74
74
|
|
75
75
|
def load
|
76
|
-
|
77
|
-
|
76
|
+
config = begin
|
77
|
+
YAML.load_file(config_path.to_s, aliases: true)
|
78
|
+
rescue ArgumentError
|
79
|
+
YAML.load_file(config_path.to_s)
|
80
|
+
end
|
81
|
+
config[env].deep_symbolize_keys
|
78
82
|
rescue Errno::ENOENT => e
|
79
83
|
raise "Webpacker configuration file not found #{config_path}. " \
|
80
84
|
"Please run rails webpacker:install " \
|
@@ -87,7 +91,14 @@ class Webpacker::Configuration
|
|
87
91
|
end
|
88
92
|
|
89
93
|
def defaults
|
90
|
-
@defaults ||=
|
91
|
-
|
94
|
+
@defaults ||= begin
|
95
|
+
path = File.expand_path("../../install/config/webpacker.yml", __FILE__)
|
96
|
+
config = begin
|
97
|
+
YAML.load_file(path, aliases: true)
|
98
|
+
rescue ArgumentError
|
99
|
+
YAML.load_file(path)
|
100
|
+
end
|
101
|
+
HashWithIndifferentAccess.new(config[env])
|
102
|
+
end
|
92
103
|
end
|
93
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
|
|
@@ -20,7 +20,7 @@ module Webpacker
|
|
20
20
|
|
21
21
|
@config = Configuration.new(
|
22
22
|
root_path: app_root,
|
23
|
-
config_path:
|
23
|
+
config_path: Pathname.new(@webpacker_config),
|
24
24
|
env: ENV["RAILS_ENV"]
|
25
25
|
)
|
26
26
|
|
@@ -30,6 +30,7 @@ module Webpacker
|
|
30
30
|
@port = dev_server.port
|
31
31
|
@pretty = dev_server.pretty?
|
32
32
|
@https = dev_server.https?
|
33
|
+
@hot = dev_server.hmr?
|
33
34
|
|
34
35
|
rescue Errno::ENOENT, NoMethodError
|
35
36
|
$stdout.puts "webpack dev_server configuration not found in #{@config.config_path}[#{ENV["RAILS_ENV"]}]."
|
@@ -64,6 +65,7 @@ module Webpacker
|
|
64
65
|
def execute_cmd
|
65
66
|
env = Webpacker::Compiler.env
|
66
67
|
env["WEBPACKER_CONFIG"] = @webpacker_config
|
68
|
+
env["WEBPACK_DEV_SERVER"] = "true"
|
67
69
|
|
68
70
|
cmd = if node_modules_bin_exist?
|
69
71
|
["#{@node_modules_bin_path}/webpack", "serve"]
|
@@ -72,11 +74,14 @@ module Webpacker
|
|
72
74
|
end
|
73
75
|
|
74
76
|
if @argv.include?("--debug-webpacker")
|
75
|
-
cmd = [ "node", "--inspect-brk"] + cmd
|
77
|
+
cmd = [ "node", "--inspect-brk", "--trace-warnings" ] + cmd
|
78
|
+
@argv.delete "--debug-webpacker"
|
76
79
|
end
|
77
80
|
|
78
81
|
cmd += ["--config", @webpack_config]
|
79
82
|
cmd += ["--progress", "--color"] if @pretty
|
83
|
+
|
84
|
+
cmd += ["--hot"] if @hot
|
80
85
|
cmd += @argv
|
81
86
|
|
82
87
|
Dir.chdir(@app_path) do
|
data/lib/webpacker/env.rb
CHANGED
@@ -27,7 +27,11 @@ class Webpacker::Env
|
|
27
27
|
|
28
28
|
def available_environments
|
29
29
|
if config_path.exist?
|
30
|
-
|
30
|
+
begin
|
31
|
+
YAML.load_file(config_path.to_s, aliases: true)
|
32
|
+
rescue ArgumentError
|
33
|
+
YAML.load_file(config_path.to_s)
|
34
|
+
end
|
31
35
|
else
|
32
36
|
[].freeze
|
33
37
|
end
|
data/lib/webpacker/helper.rb
CHANGED
@@ -72,43 +72,31 @@ module Webpacker::Helper
|
|
72
72
|
favicon_link_tag(resolve_path_to_image(name), options)
|
73
73
|
end
|
74
74
|
|
75
|
-
# Creates a script tag that references the named pack file, as compiled by webpack per the entries list
|
76
|
-
# in package/environments/base.js. By default, this list is auto-generated to match everything in
|
77
|
-
# app/javascript/packs/*.js. In production mode, the digested reference is automatically looked up.
|
78
|
-
#
|
79
|
-
# Example:
|
80
|
-
#
|
81
|
-
# <%= javascript_pack_tag 'calendar', 'data-turbolinks-track': 'reload' %> # =>
|
82
|
-
# <script src="/packs/calendar-1016838bab065ae1e314.js" data-turbolinks-track="reload"></script>
|
83
|
-
def javascript_pack_tag(*names, **options)
|
84
|
-
javascript_include_tag(*sources_from_manifest_entries(names, type: :javascript), **options)
|
85
|
-
end
|
86
|
-
|
87
75
|
# Creates script tags that reference the js chunks from entrypoints when using split chunks API,
|
88
76
|
# as compiled by webpack per the entries list in package/environments/base.js.
|
89
77
|
# By default, this list is auto-generated to match everything in
|
90
|
-
# app/
|
78
|
+
# app/packs/entrypoints/*.js and all the dependent chunks. In production mode, the digested reference is automatically looked up.
|
91
79
|
# See: https://webpack.js.org/plugins/split-chunks-plugin/
|
92
80
|
#
|
93
81
|
# Example:
|
94
82
|
#
|
95
|
-
# <%=
|
96
|
-
# <script src="/packs/vendor-16838bab065ae1e314.chunk.js" data-turbolinks-track="reload"></script>
|
97
|
-
# <script src="/packs/calendar~runtime-16838bab065ae1e314.chunk.js" data-turbolinks-track="reload"></script>
|
98
|
-
# <script src="/packs/calendar-1016838bab065ae1e314.chunk.js" data-turbolinks-track="reload"></script>
|
99
|
-
# <script src="/packs/map~runtime-16838bab065ae1e314.chunk.js" data-turbolinks-track="reload"></script>
|
100
|
-
# <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>
|
101
89
|
#
|
102
90
|
# DO:
|
103
91
|
#
|
104
|
-
# <%=
|
92
|
+
# <%= javascript_pack_tag 'calendar', 'map' %>
|
105
93
|
#
|
106
94
|
# DON'T:
|
107
95
|
#
|
108
|
-
# <%=
|
109
|
-
# <%=
|
110
|
-
def
|
111
|
-
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, **options)
|
99
|
+
javascript_include_tag(*sources_from_manifest_entrypoints(names, type: :javascript), defer: true, **options)
|
112
100
|
end
|
113
101
|
|
114
102
|
# Creates a link tag, for preloading, that references a given Webpacker asset.
|
@@ -127,57 +115,45 @@ module Webpacker::Helper
|
|
127
115
|
end
|
128
116
|
end
|
129
117
|
|
130
|
-
# Creates a link tag that references the named pack file, as compiled by webpack per the entries list
|
131
|
-
# in package/environments/base.js. By default, this list is auto-generated to match everything in
|
132
|
-
# app/javascript/packs/*.js. In production mode, the digested reference is automatically looked up.
|
133
|
-
#
|
134
|
-
# Note: If the development server is running and hot module replacement is active, this will return nothing.
|
135
|
-
# In that setup you need to configure your styles to be inlined in your JavaScript for hot reloading.
|
136
|
-
#
|
137
|
-
# Examples:
|
138
|
-
#
|
139
|
-
# <%= stylesheet_pack_tag 'calendar', 'data-turbolinks-track': 'reload' %> # =>
|
140
|
-
# <link rel="stylesheet" media="screen" href="/packs/calendar-1016838bab065ae1e122.css" data-turbolinks-track="reload" />
|
141
|
-
def stylesheet_pack_tag(*names, **options)
|
142
|
-
stylesheet_link_tag(*sources_from_manifest_entries(names, type: :stylesheet), **options)
|
143
|
-
end
|
144
|
-
|
145
118
|
# Creates link tags that reference the css chunks from entrypoints when using split chunks API,
|
146
119
|
# as compiled by webpack per the entries list in package/environments/base.js.
|
147
120
|
# By default, this list is auto-generated to match everything in
|
148
|
-
# app/
|
121
|
+
# app/packs/entrypoints/*.js and all the dependent chunks. In production mode, the digested reference is automatically looked up.
|
149
122
|
# See: https://webpack.js.org/plugins/split-chunks-plugin/
|
150
123
|
#
|
151
124
|
# Examples:
|
152
125
|
#
|
153
|
-
# <%=
|
126
|
+
# <%= stylesheet_pack_tag 'calendar', 'map' %> # =>
|
154
127
|
# <link rel="stylesheet" media="screen" href="/packs/3-8c7ce31a.chunk.css" />
|
155
128
|
# <link rel="stylesheet" media="screen" href="/packs/calendar-8c7ce31a.chunk.css" />
|
156
129
|
# <link rel="stylesheet" media="screen" href="/packs/map-8c7ce31a.chunk.css" />
|
157
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
|
+
#
|
158
135
|
# DO:
|
159
136
|
#
|
160
|
-
# <%=
|
137
|
+
# <%= stylesheet_pack_tag 'calendar', 'map' %>
|
161
138
|
#
|
162
139
|
# DON'T:
|
163
140
|
#
|
164
|
-
# <%=
|
165
|
-
# <%=
|
166
|
-
def
|
141
|
+
# <%= stylesheet_pack_tag 'calendar' %>
|
142
|
+
# <%= stylesheet_pack_tag 'map' %>
|
143
|
+
def stylesheet_pack_tag(*names, **options)
|
144
|
+
return "" if Webpacker.inlining_css?
|
145
|
+
|
167
146
|
stylesheet_link_tag(*sources_from_manifest_entrypoints(names, type: :stylesheet), **options)
|
168
147
|
end
|
169
148
|
|
170
149
|
private
|
171
|
-
def sources_from_manifest_entries(names, type:)
|
172
|
-
names.map { |name| current_webpacker_instance.manifest.lookup!(name, type: type) }.flatten
|
173
|
-
end
|
174
150
|
|
175
151
|
def sources_from_manifest_entrypoints(names, type:)
|
176
|
-
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
|
177
153
|
end
|
178
154
|
|
179
155
|
def resolve_path_to_image(name, **options)
|
180
|
-
path = name.starts_with?("
|
156
|
+
path = name.starts_with?("static/") ? name : "static/#{name}"
|
181
157
|
path_to_asset(current_webpacker_instance.manifest.lookup!(path), options)
|
182
158
|
rescue
|
183
159
|
path_to_asset(current_webpacker_instance.manifest.lookup!(name), options)
|
data/lib/webpacker/instance.rb
CHANGED
data/lib/webpacker/manifest.rb
CHANGED
@@ -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
|
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."
|