jetpacker 0.1.0 → 0.2.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/.eslintignore +4 -0
- data/.eslintrc.js +14 -0
- data/.gitignore +11 -11
- data/.node-version +1 -0
- data/.rubocop.yml +125 -0
- data/.travis.yml +54 -5
- data/CHANGELOG.jetpacker.md +7 -0
- data/CHANGELOG.md +1000 -0
- data/CONTRIBUTING.md +33 -0
- data/Gemfile +9 -3
- data/Gemfile.lock +157 -21
- data/MIT-LICENSE +20 -0
- data/README.md +671 -16
- data/Rakefile +8 -3
- data/docs/assets.md +119 -0
- data/docs/cloud9.md +310 -0
- data/docs/css.md +253 -0
- data/docs/deployment.md +130 -0
- data/docs/docker.md +68 -0
- data/docs/engines.md +200 -0
- data/docs/env.md +65 -0
- data/docs/es6.md +72 -0
- data/docs/folder-structure.md +66 -0
- data/docs/misc.md +23 -0
- data/docs/props.md +223 -0
- data/docs/testing.md +137 -0
- data/docs/troubleshooting.md +156 -0
- data/docs/typescript.md +126 -0
- data/docs/v4-upgrade.md +142 -0
- data/docs/webpack-dev-server.md +92 -0
- data/docs/webpack.md +364 -0
- data/docs/yarn.md +23 -0
- data/gemfiles/Gemfile-rails-edge +12 -0
- data/gemfiles/Gemfile-rails.4.2.x +9 -0
- data/gemfiles/Gemfile-rails.5.0.x +9 -0
- data/gemfiles/Gemfile-rails.5.1.x +9 -0
- data/gemfiles/Gemfile-rails.5.2.x +9 -0
- data/gemfiles/Gemfile-rails.6.0.x +9 -0
- data/jetpacker.gemspec +28 -22
- data/lib/install/angular.rb +23 -0
- data/lib/install/bin/webpack +18 -0
- data/lib/install/bin/webpack-dev-server +18 -0
- data/lib/install/binstubs.rb +4 -0
- data/lib/install/coffee.rb +25 -0
- data/lib/install/config/.browserslistrc +1 -0
- data/lib/install/config/babel.config.js +72 -0
- data/lib/install/config/postcss.config.js +12 -0
- data/lib/install/config/webpack/development.js +5 -0
- data/lib/install/config/webpack/environment.js +3 -0
- data/lib/install/config/webpack/production.js +5 -0
- data/lib/install/config/webpack/test.js +5 -0
- data/lib/install/config/webpacker.yml +96 -0
- data/lib/install/elm.rb +39 -0
- data/lib/install/erb.rb +25 -0
- data/lib/install/examples/angular/hello_angular.js +7 -0
- data/lib/install/examples/angular/hello_angular/app/app.component.ts +9 -0
- data/lib/install/examples/angular/hello_angular/app/app.module.ts +16 -0
- data/lib/install/examples/angular/hello_angular/index.ts +8 -0
- data/lib/install/examples/angular/hello_angular/polyfills.ts +73 -0
- data/lib/install/examples/coffee/hello_coffee.coffee +4 -0
- data/lib/install/examples/elm/Main.elm +55 -0
- data/lib/install/examples/elm/hello_elm.js +16 -0
- data/lib/install/examples/erb/hello_erb.js.erb +6 -0
- data/lib/install/examples/react/babel.config.js +87 -0
- data/lib/install/examples/react/hello_react.jsx +26 -0
- data/lib/install/examples/react/tsconfig.json +20 -0
- data/lib/install/examples/stimulus/application.js +1 -0
- data/lib/install/examples/stimulus/controllers/hello_controller.js +18 -0
- data/lib/install/examples/stimulus/controllers/index.js +9 -0
- data/lib/install/examples/svelte/app.svelte +11 -0
- data/lib/install/examples/svelte/hello_svelte.js +20 -0
- data/lib/install/examples/typescript/hello_typescript.ts +4 -0
- data/lib/install/examples/typescript/tsconfig.json +23 -0
- data/lib/install/examples/vue/app.vue +22 -0
- data/lib/install/examples/vue/hello_vue.js +72 -0
- data/lib/install/javascript/packs/application.js +18 -0
- data/lib/install/loaders/coffee.js +6 -0
- data/lib/install/loaders/elm.js +25 -0
- data/lib/install/loaders/erb.js +11 -0
- data/lib/install/loaders/svelte.js +9 -0
- data/lib/install/loaders/typescript.js +11 -0
- data/lib/install/loaders/vue.js +6 -0
- data/lib/install/react.rb +18 -0
- data/lib/install/stimulus.rb +12 -0
- data/lib/install/svelte.rb +29 -0
- data/lib/install/template.rb +55 -0
- data/lib/install/typescript.rb +46 -0
- data/lib/install/vue.rb +49 -0
- data/lib/jetpacker/version.rb +2 -1
- data/lib/tasks/installers.rake +37 -0
- data/lib/tasks/webpacker.rake +28 -0
- data/lib/tasks/webpacker/binstubs.rake +11 -0
- data/lib/tasks/webpacker/check_binstubs.rake +12 -0
- data/lib/tasks/webpacker/check_node.rake +24 -0
- data/lib/tasks/webpacker/check_yarn.rake +24 -0
- data/lib/tasks/webpacker/clean.rake +21 -0
- data/lib/tasks/webpacker/clobber.rake +16 -0
- data/lib/tasks/webpacker/compile.rake +43 -0
- data/lib/tasks/webpacker/info.rake +20 -0
- data/lib/tasks/webpacker/install.rake +13 -0
- data/lib/tasks/webpacker/verify_install.rake +13 -0
- data/lib/tasks/webpacker/yarn_install.rake +21 -0
- data/lib/webpacker.rb +46 -0
- data/lib/webpacker/commands.rb +50 -0
- data/lib/webpacker/compiler.rb +107 -0
- data/lib/webpacker/configuration.rb +113 -0
- data/lib/webpacker/dev_server.rb +66 -0
- data/lib/webpacker/dev_server_proxy.rb +31 -0
- data/lib/webpacker/dev_server_runner.rb +72 -0
- data/lib/webpacker/env.rb +39 -0
- data/lib/webpacker/helper.rb +176 -0
- data/lib/webpacker/instance.rb +37 -0
- data/lib/webpacker/manifest.rb +118 -0
- data/lib/webpacker/railtie.rb +98 -0
- data/lib/webpacker/rake_tasks.rb +6 -0
- data/lib/webpacker/runner.rb +22 -0
- data/lib/webpacker/version.rb +4 -0
- data/lib/webpacker/webpack_runner.rb +32 -0
- data/package.json +82 -0
- data/package/__tests__/config.js +55 -0
- data/package/__tests__/dev_server.js +43 -0
- data/package/__tests__/development.js +30 -0
- data/package/__tests__/env.js +46 -0
- data/package/__tests__/production.js +29 -0
- data/package/__tests__/staging.js +29 -0
- data/package/__tests__/test.js +26 -0
- data/package/config.js +37 -0
- data/package/config_types/__tests__/config_list.js +118 -0
- data/package/config_types/__tests__/config_object.js +43 -0
- data/package/config_types/config_list.js +75 -0
- data/package/config_types/config_object.js +55 -0
- data/package/config_types/index.js +7 -0
- data/package/dev_server.js +20 -0
- data/package/env.js +19 -0
- data/package/environments/__tests__/base.js +74 -0
- data/package/environments/base.js +166 -0
- data/package/environments/development.js +51 -0
- data/package/environments/production.js +79 -0
- data/package/environments/test.js +3 -0
- data/package/index.js +24 -0
- data/package/rules/babel.js +21 -0
- data/package/rules/css.js +3 -0
- data/package/rules/file.js +20 -0
- data/package/rules/index.js +20 -0
- data/package/rules/module.css.js +3 -0
- data/package/rules/module.sass.js +8 -0
- data/package/rules/node_modules.js +24 -0
- data/package/rules/sass.js +8 -0
- data/package/utils/__tests__/deep_assign.js +32 -0
- data/package/utils/__tests__/deep_merge.js +10 -0
- data/package/utils/__tests__/get_style_rule.js +65 -0
- data/package/utils/__tests__/objectify.js +9 -0
- data/package/utils/deep_assign.js +22 -0
- data/package/utils/deep_merge.js +22 -0
- data/package/utils/get_style_rule.js +45 -0
- data/package/utils/helpers.js +58 -0
- data/package/utils/objectify.js +3 -0
- data/test/command_test.rb +33 -0
- data/test/compiler_test.rb +75 -0
- data/test/configuration_test.rb +108 -0
- data/test/dev_server_runner_test.rb +51 -0
- data/test/dev_server_test.rb +47 -0
- data/test/env_test.rb +23 -0
- data/test/helper_test.rb +142 -0
- data/test/manifest_test.rb +42 -0
- data/test/rake_tasks_test.rb +69 -0
- data/test/test_app/Rakefile +3 -0
- data/test/test_app/app/javascript/packs/application.js +10 -0
- data/test/test_app/bin/webpack +14 -0
- data/test/test_app/bin/webpack-dev-server +14 -0
- data/test/test_app/config.ru +5 -0
- data/test/test_app/config/application.rb +12 -0
- data/test/test_app/config/environment.rb +4 -0
- data/test/test_app/config/webpack/development.js +0 -0
- data/test/test_app/config/webpacker.yml +97 -0
- data/test/test_app/config/webpacker_public_root.yml +19 -0
- data/test/test_app/package.json +13 -0
- data/test/test_app/public/packs/manifest.json +31 -0
- data/test/test_app/yarn.lock +11 -0
- data/test/test_helper.rb +33 -0
- data/test/webpack_runner_test.rb +51 -0
- data/test/webpacker_test.rb +13 -0
- data/yarn.lock +8321 -0
- metadata +267 -29
- data/.rspec +0 -3
- data/LICENSE.txt +0 -21
- data/bin/console +0 -14
- data/bin/setup +0 -8
- data/lib/jetpacker.rb +0 -6
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
require "test_helper"
|
|
2
|
+
require "webpacker/dev_server_runner"
|
|
3
|
+
|
|
4
|
+
class DevServerRunnerTest < Webpacker::Test
|
|
5
|
+
def setup
|
|
6
|
+
@original_node_env, ENV["NODE_ENV"] = ENV["NODE_ENV"], "development"
|
|
7
|
+
@original_rails_env, ENV["RAILS_ENV"] = ENV["RAILS_ENV"], "development"
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def teardown
|
|
11
|
+
ENV["NODE_ENV"] = @original_node_env
|
|
12
|
+
ENV["RAILS_ENV"] = @original_rails_env
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def test_run_cmd_via_node_modules
|
|
16
|
+
cmd = ["#{test_app_path}/node_modules/.bin/webpack-dev-server", "--config", "#{test_app_path}/config/webpack/development.js"]
|
|
17
|
+
|
|
18
|
+
verify_command(cmd, use_node_modules: true)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def test_run_cmd_via_yarn
|
|
22
|
+
cmd = ["yarn", "webpack-dev-server", "--config", "#{test_app_path}/config/webpack/development.js"]
|
|
23
|
+
|
|
24
|
+
verify_command(cmd, use_node_modules: false)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
private
|
|
28
|
+
def test_app_path
|
|
29
|
+
File.expand_path("test_app", __dir__)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def verify_command(cmd, use_node_modules: true)
|
|
33
|
+
cwd = Dir.pwd
|
|
34
|
+
Dir.chdir(test_app_path)
|
|
35
|
+
|
|
36
|
+
klass = Webpacker::DevServerRunner
|
|
37
|
+
instance = klass.new([])
|
|
38
|
+
mock = Minitest::Mock.new
|
|
39
|
+
mock.expect(:call, nil, [{}, *cmd])
|
|
40
|
+
|
|
41
|
+
klass.stub(:new, instance) do
|
|
42
|
+
instance.stub(:node_modules_bin_exist?, use_node_modules) do
|
|
43
|
+
Kernel.stub(:exec, mock) { klass.run([]) }
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
mock.verify
|
|
48
|
+
ensure
|
|
49
|
+
Dir.chdir(cwd)
|
|
50
|
+
end
|
|
51
|
+
end
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
require "test_helper"
|
|
2
|
+
|
|
3
|
+
class DevServerTest < Webpacker::Test
|
|
4
|
+
def test_running?
|
|
5
|
+
refute Webpacker.dev_server.running?
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def test_host
|
|
9
|
+
with_rails_env("development") do
|
|
10
|
+
assert_equal Webpacker.dev_server.host, "localhost"
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def test_port
|
|
15
|
+
with_rails_env("development") do
|
|
16
|
+
assert_equal Webpacker.dev_server.port, 3035
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def test_https?
|
|
21
|
+
with_rails_env("development") do
|
|
22
|
+
assert_equal Webpacker.dev_server.https?, false
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def test_protocol
|
|
27
|
+
with_rails_env("development") do
|
|
28
|
+
assert_equal Webpacker.dev_server.protocol, "http"
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def test_host_with_port
|
|
33
|
+
with_rails_env("development") do
|
|
34
|
+
assert_equal Webpacker.dev_server.host_with_port, "localhost:3035"
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def test_pretty?
|
|
39
|
+
with_rails_env("development") do
|
|
40
|
+
refute Webpacker.dev_server.pretty?
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def test_default_env_prefix
|
|
45
|
+
assert_equal Webpacker::DevServer::DEFAULT_ENV_PREFIX, "WEBPACKER_DEV_SERVER"
|
|
46
|
+
end
|
|
47
|
+
end
|
data/test/env_test.rb
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
require "test_helper"
|
|
2
|
+
|
|
3
|
+
class EnvTest < Webpacker::Test
|
|
4
|
+
def test_current
|
|
5
|
+
assert_equal Webpacker.env, Rails.env
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def test_custom_without_config
|
|
9
|
+
with_rails_env("foo") do
|
|
10
|
+
assert_equal Webpacker.env, "production"
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def test_custom_with_config
|
|
15
|
+
with_rails_env("staging") do
|
|
16
|
+
assert_equal Webpacker.env, "staging"
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def test_default
|
|
21
|
+
assert_equal Webpacker::Env::DEFAULT, "production"
|
|
22
|
+
end
|
|
23
|
+
end
|
data/test/helper_test.rb
ADDED
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
require "test_helper"
|
|
2
|
+
|
|
3
|
+
class HelperTest < ActionView::TestCase
|
|
4
|
+
tests Webpacker::Helper
|
|
5
|
+
|
|
6
|
+
attr_reader :request
|
|
7
|
+
|
|
8
|
+
def setup
|
|
9
|
+
@request = Class.new do
|
|
10
|
+
def send_early_hints(links) end
|
|
11
|
+
def base_url
|
|
12
|
+
"https://example.com"
|
|
13
|
+
end
|
|
14
|
+
end.new
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def test_asset_pack_path
|
|
18
|
+
assert_equal "/packs/bootstrap-300631c4f0e0f9c865bc.js", asset_pack_path("bootstrap.js")
|
|
19
|
+
assert_equal "/packs/bootstrap-c38deda30895059837cf.css", asset_pack_path("bootstrap.css")
|
|
20
|
+
|
|
21
|
+
Webpacker.config.stub :extract_css?, false do
|
|
22
|
+
assert_nil asset_pack_path("bootstrap.css")
|
|
23
|
+
assert_equal "/packs/application-k344a6d59eef8632c9d1.png", asset_pack_path("application.png")
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def test_asset_pack_url
|
|
28
|
+
assert_equal "https://example.com/packs/bootstrap-300631c4f0e0f9c865bc.js", asset_pack_url("bootstrap.js")
|
|
29
|
+
assert_equal "https://example.com/packs/bootstrap-c38deda30895059837cf.css", asset_pack_url("bootstrap.css")
|
|
30
|
+
|
|
31
|
+
Webpacker.config.stub :extract_css?, false do
|
|
32
|
+
assert_nil asset_pack_path("bootstrap.css")
|
|
33
|
+
assert_equal "https://example.com/packs/application-k344a6d59eef8632c9d1.png", asset_pack_url("application.png")
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def test_image_pack_tag
|
|
38
|
+
assert_equal \
|
|
39
|
+
"<img alt=\"Edit Entry\" src=\"/packs/application-k344a6d59eef8632c9d1.png\" width=\"16\" height=\"10\" />",
|
|
40
|
+
image_pack_tag("application.png", size: "16x10", alt: "Edit Entry")
|
|
41
|
+
assert_equal \
|
|
42
|
+
"<img alt=\"Edit Entry\" src=\"/packs/media/images/image-c38deda30895059837cf.jpg\" width=\"16\" height=\"10\" />",
|
|
43
|
+
image_pack_tag("image.jpg", size: "16x10", alt: "Edit Entry")
|
|
44
|
+
assert_equal \
|
|
45
|
+
"<img alt=\"Edit Entry\" src=\"/packs/media/images/image-c38deda30895059837cf.jpg\" width=\"16\" height=\"10\" />",
|
|
46
|
+
image_pack_tag("media/images/image.jpg", size: "16x10", alt: "Edit Entry")
|
|
47
|
+
assert_equal \
|
|
48
|
+
"<img alt=\"Edit Entry\" src=\"/packs/media/images/nested/image-c38deda30895059837cf.jpg\" width=\"16\" height=\"10\" />",
|
|
49
|
+
image_pack_tag("nested/image.jpg", size: "16x10", alt: "Edit Entry")
|
|
50
|
+
assert_equal \
|
|
51
|
+
"<img alt=\"Edit Entry\" src=\"/packs/media/images/nested/image-c38deda30895059837cf.jpg\" width=\"16\" height=\"10\" />",
|
|
52
|
+
image_pack_tag("media/images/nested/image.jpg", size: "16x10", alt: "Edit Entry")
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def test_favicon_pack_tag
|
|
56
|
+
assert_equal \
|
|
57
|
+
"<link rel=\"apple-touch-icon\" type=\"image/png\" href=\"/packs/application-k344a6d59eef8632c9d1.png\" />",
|
|
58
|
+
favicon_pack_tag("application.png", rel: "apple-touch-icon", type: "image/png")
|
|
59
|
+
assert_equal \
|
|
60
|
+
"<link rel=\"apple-touch-icon\" type=\"image/png\" href=\"/packs/media/images/mb-icon-c38deda30895059837cf.png\" />",
|
|
61
|
+
favicon_pack_tag("mb-icon.png", rel: "apple-touch-icon", type: "image/png")
|
|
62
|
+
assert_equal \
|
|
63
|
+
"<link rel=\"apple-touch-icon\" type=\"image/png\" href=\"/packs/media/images/mb-icon-c38deda30895059837cf.png\" />",
|
|
64
|
+
favicon_pack_tag("media/images/mb-icon.png", rel: "apple-touch-icon", type: "image/png")
|
|
65
|
+
assert_equal \
|
|
66
|
+
"<link rel=\"apple-touch-icon\" type=\"image/png\" href=\"/packs/media/images/nested/mb-icon-c38deda30895059837cf.png\" />",
|
|
67
|
+
favicon_pack_tag("nested/mb-icon.png", rel: "apple-touch-icon", type: "image/png")
|
|
68
|
+
assert_equal \
|
|
69
|
+
"<link rel=\"apple-touch-icon\" type=\"image/png\" href=\"/packs/media/images/nested/mb-icon-c38deda30895059837cf.png\" />",
|
|
70
|
+
favicon_pack_tag("media/images/nested/mb-icon.png", rel: "apple-touch-icon", type: "image/png")
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def test_javascript_pack_tag
|
|
74
|
+
assert_equal \
|
|
75
|
+
%(<script src="/packs/bootstrap-300631c4f0e0f9c865bc.js"></script>),
|
|
76
|
+
javascript_pack_tag("bootstrap.js")
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
def test_javascript_pack_tag_symbol
|
|
80
|
+
assert_equal \
|
|
81
|
+
%(<script src="/packs/bootstrap-300631c4f0e0f9c865bc.js"></script>),
|
|
82
|
+
javascript_pack_tag(:bootstrap)
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
def test_javascript_pack_tag_splat
|
|
86
|
+
assert_equal \
|
|
87
|
+
%(<script src="/packs/bootstrap-300631c4f0e0f9c865bc.js" defer="defer"></script>\n) +
|
|
88
|
+
%(<script src="/packs/application-k344a6d59eef8632c9d1.js" defer="defer"></script>),
|
|
89
|
+
javascript_pack_tag("bootstrap.js", "application.js", defer: true)
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
def test_javascript_pack_tag_split_chunks
|
|
93
|
+
assert_equal \
|
|
94
|
+
%(<script src="/packs/vendors~application~bootstrap-c20632e7baf2c81200d3.chunk.js"></script>\n) +
|
|
95
|
+
%(<script src="/packs/vendors~application-e55f2aae30c07fb6d82a.chunk.js"></script>\n) +
|
|
96
|
+
%(<script src="/packs/application-k344a6d59eef8632c9d1.js"></script>),
|
|
97
|
+
javascript_packs_with_chunks_tag("application")
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
def test_preload_pack_asset
|
|
101
|
+
if self.class.method_defined?(:preload_link_tag)
|
|
102
|
+
assert_equal \
|
|
103
|
+
%(<link rel="preload" href="/packs/fonts/fa-regular-400-944fb546bd7018b07190a32244f67dc9.woff2" as="font" type="font/woff2" crossorigin="anonymous">),
|
|
104
|
+
preload_pack_asset("fonts/fa-regular-400.woff2")
|
|
105
|
+
else
|
|
106
|
+
error = assert_raises do
|
|
107
|
+
preload_pack_asset("fonts/fa-regular-400.woff2")
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
assert_equal \
|
|
111
|
+
"You need Rails >= 5.2 to use this tag.",
|
|
112
|
+
error.message
|
|
113
|
+
end
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
def test_stylesheet_pack_tag_split_chunks
|
|
117
|
+
assert_equal \
|
|
118
|
+
%(<link rel="stylesheet" media="screen" href="/packs/1-c20632e7baf2c81200d3.chunk.css" />\n) +
|
|
119
|
+
%(<link rel="stylesheet" media="screen" href="/packs/application-k344a6d59eef8632c9d1.chunk.css" />\n) +
|
|
120
|
+
%(<link rel="stylesheet" media="screen" href="/packs/hello_stimulus-k344a6d59eef8632c9d1.chunk.css" />),
|
|
121
|
+
stylesheet_packs_with_chunks_tag("application", "hello_stimulus")
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
def test_stylesheet_pack_tag
|
|
125
|
+
assert_equal \
|
|
126
|
+
%(<link rel="stylesheet" media="screen" href="/packs/bootstrap-c38deda30895059837cf.css" />),
|
|
127
|
+
stylesheet_pack_tag("bootstrap.css")
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
def test_stylesheet_pack_tag_symbol
|
|
131
|
+
assert_equal \
|
|
132
|
+
%(<link rel="stylesheet" media="screen" href="/packs/bootstrap-c38deda30895059837cf.css" />),
|
|
133
|
+
stylesheet_pack_tag(:bootstrap)
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
def test_stylesheet_pack_tag_splat
|
|
137
|
+
assert_equal \
|
|
138
|
+
%(<link rel="stylesheet" media="all" href="/packs/bootstrap-c38deda30895059837cf.css" />\n) +
|
|
139
|
+
%(<link rel="stylesheet" media="all" href="/packs/application-dd6b1cd38bfa093df600.css" />),
|
|
140
|
+
stylesheet_pack_tag("bootstrap.css", "application.css", media: "all")
|
|
141
|
+
end
|
|
142
|
+
end
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
require "test_helper"
|
|
2
|
+
|
|
3
|
+
class ManifestTest < Minitest::Test
|
|
4
|
+
def test_lookup_exception!
|
|
5
|
+
manifest_path = File.expand_path File.join(File.dirname(__FILE__), "test_app/public/packs", "manifest.json").to_s
|
|
6
|
+
asset_file = "calendar.js"
|
|
7
|
+
|
|
8
|
+
Webpacker.config.stub :compile?, false do
|
|
9
|
+
error = assert_raises Webpacker::Manifest::MissingEntryError do
|
|
10
|
+
Webpacker.manifest.lookup!(asset_file)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
assert_match "Webpacker can't find #{asset_file} in #{manifest_path}", error.message
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def test_lookup_success!
|
|
18
|
+
assert_equal Webpacker.manifest.lookup!("bootstrap.js"), "/packs/bootstrap-300631c4f0e0f9c865bc.js"
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def test_lookup_nil
|
|
22
|
+
assert_nil Webpacker.manifest.lookup("foo.js")
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def test_lookup_chunks_nil
|
|
26
|
+
assert_nil Webpacker.manifest.lookup_pack_with_chunks("foo.js")
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def test_lookup_success
|
|
30
|
+
assert_equal Webpacker.manifest.lookup("bootstrap.js"), "/packs/bootstrap-300631c4f0e0f9c865bc.js"
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def test_lookup_entrypoint
|
|
34
|
+
application_entrypoints = [
|
|
35
|
+
"/packs/vendors~application~bootstrap-c20632e7baf2c81200d3.chunk.js",
|
|
36
|
+
"/packs/vendors~application-e55f2aae30c07fb6d82a.chunk.js",
|
|
37
|
+
"/packs/application-k344a6d59eef8632c9d1.js"
|
|
38
|
+
]
|
|
39
|
+
|
|
40
|
+
assert_equal Webpacker.manifest.lookup_pack_with_chunks!("application", type: :javascript), application_entrypoints
|
|
41
|
+
end
|
|
42
|
+
end
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
require "test_helper"
|
|
2
|
+
|
|
3
|
+
class RakeTasksTest < Minitest::Test
|
|
4
|
+
def test_rake_tasks
|
|
5
|
+
output = Dir.chdir(test_app_path) { `rake -T` }
|
|
6
|
+
assert_includes output, "webpacker"
|
|
7
|
+
assert_includes output, "webpacker:check_binstubs"
|
|
8
|
+
assert_includes output, "webpacker:check_node"
|
|
9
|
+
assert_includes output, "webpacker:check_yarn"
|
|
10
|
+
assert_includes output, "webpacker:clean"
|
|
11
|
+
assert_includes output, "webpacker:clobber"
|
|
12
|
+
assert_includes output, "webpacker:compile"
|
|
13
|
+
assert_includes output, "webpacker:install"
|
|
14
|
+
assert_includes output, "webpacker:install:angular"
|
|
15
|
+
assert_includes output, "webpacker:install:coffee"
|
|
16
|
+
assert_includes output, "webpacker:install:elm"
|
|
17
|
+
assert_includes output, "webpacker:install:erb"
|
|
18
|
+
assert_includes output, "webpacker:install:react"
|
|
19
|
+
assert_includes output, "webpacker:install:svelte"
|
|
20
|
+
assert_includes output, "webpacker:install:stimulus"
|
|
21
|
+
assert_includes output, "webpacker:install:typescript"
|
|
22
|
+
assert_includes output, "webpacker:install:vue"
|
|
23
|
+
assert_includes output, "webpacker:verify_install"
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def test_rake_task_webpacker_check_binstubs
|
|
27
|
+
output = Dir.chdir(test_app_path) { `rake webpacker:check_binstubs 2>&1` }
|
|
28
|
+
refute_includes output, "webpack binstubs not found."
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def test_rake_webpacker_yarn_install_in_non_production_environments
|
|
32
|
+
assert_includes test_app_dev_dependencies, "right-pad"
|
|
33
|
+
|
|
34
|
+
Webpacker.with_node_env("test") do
|
|
35
|
+
Dir.chdir(test_app_path) do
|
|
36
|
+
`bundle exec rake webpacker:yarn_install`
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
assert_includes installed_node_module_names, "right-pad",
|
|
41
|
+
"Expected dev dependencies to be installed"
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def test_rake_webpacker_yarn_install_in_production_environment
|
|
45
|
+
Webpacker.with_node_env("production") do
|
|
46
|
+
Dir.chdir(test_app_path) do
|
|
47
|
+
`bundle exec rake webpacker:yarn_install`
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
refute_includes installed_node_module_names, "right-pad",
|
|
52
|
+
"Expected only production dependencies to be installed"
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
private
|
|
56
|
+
def test_app_path
|
|
57
|
+
File.expand_path("test_app", __dir__)
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def test_app_dev_dependencies
|
|
61
|
+
package_json = File.expand_path("package.json", test_app_path)
|
|
62
|
+
JSON.parse(File.read(package_json))["devDependencies"]
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def installed_node_module_names
|
|
66
|
+
node_modules_path = File.expand_path("node_modules", test_app_path)
|
|
67
|
+
Dir.chdir(node_modules_path) { Dir.glob("*") }
|
|
68
|
+
end
|
|
69
|
+
end
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/* eslint no-console:0 */
|
|
2
|
+
// This file is automatically compiled by Webpack, along with any other files
|
|
3
|
+
// present in this directory. You're encouraged to place your actual application logic in
|
|
4
|
+
// a relevant structure within app/javascript and only use these pack files to reference
|
|
5
|
+
// that code so it'll be compiled.
|
|
6
|
+
//
|
|
7
|
+
// To reference this file, add <%= javascript_pack_tag 'application' %> to the appropriate
|
|
8
|
+
// layout file, like app/views/layouts/application.html.erb
|
|
9
|
+
|
|
10
|
+
console.log('Hello World from Webpacker')
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
ENV["RAILS_ENV"] ||= ENV["RACK_ENV"] || "development"
|
|
4
|
+
ENV["NODE_ENV"] ||= ENV["RAILS_ENV"]
|
|
5
|
+
|
|
6
|
+
require "pathname"
|
|
7
|
+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
|
|
8
|
+
Pathname.new(__FILE__).realpath)
|
|
9
|
+
|
|
10
|
+
require "bundler/setup"
|
|
11
|
+
|
|
12
|
+
require "webpacker"
|
|
13
|
+
require "webpacker/webpack_runner"
|
|
14
|
+
Webpacker::WebpackRunner.run(ARGV)
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
ENV["RAILS_ENV"] ||= ENV["RACK_ENV"] || "development"
|
|
4
|
+
ENV["NODE_ENV"] ||= ENV["RAILS_ENV"]
|
|
5
|
+
|
|
6
|
+
require "pathname"
|
|
7
|
+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
|
|
8
|
+
Pathname.new(__FILE__).realpath)
|
|
9
|
+
|
|
10
|
+
require "bundler/setup"
|
|
11
|
+
|
|
12
|
+
require "webpacker"
|
|
13
|
+
require "webpacker/dev_server_runner"
|
|
14
|
+
Webpacker::DevServerRunner.run(ARGV)
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
require "action_controller/railtie"
|
|
2
|
+
require "action_view/railtie"
|
|
3
|
+
require "webpacker"
|
|
4
|
+
|
|
5
|
+
module TestApp
|
|
6
|
+
class Application < ::Rails::Application
|
|
7
|
+
config.secret_key_base = "abcdef"
|
|
8
|
+
config.eager_load = true
|
|
9
|
+
config.webpacker.check_yarn_integrity = false
|
|
10
|
+
config.active_support.test_order = :sorted
|
|
11
|
+
end
|
|
12
|
+
end
|