webpacker 6.0.0.beta.7 → 6.0.0.rc.2
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 +4 -1
- data/.github/workflows/rubocop.yml +1 -1
- data/.github/workflows/ruby.yml +12 -12
- data/.node-version +1 -1
- data/.rubocop.yml +1 -0
- data/CHANGELOG.md +21 -10
- data/Gemfile.lock +2 -2
- data/README.md +159 -156
- data/config/webpacker.yml +1 -1
- data/docs/developing_webpacker.md +29 -0
- data/docs/troubleshooting.md +53 -23
- data/docs/v6_upgrade.md +31 -42
- data/gemfiles/Gemfile-rails-edge +1 -1
- data/gemfiles/Gemfile-rails.6.1.x +12 -0
- data/lib/install/bin/yarn +18 -0
- data/lib/install/config/webpacker.yml +2 -6
- data/lib/install/package.json +17 -0
- data/lib/install/packs/entrypoints/application.js +3 -4
- data/lib/install/template.rb +28 -15
- data/lib/tasks/webpacker/check_node.rake +3 -1
- data/lib/tasks/webpacker/check_yarn.rake +4 -2
- data/lib/tasks/webpacker/clobber.rake +1 -1
- data/lib/tasks/webpacker/verify_config.rake +14 -0
- data/lib/tasks/webpacker/verify_install.rake +1 -11
- data/lib/tasks/yarn.rake +36 -0
- data/lib/webpacker/configuration.rb +15 -4
- data/lib/webpacker/dev_server.rb +6 -0
- data/lib/webpacker/dev_server_runner.rb +5 -2
- data/lib/webpacker/env.rb +5 -1
- data/lib/webpacker/helper.rb +14 -8
- 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.rb +1 -1
- data/package/__tests__/development.js +2 -2
- data/package/__tests__/env.js +8 -4
- data/package/babel/preset.js +0 -1
- data/package/env.js +7 -1
- data/package/environments/__tests__/base.js +3 -3
- data/package/environments/base.js +12 -7
- data/package/environments/development.js +7 -9
- data/package/index.js +2 -0
- data/package/inliningCss.js +7 -0
- data/package/rules/file.js +1 -1
- data/package/rules/sass.js +1 -2
- data/package/utils/get_style_rule.js +4 -2
- data/package.json +25 -29
- data/test/configuration_test.rb +1 -1
- data/test/dev_server_runner_test.rb +4 -1
- data/test/helper_test.rb +48 -34
- data/test/manifest_test.rb +10 -2
- data/test/mounted_app/test/dummy/config/webpacker.yml +1 -1
- data/test/test_app/config/webpacker.yml +1 -3
- data/test/test_app/config/webpacker_other_location.yml +79 -0
- data/test/test_app/public/packs/manifest.json +12 -5
- data/test/webpacker_test.rb +17 -0
- data/yarn.lock +1567 -1039
- metadata +14 -5
@@ -3,7 +3,9 @@ namespace :webpacker do
|
|
3
3
|
desc "Verifies if Node.js is installed"
|
4
4
|
task :check_node do
|
5
5
|
begin
|
6
|
-
|
6
|
+
which_command = Gem.win_platform? ? "where" : "which"
|
7
|
+
raise Errno::ENOENT if `#{which_command} node || #{which_command} nodejs`.strip.empty?
|
8
|
+
|
7
9
|
node_version = `node -v || nodejs -v`.strip
|
8
10
|
raise Errno::ENOENT if node_version.blank?
|
9
11
|
|
@@ -3,14 +3,16 @@ namespace :webpacker do
|
|
3
3
|
desc "Verifies if Yarn is installed"
|
4
4
|
task :check_yarn do
|
5
5
|
begin
|
6
|
-
|
6
|
+
which_command = Gem.win_platform? ? "where" : "which"
|
7
|
+
raise Errno::ENOENT if `#{which_command} yarn`.strip.empty?
|
8
|
+
|
7
9
|
yarn_version = `yarn --version`.strip
|
8
10
|
raise Errno::ENOENT if yarn_version.blank?
|
9
11
|
|
10
12
|
pkg_path = Pathname.new("#{__dir__}/../../../package.json").realpath
|
11
13
|
yarn_range = JSON.parse(pkg_path.read)["engines"]["yarn"]
|
12
14
|
is_valid = SemanticRange.satisfies?(yarn_version, yarn_range) rescue false
|
13
|
-
is_unsupported = SemanticRange.satisfies?(yarn_version, ">=
|
15
|
+
is_unsupported = SemanticRange.satisfies?(yarn_version, ">=4.0.0") rescue false
|
14
16
|
|
15
17
|
unless is_valid
|
16
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
|
@@ -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/tasks/yarn.rake
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Duplicate of the yarn tasks still present in Rails until Webpacker <5 have been deprecated
|
4
|
+
|
5
|
+
namespace :yarn do
|
6
|
+
desc "Install all JavaScript dependencies as specified via Yarn"
|
7
|
+
task :install do
|
8
|
+
# Install only production deps when for not usual envs.
|
9
|
+
valid_node_envs = %w[test development production]
|
10
|
+
node_env = ENV.fetch("NODE_ENV") do
|
11
|
+
valid_node_envs.include?(Rails.env) ? Rails.env : "production"
|
12
|
+
end
|
13
|
+
|
14
|
+
yarn_flags =
|
15
|
+
if `#{RbConfig.ruby} "#{Rails.root}/bin/yarn" --version`.start_with?("1")
|
16
|
+
"--no-progress --frozen-lockfile"
|
17
|
+
else
|
18
|
+
"--immutable"
|
19
|
+
end
|
20
|
+
|
21
|
+
system(
|
22
|
+
{ "NODE_ENV" => node_env },
|
23
|
+
"#{RbConfig.ruby} \"#{Rails.root}/bin/yarn\" install #{yarn_flags}",
|
24
|
+
exception: true
|
25
|
+
)
|
26
|
+
rescue Errno::ENOENT
|
27
|
+
$stderr.puts "bin/yarn was not found."
|
28
|
+
$stderr.puts "Please run `bundle exec rails app:update:bin` to create it."
|
29
|
+
exit 1
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
# Run Yarn prior to Sprockets assets precompilation, so dependencies are available for use.
|
34
|
+
if Rake::Task.task_defined?("assets:precompile") && File.exist?(Rails.root.join("bin", "yarn"))
|
35
|
+
Rake::Task["assets:precompile"].enhance [ "yarn:install" ]
|
36
|
+
end
|
@@ -73,8 +73,12 @@ class Webpacker::Configuration
|
|
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"]}]."
|
@@ -73,12 +74,14 @@ module Webpacker
|
|
73
74
|
end
|
74
75
|
|
75
76
|
if @argv.include?("--debug-webpacker")
|
76
|
-
cmd = [ "node", "--inspect-brk"] + cmd
|
77
|
+
cmd = [ "node", "--inspect-brk", "--trace-warnings" ] + cmd
|
77
78
|
@argv.delete "--debug-webpacker"
|
78
79
|
end
|
79
80
|
|
80
81
|
cmd += ["--config", @webpack_config]
|
81
82
|
cmd += ["--progress", "--color"] if @pretty
|
83
|
+
|
84
|
+
cmd += ["--hot"] if @hot
|
82
85
|
cmd += @argv
|
83
86
|
|
84
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
@@ -81,11 +81,11 @@ module Webpacker::Helper
|
|
81
81
|
# Example:
|
82
82
|
#
|
83
83
|
# <%= javascript_pack_tag 'calendar', 'map', 'data-turbolinks-track': 'reload' %> # =>
|
84
|
-
# <script src="/packs/vendor-16838bab065ae1e314.chunk.js" data-turbolinks-track="reload"></script>
|
85
|
-
# <script src="/packs/calendar~runtime-16838bab065ae1e314.chunk.js" data-turbolinks-track="reload"></script>
|
86
|
-
# <script src="/packs/calendar-1016838bab065ae1e314.chunk.js" data-turbolinks-track="reload"></script>
|
87
|
-
# <script src="/packs/map~runtime-16838bab065ae1e314.chunk.js" data-turbolinks-track="reload"></script>
|
88
|
-
# <script src="/packs/map-16838bab065ae1e314.chunk.js" data-turbolinks-track="reload"></script>
|
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>
|
89
89
|
#
|
90
90
|
# DO:
|
91
91
|
#
|
@@ -95,8 +95,8 @@ module Webpacker::Helper
|
|
95
95
|
#
|
96
96
|
# <%= javascript_pack_tag 'calendar' %>
|
97
97
|
# <%= javascript_pack_tag 'map' %>
|
98
|
-
def javascript_pack_tag(*names, **options)
|
99
|
-
javascript_include_tag(*sources_from_manifest_entrypoints(names, type: :javascript), **options)
|
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 })
|
100
100
|
end
|
101
101
|
|
102
102
|
# Creates a link tag, for preloading, that references a given Webpacker asset.
|
@@ -128,6 +128,10 @@ module Webpacker::Helper
|
|
128
128
|
# <link rel="stylesheet" media="screen" href="/packs/calendar-8c7ce31a.chunk.css" />
|
129
129
|
# <link rel="stylesheet" media="screen" href="/packs/map-8c7ce31a.chunk.css" />
|
130
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
|
+
#
|
131
135
|
# DO:
|
132
136
|
#
|
133
137
|
# <%= stylesheet_pack_tag 'calendar', 'map' %>
|
@@ -137,6 +141,8 @@ module Webpacker::Helper
|
|
137
141
|
# <%= stylesheet_pack_tag 'calendar' %>
|
138
142
|
# <%= stylesheet_pack_tag 'map' %>
|
139
143
|
def stylesheet_pack_tag(*names, **options)
|
144
|
+
return "" if Webpacker.inlining_css?
|
145
|
+
|
140
146
|
stylesheet_link_tag(*sources_from_manifest_entrypoints(names, type: :stylesheet), **options)
|
141
147
|
end
|
142
148
|
|
@@ -147,7 +153,7 @@ module Webpacker::Helper
|
|
147
153
|
end
|
148
154
|
|
149
155
|
def resolve_path_to_image(name, **options)
|
150
|
-
path = name.starts_with?("
|
156
|
+
path = name.starts_with?("static/") ? name : "static/#{name}"
|
151
157
|
path_to_asset(current_webpacker_instance.manifest.lookup!(path), options)
|
152
158
|
rescue
|
153
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."
|
data/lib/webpacker/version.rb
CHANGED
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
|
@@ -14,7 +14,7 @@ describe('Development environment', () => {
|
|
14
14
|
test('should use development config and environment including devServer if WEBPACK_DEV_SERVER', () => {
|
15
15
|
process.env.RAILS_ENV = 'development'
|
16
16
|
process.env.NODE_ENV = 'development'
|
17
|
-
process.env.WEBPACK_DEV_SERVER = '
|
17
|
+
process.env.WEBPACK_DEV_SERVER = 'true'
|
18
18
|
const { webpackConfig } = require('../index')
|
19
19
|
|
20
20
|
expect(webpackConfig.output.path).toEqual(resolve('public', 'packs'))
|
@@ -23,7 +23,7 @@ describe('Development environment', () => {
|
|
23
23
|
devServer: {
|
24
24
|
host: 'localhost',
|
25
25
|
port: 3035,
|
26
|
-
injectClient:
|
26
|
+
injectClient: false
|
27
27
|
}
|
28
28
|
})
|
29
29
|
})
|
data/package/__tests__/env.js
CHANGED
@@ -15,7 +15,8 @@ describe('Env', () => {
|
|
15
15
|
railsEnv: 'development',
|
16
16
|
nodeEnv: 'development',
|
17
17
|
isProduction: false,
|
18
|
-
isDevelopment: true
|
18
|
+
isDevelopment: true,
|
19
|
+
runningWebpackDevServer: false
|
19
20
|
})
|
20
21
|
})
|
21
22
|
|
@@ -26,7 +27,8 @@ describe('Env', () => {
|
|
26
27
|
railsEnv: 'development',
|
27
28
|
nodeEnv: 'production',
|
28
29
|
isProduction: true,
|
29
|
-
isDevelopment: false
|
30
|
+
isDevelopment: false,
|
31
|
+
runningWebpackDevServer: false
|
30
32
|
})
|
31
33
|
})
|
32
34
|
|
@@ -37,7 +39,8 @@ describe('Env', () => {
|
|
37
39
|
railsEnv: 'production',
|
38
40
|
nodeEnv: 'production',
|
39
41
|
isProduction: true,
|
40
|
-
isDevelopment: false
|
42
|
+
isDevelopment: false,
|
43
|
+
runningWebpackDevServer: false
|
41
44
|
})
|
42
45
|
})
|
43
46
|
|
@@ -48,7 +51,8 @@ describe('Env', () => {
|
|
48
51
|
railsEnv: 'staging',
|
49
52
|
nodeEnv: 'production',
|
50
53
|
isProduction: true,
|
51
|
-
isDevelopment: false
|
54
|
+
isDevelopment: false,
|
55
|
+
runningWebpackDevServer: false
|
52
56
|
})
|
53
57
|
})
|
54
58
|
})
|
data/package/babel/preset.js
CHANGED
data/package/env.js
CHANGED
@@ -16,9 +16,15 @@ const config = safeLoad(readFileSync(configPath), 'utf8')
|
|
16
16
|
const availableEnvironments = Object.keys(config).join('|')
|
17
17
|
const regex = new RegExp(`^(${availableEnvironments})$`, 'g')
|
18
18
|
|
19
|
+
// v4 of webpack-dev-server will switch to WEBPACK_DEV_SERVE
|
20
|
+
// https://github.com/rails/webpacker/issues/3057
|
21
|
+
const runningWebpackDevServer = process.env.WEBPACK_DEV_SERVER === 'true' ||
|
22
|
+
process.env.WEBPACK_DEV_SERVE === 'true'
|
23
|
+
|
19
24
|
module.exports = {
|
20
25
|
railsEnv: railsEnv && railsEnv.match(regex) ? railsEnv : DEFAULT,
|
21
26
|
nodeEnv,
|
22
27
|
isProduction,
|
23
|
-
isDevelopment
|
28
|
+
isDevelopment,
|
29
|
+
runningWebpackDevServer
|
24
30
|
}
|
@@ -29,9 +29,9 @@ describe('Base config', () => {
|
|
29
29
|
})
|
30
30
|
|
31
31
|
test('should return output', () => {
|
32
|
-
expect(baseConfig.output.filename).toEqual('js/[name]
|
32
|
+
expect(baseConfig.output.filename).toEqual('js/[name].js')
|
33
33
|
expect(baseConfig.output.chunkFilename).toEqual(
|
34
|
-
'js/[name]
|
34
|
+
'js/[name].chunk.js'
|
35
35
|
)
|
36
36
|
})
|
37
37
|
|
@@ -44,7 +44,7 @@ describe('Base config', () => {
|
|
44
44
|
})
|
45
45
|
|
46
46
|
test('should return default plugins', () => {
|
47
|
-
expect(baseConfig.plugins.length).toEqual(
|
47
|
+
expect(baseConfig.plugins.length).toEqual(2)
|
48
48
|
})
|
49
49
|
|
50
50
|
test('should return default resolveLoader', () => {
|
@@ -5,10 +5,10 @@ const { basename, dirname, join, relative, resolve } = require('path')
|
|
5
5
|
const extname = require('path-complete-extname')
|
6
6
|
const PnpWebpackPlugin = require('pnp-webpack-plugin')
|
7
7
|
const { sync: globSync } = require('glob')
|
8
|
-
const CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin')
|
9
8
|
const WebpackAssetsManifest = require('webpack-assets-manifest')
|
10
9
|
const webpack = require('webpack')
|
11
10
|
const rules = require('../rules')
|
11
|
+
const { isProduction } = require('../env')
|
12
12
|
const config = require('../config')
|
13
13
|
const { moduleExists } = require('../utils/helpers')
|
14
14
|
|
@@ -52,7 +52,6 @@ const getModulePaths = () => {
|
|
52
52
|
const getPlugins = () => {
|
53
53
|
const plugins = [
|
54
54
|
new webpack.EnvironmentPlugin(process.env),
|
55
|
-
new CaseSensitivePathsPlugin(),
|
56
55
|
new WebpackAssetsManifest({
|
57
56
|
entrypoints: true,
|
58
57
|
writeToDisk: true,
|
@@ -63,11 +62,12 @@ const getPlugins = () => {
|
|
63
62
|
]
|
64
63
|
|
65
64
|
if (moduleExists('css-loader') && moduleExists('mini-css-extract-plugin')) {
|
65
|
+
const hash = isProduction ? '-[contenthash:8]' : ''
|
66
66
|
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
|
67
67
|
plugins.push(
|
68
68
|
new MiniCssExtractPlugin({
|
69
|
-
filename:
|
70
|
-
chunkFilename:
|
69
|
+
filename: `css/[name]${hash}.css`,
|
70
|
+
chunkFilename: `css/[id]${hash}.css`
|
71
71
|
})
|
72
72
|
)
|
73
73
|
}
|
@@ -75,12 +75,17 @@ const getPlugins = () => {
|
|
75
75
|
return plugins
|
76
76
|
}
|
77
77
|
|
78
|
+
// Don't use contentHash except for production for performance
|
79
|
+
// https://webpack.js.org/guides/build-performance/#avoid-production-specific-tooling
|
80
|
+
const hash = isProduction ? '-[contenthash]' : ''
|
78
81
|
module.exports = {
|
79
82
|
mode: 'production',
|
80
83
|
output: {
|
81
|
-
filename:
|
82
|
-
chunkFilename:
|
83
|
-
|
84
|
+
filename: `js/[name]${hash}.js`,
|
85
|
+
chunkFilename: `js/[name]${hash}.chunk.js`,
|
86
|
+
|
87
|
+
// https://webpack.js.org/configuration/output/#outputhotupdatechunkfilename
|
88
|
+
hotUpdateChunkFilename: 'js/[id].[fullhash].hot-update.js',
|
84
89
|
path: config.outputPath,
|
85
90
|
publicPath: config.publicPath
|
86
91
|
},
|