webpacker 6.0.0.beta.7 → 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/.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 +15 -40
- data/.node-version +1 -1
- data/.rubocop.yml +2 -1
- data/CHANGELOG.md +34 -11
- data/CONTRIBUTING.md +19 -0
- data/Gemfile.lock +84 -84
- data/README.md +177 -165
- data/config/webpacker.yml +1 -1
- data/docs/developing_webpacker.md +29 -0
- data/docs/troubleshooting.md +57 -23
- data/docs/v6_upgrade.md +69 -42
- data/gemfiles/Gemfile-rails-edge +1 -1
- data/gemfiles/Gemfile-rails.6.1.x +12 -0
- data/lib/install/{packs/entrypoints/application.js → application.js} +3 -8
- data/lib/install/bin/webpack +4 -7
- data/lib/install/bin/yarn +18 -0
- data/lib/install/config/webpacker.yml +18 -19
- data/lib/install/package.json +15 -0
- data/lib/install/template.rb +38 -16
- 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 +38 -0
- data/lib/webpacker/commands.rb +19 -15
- data/lib/webpacker/configuration.rb +15 -4
- data/lib/webpacker/dev_server.rb +6 -0
- data/lib/webpacker/dev_server_runner.rb +6 -3
- 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 +8 -2
- data/lib/webpacker/runner.rb +1 -1
- data/lib/webpacker/version.rb +1 -1
- data/lib/webpacker/webpack_runner.rb +27 -7
- data/lib/webpacker.rb +1 -1
- data/package/__tests__/development.js +4 -11
- data/package/__tests__/env.js +8 -4
- data/package/babel/preset.js +0 -1
- data/package/config.js +3 -3
- data/package/env.js +6 -3
- data/package/environments/__tests__/base.js +3 -3
- data/package/environments/base.js +13 -8
- data/package/environments/development.js +36 -36
- 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/command_test.rb +76 -0
- data/test/configuration_test.rb +1 -1
- data/test/dev_server_runner_test.rb +5 -2
- 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/initializers/inspect_autoload_paths.rb +1 -0
- 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 +21 -0
- data/webpacker.gemspec +2 -2
- data/yarn.lock +2357 -3262
- metadata +22 -11
@@ -1,8 +1,8 @@
|
|
1
1
|
const { merge } = require('webpack-merge')
|
2
|
-
const webpack = require('webpack')
|
3
2
|
|
4
3
|
const baseConfig = require('./base')
|
5
4
|
const devServer = require('../dev_server')
|
5
|
+
const { runningWebpackDevServer } = require('../env')
|
6
6
|
|
7
7
|
const { outputPath: contentBase, publicPath } = require('../config')
|
8
8
|
|
@@ -11,44 +11,44 @@ let devConfig = {
|
|
11
11
|
devtool: 'cheap-module-source-map'
|
12
12
|
}
|
13
13
|
|
14
|
-
if (
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
14
|
+
if (runningWebpackDevServer) {
|
15
|
+
const liveReload = devServer.live_reload !== undefined ? devServer.live_reload : !devServer.hmr
|
16
|
+
|
17
|
+
const devServerConfig = {
|
18
|
+
devMiddleware: {
|
19
|
+
publicPath
|
20
|
+
},
|
21
|
+
compress: devServer.compress,
|
22
|
+
allowedHosts: devServer.allowed_hosts,
|
23
|
+
host: devServer.host,
|
24
|
+
port: devServer.port,
|
25
|
+
https: devServer.https,
|
26
|
+
hot: devServer.hmr,
|
27
|
+
liveReload,
|
28
|
+
historyApiFallback: { disableDotRule: true },
|
29
|
+
headers: devServer.headers,
|
30
|
+
static: {
|
31
|
+
publicPath: contentBase
|
32
|
+
}
|
33
|
+
}
|
34
|
+
|
35
|
+
if (devServer.static) {
|
36
|
+
devServerConfig.static = { ...devServerConfig.static, ...devServer.static }
|
37
|
+
}
|
38
|
+
|
39
|
+
if (devServer.client) {
|
40
|
+
devServerConfig.client = devServer.client
|
23
41
|
}
|
24
42
|
|
25
43
|
devConfig = merge(devConfig, {
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
hot: devServer.hmr,
|
35
|
-
contentBase,
|
36
|
-
inline: devServer.inline,
|
37
|
-
injectClient: devServer.inject_client,
|
38
|
-
useLocalIp: devServer.use_local_ip,
|
39
|
-
public: devServer.public,
|
40
|
-
publicPath,
|
41
|
-
historyApiFallback: { disableDotRule: true },
|
42
|
-
headers: devServer.headers,
|
43
|
-
overlay: devServer.overlay,
|
44
|
-
stats: {
|
45
|
-
entrypoints: false,
|
46
|
-
errorDetails: true,
|
47
|
-
modules: false,
|
48
|
-
moduleTrace: false
|
49
|
-
},
|
50
|
-
watchOptions: devServer.watch_options
|
51
|
-
}
|
44
|
+
stats: {
|
45
|
+
colors: true,
|
46
|
+
entrypoints: false,
|
47
|
+
errorDetails: true,
|
48
|
+
modules: false,
|
49
|
+
moduleTrace: false
|
50
|
+
},
|
51
|
+
devServer: devServerConfig
|
52
52
|
})
|
53
53
|
}
|
54
54
|
|
data/package/index.js
CHANGED
@@ -10,6 +10,7 @@ const config = require('./config')
|
|
10
10
|
const devServer = require('./dev_server')
|
11
11
|
const { nodeEnv } = require('./env')
|
12
12
|
const { moduleExists, canProcess } = require('./utils/helpers')
|
13
|
+
const inliningCss = require('./inliningCss')
|
13
14
|
|
14
15
|
const webpackConfig = () => {
|
15
16
|
const path = resolve(__dirname, 'environments', `${nodeEnv}.js`)
|
@@ -25,5 +26,6 @@ module.exports = {
|
|
25
26
|
rules,
|
26
27
|
moduleExists,
|
27
28
|
canProcess,
|
29
|
+
inliningCss,
|
28
30
|
...webpackMerge
|
29
31
|
}
|
data/package/rules/file.js
CHANGED
data/package/rules/sass.js
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
/* eslint global-require: 0 */
|
2
|
-
|
3
2
|
const { canProcess, moduleExists } = require('./helpers')
|
3
|
+
const inliningCss = require('../inliningCss')
|
4
4
|
|
5
5
|
const getStyleRule = (test, preprocessors = []) => {
|
6
6
|
if (moduleExists('css-loader')) {
|
@@ -10,8 +10,10 @@ const getStyleRule = (test, preprocessors = []) => {
|
|
10
10
|
options: { sourceMap: true }
|
11
11
|
}))
|
12
12
|
|
13
|
+
// style-loader is required when using css modules with HMR on the webpack-dev-server
|
14
|
+
|
13
15
|
const use = [
|
14
|
-
|
16
|
+
inliningCss ? 'style-loader' : require('mini-css-extract-plugin').loader,
|
15
17
|
{
|
16
18
|
loader: require.resolve('css-loader'),
|
17
19
|
options: {
|
data/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@rails/webpacker",
|
3
|
-
"version": "6.0.0-
|
3
|
+
"version": "6.0.0-rc.6",
|
4
4
|
"description": "Use webpack to manage app-like JavaScript modules in Rails",
|
5
5
|
"main": "package/index.js",
|
6
6
|
"files": [
|
@@ -8,40 +8,36 @@
|
|
8
8
|
"lib/install/config/webpacker.yml"
|
9
9
|
],
|
10
10
|
"engines": {
|
11
|
-
"node": ">=
|
12
|
-
"yarn": ">=1 <
|
11
|
+
"node": ">= 12.13.0 || >=14",
|
12
|
+
"yarn": ">=1 <4"
|
13
13
|
},
|
14
14
|
"dependencies": {
|
15
|
-
"@babel/core": "^7.
|
16
|
-
"@babel/plugin-proposal-class-properties": "^7.
|
17
|
-
"@babel/plugin-transform-runtime": "^7.
|
18
|
-
"@babel/preset-env": "^7.
|
19
|
-
"@babel/runtime": "^7.
|
15
|
+
"@babel/core": "^7.15.5",
|
16
|
+
"@babel/plugin-proposal-class-properties": "^7.14.5",
|
17
|
+
"@babel/plugin-transform-runtime": "^7.15.0",
|
18
|
+
"@babel/preset-env": "^7.15.6",
|
19
|
+
"@babel/runtime": "^7.15.4",
|
20
20
|
"babel-loader": "^8.2.2",
|
21
|
-
"
|
22
|
-
"
|
23
|
-
"
|
24
|
-
"core-js": "^3.8.0",
|
25
|
-
"glob": "^7.1.6",
|
26
|
-
"js-yaml": "^3.14.0",
|
21
|
+
"compression-webpack-plugin": "^9.0.0",
|
22
|
+
"glob": "^7.2.0",
|
23
|
+
"js-yaml": "^4.1.0",
|
27
24
|
"path-complete-extname": "^1.0.0",
|
28
|
-
"pnp-webpack-plugin": "^1.
|
29
|
-
"
|
30
|
-
"
|
31
|
-
"webpack": "^5.
|
32
|
-
"webpack-
|
33
|
-
"webpack-
|
34
|
-
"webpack-
|
35
|
-
"webpack-sources": "^2.2.0"
|
25
|
+
"pnp-webpack-plugin": "^1.7.0",
|
26
|
+
"terser-webpack-plugin": "^5.2.4",
|
27
|
+
"webpack": "^5.53.0",
|
28
|
+
"webpack-assets-manifest": "^5.0.6",
|
29
|
+
"webpack-cli": "^4.8.0",
|
30
|
+
"webpack-merge": "^5.8.0",
|
31
|
+
"webpack-sources": "^3.2.1"
|
36
32
|
},
|
37
33
|
"devDependencies": {
|
38
|
-
"eslint": "^7.
|
39
|
-
"eslint-config-airbnb": "^18.2.
|
40
|
-
"eslint-config-prettier": "^
|
41
|
-
"eslint-plugin-import": "^2.
|
42
|
-
"eslint-plugin-jsx-a11y": "^6.
|
43
|
-
"eslint-plugin-react": "^7.
|
44
|
-
"jest": "^
|
34
|
+
"eslint": "^7.32.0",
|
35
|
+
"eslint-config-airbnb": "^18.2.1",
|
36
|
+
"eslint-config-prettier": "^8.3.0",
|
37
|
+
"eslint-plugin-import": "^2.24.2",
|
38
|
+
"eslint-plugin-jsx-a11y": "^6.4.1",
|
39
|
+
"eslint-plugin-react": "^7.26.0",
|
40
|
+
"jest": "^27.2.1"
|
45
41
|
},
|
46
42
|
"jest": {
|
47
43
|
"testRegex": "(/__tests__/.*|(\\.|/))\\.jsx?$",
|
data/test/command_test.rb
CHANGED
@@ -31,3 +31,79 @@ class CommandTest < Minitest::Test
|
|
31
31
|
end
|
32
32
|
end
|
33
33
|
end
|
34
|
+
|
35
|
+
class ClearCommandVersioningTest < Minitest::Test
|
36
|
+
def setup
|
37
|
+
@now = Time.parse("2021-01-01 12:34:56 UTC")
|
38
|
+
# Test assets to be kept and deleted, path and mtime
|
39
|
+
@prev_files = {
|
40
|
+
# recent versions to be kept with Webpacker.commands.clean(count = 2)
|
41
|
+
"js/application-deadbeef.js" => @now - 4000,
|
42
|
+
"js/common-deadbeee.js" => @now - 4002,
|
43
|
+
"css/common-deadbeed.css" => @now - 4004,
|
44
|
+
"media/images/logo-deadbeeb.css" => @now - 4006,
|
45
|
+
"js/application-1eadbeef.js" => @now - 8000,
|
46
|
+
"js/common-1eadbeee.js" => @now - 8002,
|
47
|
+
"css/common-1eadbeed.css" => @now - 8004,
|
48
|
+
"media/images/logo-1eadbeeb.css" => @now - 8006,
|
49
|
+
# new files to be kept with Webpacker.commands.clean(age = 3600)
|
50
|
+
"js/brandnew-0001.js" => @now,
|
51
|
+
"js/brandnew-0002.js" => @now - 10,
|
52
|
+
"js/brandnew-0003.js" => @now - 20,
|
53
|
+
"js/brandnew-0004.js" => @now - 40,
|
54
|
+
}.transform_keys { |path| "#{Webpacker.config.public_output_path}/#{path}" }
|
55
|
+
@expired_files = {
|
56
|
+
# old files that are outside count = 2 or age = 3600 and to be deleted
|
57
|
+
"js/application-0eadbeef.js" => @now - 9000,
|
58
|
+
"js/common-0eadbeee.js" => @now - 9002,
|
59
|
+
"css/common-0eadbeed.css" => @now - 9004,
|
60
|
+
"js/brandnew-0005.js" => @now - 3640,
|
61
|
+
}.transform_keys { |path| "#{Webpacker.config.public_output_path}/#{path}" }
|
62
|
+
@all_files = @prev_files.merge(@expired_files)
|
63
|
+
@dir_glob_stub = Proc.new { |arg|
|
64
|
+
case arg
|
65
|
+
when "#{Webpacker.config.public_output_path}/**/*"
|
66
|
+
@all_files.keys
|
67
|
+
else
|
68
|
+
[]
|
69
|
+
end
|
70
|
+
}
|
71
|
+
@file_mtime_stub = Proc.new { |longpath|
|
72
|
+
@all_files[longpath]
|
73
|
+
}
|
74
|
+
@file_delete_mock = Minitest::Mock.new
|
75
|
+
@expired_files.keys.each do |longpath|
|
76
|
+
@file_delete_mock.expect(:delete, 1, [longpath])
|
77
|
+
end
|
78
|
+
@file_delete_stub = Proc.new { |longpath|
|
79
|
+
if @prev_files.has_key?(longpath)
|
80
|
+
flunk "#{longpath} should not be deleted"
|
81
|
+
else
|
82
|
+
@file_delete_mock.delete(longpath)
|
83
|
+
end
|
84
|
+
}
|
85
|
+
end
|
86
|
+
|
87
|
+
def time_and_files_stub(&proc)
|
88
|
+
Time.stub :now, @now do
|
89
|
+
Dir.stub :glob, @dir_glob_stub do
|
90
|
+
File.stub :directory?, false do
|
91
|
+
File.stub :file?, true do
|
92
|
+
File.stub :mtime, @file_mtime_stub do
|
93
|
+
File.stub :delete, @file_delete_stub do
|
94
|
+
yield proc
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
@file_delete_mock.verify
|
102
|
+
end
|
103
|
+
|
104
|
+
def test_clean_command_with_versioned_files
|
105
|
+
time_and_files_stub do
|
106
|
+
assert Webpacker.commands.clean
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
data/test/configuration_test.rb
CHANGED
@@ -44,7 +44,7 @@ class ConfigurationTest < Webpacker::Test
|
|
44
44
|
end
|
45
45
|
|
46
46
|
def test_cache_path
|
47
|
-
cache_path = File.expand_path File.join(File.dirname(__FILE__), "test_app/tmp/
|
47
|
+
cache_path = File.expand_path File.join(File.dirname(__FILE__), "test_app/tmp/webpacker").to_s
|
48
48
|
assert_equal @config.cache_path.to_s, cache_path
|
49
49
|
end
|
50
50
|
|
@@ -5,11 +5,13 @@ class DevServerRunnerTest < Webpacker::Test
|
|
5
5
|
def setup
|
6
6
|
@original_node_env, ENV["NODE_ENV"] = ENV["NODE_ENV"], "development"
|
7
7
|
@original_rails_env, ENV["RAILS_ENV"] = ENV["RAILS_ENV"], "development"
|
8
|
+
@original_webpacker_config = ENV["WEBPACKER_CONFIG"]
|
8
9
|
end
|
9
10
|
|
10
11
|
def teardown
|
11
12
|
ENV["NODE_ENV"] = @original_node_env
|
12
13
|
ENV["RAILS_ENV"] = @original_rails_env
|
14
|
+
ENV["WEBPACKER_CONFIG"] = @original_webpacker_config
|
13
15
|
end
|
14
16
|
|
15
17
|
def test_run_cmd_via_node_modules
|
@@ -38,6 +40,7 @@ class DevServerRunnerTest < Webpacker::Test
|
|
38
40
|
def dev_server.port; "3035"; end
|
39
41
|
def dev_server.pretty?; false; end
|
40
42
|
def dev_server.https?; true; end
|
43
|
+
def dev_server.hmr?; false; end
|
41
44
|
Webpacker::DevServer.stub(:new, dev_server) do
|
42
45
|
verify_command(cmd, argv: ["--https"])
|
43
46
|
end
|
@@ -46,8 +49,8 @@ class DevServerRunnerTest < Webpacker::Test
|
|
46
49
|
def test_environment_variables
|
47
50
|
cmd = ["#{test_app_path}/node_modules/.bin/webpack", "serve", "--config", "#{test_app_path}/config/webpack/development.js"]
|
48
51
|
env = Webpacker::Compiler.env.dup
|
49
|
-
env["WEBPACKER_CONFIG"] = "#{test_app_path}/config/
|
50
|
-
env["
|
52
|
+
ENV["WEBPACKER_CONFIG"] = env["WEBPACKER_CONFIG"] = "#{test_app_path}/config/webpacker_other_location.yml"
|
53
|
+
env["WEBPACK_SERVE"] = "true"
|
51
54
|
verify_command(cmd, env: env)
|
52
55
|
end
|
53
56
|
|
data/test/helper_test.rb
CHANGED
@@ -26,18 +26,18 @@ class HelperTest < ActionView::TestCase
|
|
26
26
|
|
27
27
|
def test_image_pack_path
|
28
28
|
assert_equal "/packs/application-k344a6d59eef8632c9d1.png", image_pack_path("application.png")
|
29
|
-
assert_equal "/packs/
|
30
|
-
assert_equal "/packs/
|
31
|
-
assert_equal "/packs/
|
32
|
-
assert_equal "/packs/
|
29
|
+
assert_equal "/packs/static/image-c38deda30895059837cf.jpg", image_pack_path("image.jpg")
|
30
|
+
assert_equal "/packs/static/image-c38deda30895059837cf.jpg", image_pack_path("static/image.jpg")
|
31
|
+
assert_equal "/packs/static/nested/image-c38deda30895059837cf.jpg", image_pack_path("nested/image.jpg")
|
32
|
+
assert_equal "/packs/static/nested/image-c38deda30895059837cf.jpg", image_pack_path("static/nested/image.jpg")
|
33
33
|
end
|
34
34
|
|
35
35
|
def test_image_pack_url
|
36
36
|
assert_equal "https://example.com/packs/application-k344a6d59eef8632c9d1.png", image_pack_url("application.png")
|
37
|
-
assert_equal "https://example.com/packs/
|
38
|
-
assert_equal "https://example.com/packs/
|
39
|
-
assert_equal "https://example.com/packs/
|
40
|
-
assert_equal "https://example.com/packs/
|
37
|
+
assert_equal "https://example.com/packs/static/image-c38deda30895059837cf.jpg", image_pack_url("image.jpg")
|
38
|
+
assert_equal "https://example.com/packs/static/image-c38deda30895059837cf.jpg", image_pack_url("static/image.jpg")
|
39
|
+
assert_equal "https://example.com/packs/static/nested/image-c38deda30895059837cf.jpg", image_pack_url("nested/image.jpg")
|
40
|
+
assert_equal "https://example.com/packs/static/nested/image-c38deda30895059837cf.jpg", image_pack_url("static/nested/image.jpg")
|
41
41
|
end
|
42
42
|
|
43
43
|
def test_image_pack_tag
|
@@ -45,20 +45,20 @@ class HelperTest < ActionView::TestCase
|
|
45
45
|
"<img alt=\"Edit Entry\" src=\"/packs/application-k344a6d59eef8632c9d1.png\" width=\"16\" height=\"10\" />",
|
46
46
|
image_pack_tag("application.png", size: "16x10", alt: "Edit Entry")
|
47
47
|
assert_equal \
|
48
|
-
"<img alt=\"Edit Entry\" src=\"/packs/
|
48
|
+
"<img alt=\"Edit Entry\" src=\"/packs/static/image-c38deda30895059837cf.jpg\" width=\"16\" height=\"10\" />",
|
49
49
|
image_pack_tag("image.jpg", size: "16x10", alt: "Edit Entry")
|
50
50
|
assert_equal \
|
51
|
-
"<img alt=\"Edit Entry\" src=\"/packs/
|
52
|
-
image_pack_tag("
|
51
|
+
"<img alt=\"Edit Entry\" src=\"/packs/static/image-c38deda30895059837cf.jpg\" width=\"16\" height=\"10\" />",
|
52
|
+
image_pack_tag("static/image.jpg", size: "16x10", alt: "Edit Entry")
|
53
53
|
assert_equal \
|
54
|
-
"<img alt=\"Edit Entry\" src=\"/packs/
|
54
|
+
"<img alt=\"Edit Entry\" src=\"/packs/static/nested/image-c38deda30895059837cf.jpg\" width=\"16\" height=\"10\" />",
|
55
55
|
image_pack_tag("nested/image.jpg", size: "16x10", alt: "Edit Entry")
|
56
56
|
assert_equal \
|
57
|
-
"<img alt=\"Edit Entry\" src=\"/packs/
|
58
|
-
image_pack_tag("
|
57
|
+
"<img alt=\"Edit Entry\" src=\"/packs/static/nested/image-c38deda30895059837cf.jpg\" width=\"16\" height=\"10\" />",
|
58
|
+
image_pack_tag("static/nested/image.jpg", size: "16x10", alt: "Edit Entry")
|
59
59
|
assert_equal \
|
60
|
-
"<img srcset=\"/packs/
|
61
|
-
image_pack_tag("
|
60
|
+
"<img srcset=\"/packs/static/image-2x-7cca48e6cae66ec07b8e.jpg 2x\" src=\"/packs/static/image-c38deda30895059837cf.jpg\" />",
|
61
|
+
image_pack_tag("static/image.jpg", srcset: { "static/image-2x.jpg" => "2x" })
|
62
62
|
end
|
63
63
|
|
64
64
|
def test_favicon_pack_tag
|
@@ -66,17 +66,17 @@ class HelperTest < ActionView::TestCase
|
|
66
66
|
"<link rel=\"apple-touch-icon\" type=\"image/png\" href=\"/packs/application-k344a6d59eef8632c9d1.png\" />",
|
67
67
|
favicon_pack_tag("application.png", rel: "apple-touch-icon", type: "image/png")
|
68
68
|
assert_equal \
|
69
|
-
"<link rel=\"apple-touch-icon\" type=\"image/png\" href=\"/packs/
|
69
|
+
"<link rel=\"apple-touch-icon\" type=\"image/png\" href=\"/packs/static/mb-icon-c38deda30895059837cf.png\" />",
|
70
70
|
favicon_pack_tag("mb-icon.png", rel: "apple-touch-icon", type: "image/png")
|
71
71
|
assert_equal \
|
72
|
-
"<link rel=\"apple-touch-icon\" type=\"image/png\" href=\"/packs/
|
73
|
-
favicon_pack_tag("
|
72
|
+
"<link rel=\"apple-touch-icon\" type=\"image/png\" href=\"/packs/static/mb-icon-c38deda30895059837cf.png\" />",
|
73
|
+
favicon_pack_tag("static/mb-icon.png", rel: "apple-touch-icon", type: "image/png")
|
74
74
|
assert_equal \
|
75
|
-
"<link rel=\"apple-touch-icon\" type=\"image/png\" href=\"/packs/
|
75
|
+
"<link rel=\"apple-touch-icon\" type=\"image/png\" href=\"/packs/static/nested/mb-icon-c38deda30895059837cf.png\" />",
|
76
76
|
favicon_pack_tag("nested/mb-icon.png", rel: "apple-touch-icon", type: "image/png")
|
77
77
|
assert_equal \
|
78
|
-
"<link rel=\"apple-touch-icon\" type=\"image/png\" href=\"/packs/
|
79
|
-
favicon_pack_tag("
|
78
|
+
"<link rel=\"apple-touch-icon\" type=\"image/png\" href=\"/packs/static/nested/mb-icon-c38deda30895059837cf.png\" />",
|
79
|
+
favicon_pack_tag("static/nested/mb-icon.png", rel: "apple-touch-icon", type: "image/png")
|
80
80
|
end
|
81
81
|
|
82
82
|
def test_preload_pack_asset
|
@@ -96,12 +96,21 @@ class HelperTest < ActionView::TestCase
|
|
96
96
|
end
|
97
97
|
|
98
98
|
def test_javascript_pack_tag
|
99
|
+
assert_equal \
|
100
|
+
%(<script src="/packs/vendors~application~bootstrap-c20632e7baf2c81200d3.chunk.js" defer="defer"></script>\n) +
|
101
|
+
%(<script src="/packs/vendors~application-e55f2aae30c07fb6d82a.chunk.js" defer="defer"></script>\n) +
|
102
|
+
%(<script src="/packs/application-k344a6d59eef8632c9d1.js" defer="defer"></script>\n) +
|
103
|
+
%(<script src="/packs/bootstrap-300631c4f0e0f9c865bc.js" defer="defer"></script>),
|
104
|
+
javascript_pack_tag("application", "bootstrap")
|
105
|
+
end
|
106
|
+
|
107
|
+
def test_javascript_pack_with_no_defer_tag
|
99
108
|
assert_equal \
|
100
109
|
%(<script src="/packs/vendors~application~bootstrap-c20632e7baf2c81200d3.chunk.js"></script>\n) +
|
101
110
|
%(<script src="/packs/vendors~application-e55f2aae30c07fb6d82a.chunk.js"></script>\n) +
|
102
111
|
%(<script src="/packs/application-k344a6d59eef8632c9d1.js"></script>\n) +
|
103
112
|
%(<script src="/packs/bootstrap-300631c4f0e0f9c865bc.js"></script>),
|
104
|
-
javascript_pack_tag("application", "bootstrap")
|
113
|
+
javascript_pack_tag("application", "bootstrap", defer: false)
|
105
114
|
end
|
106
115
|
|
107
116
|
def test_javascript_pack_tag_splat
|
@@ -114,32 +123,37 @@ class HelperTest < ActionView::TestCase
|
|
114
123
|
|
115
124
|
def test_javascript_pack_tag_symbol
|
116
125
|
assert_equal \
|
117
|
-
%(<script src="/packs/vendors~application~bootstrap-c20632e7baf2c81200d3.chunk.js"></script>\n) +
|
118
|
-
%(<script src="/packs/vendors~application-e55f2aae30c07fb6d82a.chunk.js"></script>\n) +
|
119
|
-
%(<script src="/packs/application-k344a6d59eef8632c9d1.js"></script>),
|
126
|
+
%(<script src="/packs/vendors~application~bootstrap-c20632e7baf2c81200d3.chunk.js" defer="defer"></script>\n) +
|
127
|
+
%(<script src="/packs/vendors~application-e55f2aae30c07fb6d82a.chunk.js" defer="defer"></script>\n) +
|
128
|
+
%(<script src="/packs/application-k344a6d59eef8632c9d1.js" defer="defer"></script>),
|
120
129
|
javascript_pack_tag(:application)
|
121
130
|
end
|
122
131
|
|
132
|
+
def application_stylesheet_chunks
|
133
|
+
%w[/packs/1-c20632e7baf2c81200d3.chunk.css /packs/application-k344a6d59eef8632c9d1.chunk.css]
|
134
|
+
end
|
135
|
+
|
136
|
+
def hello_stimulus_stylesheet_chunks
|
137
|
+
%w[/packs/hello_stimulus-k344a6d59eef8632c9d1.chunk.css]
|
138
|
+
end
|
139
|
+
|
123
140
|
def test_stylesheet_pack_tag
|
124
141
|
assert_equal \
|
125
|
-
|
126
|
-
|
127
|
-
%(<link rel="stylesheet" media="screen" href="/packs/hello_stimulus-k344a6d59eef8632c9d1.chunk.css" />),
|
142
|
+
(application_stylesheet_chunks + hello_stimulus_stylesheet_chunks)
|
143
|
+
.map { |chunk| stylesheet_link_tag(chunk) }.join("\n"),
|
128
144
|
stylesheet_pack_tag("application", "hello_stimulus")
|
129
145
|
end
|
130
146
|
|
131
147
|
def test_stylesheet_pack_tag_symbol
|
132
148
|
assert_equal \
|
133
|
-
|
134
|
-
|
135
|
-
%(<link rel="stylesheet" media="screen" href="/packs/hello_stimulus-k344a6d59eef8632c9d1.chunk.css" />),
|
149
|
+
(application_stylesheet_chunks + hello_stimulus_stylesheet_chunks)
|
150
|
+
.map { |chunk| stylesheet_link_tag(chunk) }.join("\n"),
|
136
151
|
stylesheet_pack_tag(:application, :hello_stimulus)
|
137
152
|
end
|
138
153
|
|
139
154
|
def test_stylesheet_pack_tag_splat
|
140
155
|
assert_equal \
|
141
|
-
|
142
|
-
%(<link rel="stylesheet" media="all" href="/packs/application-k344a6d59eef8632c9d1.chunk.css" />),
|
156
|
+
(application_stylesheet_chunks).map { |chunk| stylesheet_link_tag(chunk, media: "all") }.join("\n"),
|
143
157
|
stylesheet_pack_tag("application", media: "all")
|
144
158
|
end
|
145
159
|
end
|
data/test/manifest_test.rb
CHANGED
@@ -26,11 +26,19 @@ class ManifestTest < Minitest::Test
|
|
26
26
|
end
|
27
27
|
|
28
28
|
def test_lookup_with_chunks_without_extension_success!
|
29
|
-
assert_equal Webpacker.manifest.lookup_pack_with_chunks!("bootstrap", type: :javascript)
|
29
|
+
assert_equal ["/packs/bootstrap-300631c4f0e0f9c865bc.js"], Webpacker.manifest.lookup_pack_with_chunks!("bootstrap", type: :javascript)
|
30
30
|
end
|
31
31
|
|
32
32
|
def test_lookup_with_chunks_with_extension_success!
|
33
|
-
assert_equal Webpacker.manifest.lookup_pack_with_chunks!("bootstrap.js", type: :javascript)
|
33
|
+
assert_equal ["/packs/bootstrap-300631c4f0e0f9c865bc.js"], Webpacker.manifest.lookup_pack_with_chunks!("bootstrap.js", type: :javascript)
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_lookup_with_chunks_without_extension_subdir_success!
|
37
|
+
assert_equal ["/packs/print/application-983b6c164a47f7ed49cd.css"], Webpacker.manifest.lookup_pack_with_chunks!("print/application", type: :css)
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_lookup_with_chunks_with_extension_subdir_success!
|
41
|
+
assert_equal ["/packs/print/application-983b6c164a47f7ed49cd.css"], Webpacker.manifest.lookup_pack_with_chunks!("print/application.css", type: :css)
|
34
42
|
end
|
35
43
|
|
36
44
|
def test_lookup_nil
|
@@ -0,0 +1 @@
|
|
1
|
+
$test_app_autoload_paths_in_initializer = ActiveSupport::Dependencies.autoload_paths
|
@@ -5,7 +5,7 @@ default: &default
|
|
5
5
|
source_entry_path: entrypoints
|
6
6
|
public_root_path: public
|
7
7
|
public_output_path: packs
|
8
|
-
cache_path: tmp/
|
8
|
+
cache_path: tmp/webpacker
|
9
9
|
webpack_compile_output: false
|
10
10
|
|
11
11
|
# Additional paths webpack should look up modules
|
@@ -43,8 +43,6 @@ development:
|
|
43
43
|
port: 3035
|
44
44
|
public: localhost:3035
|
45
45
|
hmr: false
|
46
|
-
# Inline should be set to true if using HMR
|
47
|
-
inline: true
|
48
46
|
overlay: true
|
49
47
|
disable_host_check: true
|
50
48
|
use_local_ip: false
|
@@ -0,0 +1,79 @@
|
|
1
|
+
# Note: You must restart bin/webpack-dev-server for changes to take effect
|
2
|
+
|
3
|
+
default: &default
|
4
|
+
source_path: app/packs
|
5
|
+
source_entry_path: entrypoints
|
6
|
+
public_root_path: public
|
7
|
+
public_output_path: packs
|
8
|
+
cache_path: tmp/cache/webpacker
|
9
|
+
webpack_compile_output: false
|
10
|
+
|
11
|
+
# Additional paths webpack should look up modules
|
12
|
+
# ['app/assets', 'engine/foo/app/assets']
|
13
|
+
additional_paths:
|
14
|
+
- app/assets
|
15
|
+
- /etc/yarn
|
16
|
+
- some.config.js
|
17
|
+
- app/elm
|
18
|
+
|
19
|
+
# Reload manifest.json on all requests so we reload latest compiled packs
|
20
|
+
cache_manifest: false
|
21
|
+
|
22
|
+
static_assets_extensions:
|
23
|
+
- .jpg
|
24
|
+
- .jpeg
|
25
|
+
- .png
|
26
|
+
- .gif
|
27
|
+
- .tiff
|
28
|
+
- .ico
|
29
|
+
- .svg
|
30
|
+
|
31
|
+
extensions:
|
32
|
+
- .mjs
|
33
|
+
- .js
|
34
|
+
|
35
|
+
development:
|
36
|
+
<<: *default
|
37
|
+
compile: true
|
38
|
+
|
39
|
+
# Reference: https://webpack.js.org/configuration/dev-server/
|
40
|
+
dev_server:
|
41
|
+
https: false
|
42
|
+
host: localhost
|
43
|
+
port: 3035
|
44
|
+
public: localhost:3035
|
45
|
+
hmr: false
|
46
|
+
# Inline should be set to true if using HMR
|
47
|
+
inline: true
|
48
|
+
overlay: true
|
49
|
+
disable_host_check: true
|
50
|
+
use_local_ip: false
|
51
|
+
pretty: false
|
52
|
+
|
53
|
+
test:
|
54
|
+
<<: *default
|
55
|
+
compile: true
|
56
|
+
|
57
|
+
# Compile test packs to a separate directory
|
58
|
+
public_output_path: packs-test
|
59
|
+
|
60
|
+
production:
|
61
|
+
<<: *default
|
62
|
+
|
63
|
+
# Production depends on precompilation of packs prior to booting for performance.
|
64
|
+
compile: false
|
65
|
+
|
66
|
+
# Cache manifest.json for performance
|
67
|
+
cache_manifest: true
|
68
|
+
|
69
|
+
staging:
|
70
|
+
<<: *default
|
71
|
+
|
72
|
+
# Production depends on precompilation of packs prior to booting for performance.
|
73
|
+
compile: false
|
74
|
+
|
75
|
+
# Cache manifest.json for performance
|
76
|
+
cache_manifest: true
|
77
|
+
|
78
|
+
# Compile staging packs to a separate directory
|
79
|
+
public_output_path: packs-staging
|