shakapacker 7.0.0.rc.0 → 7.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/PULL_REQUEST_TEMPLATE.md +4 -8
- data/.github/workflows/dummy.yml +21 -0
- data/.github/workflows/generator.yml +37 -0
- data/.github/workflows/jest.yml +2 -2
- data/.github/workflows/js-lint.yml +2 -2
- data/.github/workflows/rubocop.yml +1 -1
- data/.github/workflows/ruby-backward-compatibility.yml +2 -6
- data/.github/workflows/ruby.yml +2 -6
- data/.gitignore +3 -0
- data/CHANGELOG.md +17 -18
- data/CONTRIBUTING.md +76 -20
- data/README.md +5 -1
- data/Rakefile +44 -8
- data/docs/deployment.md +1 -2
- data/lib/install/binstubs.rb +3 -1
- data/lib/install/config/shakapacker.yml +9 -0
- data/lib/install/config/webpack/webpack.config.js +3 -2
- data/lib/install/template.rb +27 -15
- data/lib/shakapacker/deprecation_helper.rb +4 -5
- data/lib/shakapacker/version.rb +1 -1
- data/lib/tasks/shakapacker/check_binstubs.rake +14 -10
- data/lib/tasks/shakapacker/compile.rake +1 -6
- data/package/__tests__/index-bc.js +22 -0
- data/package/environments/__tests__/base-bc.js +2 -2
- data/package/environments/__tests__/base.js +2 -2
- data/package/environments/__tests__/development.js +53 -0
- data/package/environments/__tests__/production.js +53 -0
- data/package/environments/base.js +4 -3
- data/package/environments/production.js +9 -0
- data/package/index.js +24 -1
- data/package/utils/helpers.js +1 -1
- data/package.json +1 -1
- data/spec/dummy/.browserslistrc +1 -0
- data/spec/dummy/.gitignore +20 -0
- data/spec/dummy/.prettierrc.yaml +4 -0
- data/spec/dummy/Gemfile +63 -0
- data/spec/dummy/Procfile.dev +5 -0
- data/spec/dummy/Procfile.dev-static +9 -0
- data/spec/dummy/README.md +1 -0
- data/spec/dummy/Rakefile +6 -0
- data/spec/dummy/app/assets/config/manifest.js +2 -0
- data/spec/dummy/app/assets/stylesheets/application.css +15 -0
- data/spec/dummy/app/channels/application_cable/channel.rb +4 -0
- data/spec/dummy/app/channels/application_cable/connection.rb +4 -0
- data/spec/dummy/app/controllers/application_controller.rb +2 -0
- data/spec/dummy/app/controllers/hello_world_controller.rb +9 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/javascript/Globals.d.ts +3 -0
- data/spec/dummy/app/javascript/bundles/HelloWorld/components/HelloWorld.module.css +25 -0
- data/spec/dummy/app/javascript/bundles/HelloWorld/components/HelloWorld.tsx +47 -0
- data/spec/dummy/app/javascript/bundles/HelloWorld/components/HelloWorldServer.tsx +5 -0
- data/spec/dummy/app/javascript/bundles/HelloWorld/components/logo.svg +7 -0
- data/spec/dummy/app/javascript/packs/application.js +17 -0
- data/spec/dummy/app/javascript/packs/hello-world-bundle.ts +8 -0
- data/spec/dummy/app/javascript/packs/server-bundle.ts +8 -0
- data/spec/dummy/app/jobs/application_job.rb +7 -0
- data/spec/dummy/app/mailers/application_mailer.rb +4 -0
- data/spec/dummy/app/models/application_record.rb +3 -0
- data/spec/dummy/app/models/concerns/.keep +0 -0
- data/spec/dummy/app/views/hello_world/index.html.erb +2 -0
- data/spec/dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy/app/views/layouts/hello_world.html.erb +13 -0
- data/spec/dummy/app/views/layouts/mailer.html.erb +13 -0
- data/spec/dummy/app/views/layouts/mailer.text.erb +1 -0
- data/spec/dummy/babel.config.js +30 -0
- data/spec/dummy/bin/bundle +114 -0
- data/spec/dummy/bin/dev +30 -0
- data/spec/dummy/bin/dev-static +30 -0
- data/spec/dummy/bin/rails +9 -0
- data/spec/dummy/bin/rake +9 -0
- data/spec/dummy/bin/setup +33 -0
- data/spec/dummy/bin/shakapacker +13 -0
- data/spec/dummy/bin/shakapacker-dev-server +13 -0
- data/spec/dummy/bin/spring +17 -0
- data/spec/dummy/bin/yarn +18 -0
- data/spec/dummy/config/application.rb +32 -0
- data/spec/dummy/config/boot.rb +4 -0
- data/spec/dummy/config/cable.yml +10 -0
- data/spec/dummy/config/credentials.yml.enc +1 -0
- data/spec/dummy/config/database.yml +25 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +54 -0
- data/spec/dummy/config/environments/production.rb +106 -0
- data/spec/dummy/config/environments/test.rb +49 -0
- data/spec/dummy/config/initializers/application_controller_renderer.rb +8 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/content_security_policy.rb +28 -0
- data/spec/dummy/config/initializers/cookies_serializer.rb +5 -0
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/dummy/config/initializers/inflections.rb +16 -0
- data/spec/dummy/config/initializers/mime_types.rb +4 -0
- data/spec/dummy/config/initializers/react_on_rails.rb +58 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/en.yml +33 -0
- data/spec/dummy/config/puma.rb +38 -0
- data/spec/dummy/config/routes.rb +6 -0
- data/spec/dummy/config/shakapacker.yml +62 -0
- data/spec/dummy/config/spring.rb +6 -0
- data/spec/dummy/config/storage.yml +34 -0
- data/spec/dummy/config/webpack/ServerClientOrBoth.js +34 -0
- data/spec/dummy/config/webpack/clientWebpackConfig.js +15 -0
- data/spec/dummy/config/webpack/commonWebpackConfig.js +18 -0
- data/spec/dummy/config/webpack/development.js +32 -0
- data/spec/dummy/config/webpack/production.js +9 -0
- data/spec/dummy/config/webpack/serverWebpackConfig.js +116 -0
- data/spec/dummy/config/webpack/test.js +7 -0
- data/spec/dummy/config/webpack/webpack.config.js +24 -0
- data/spec/dummy/config.ru +5 -0
- data/spec/dummy/db/seeds.rb +7 -0
- data/spec/dummy/lib/assets/.keep +0 -0
- data/spec/dummy/lib/tasks/.keep +0 -0
- data/spec/dummy/package.json +44 -0
- data/spec/dummy/postcss.config.js +12 -0
- data/spec/dummy/public/404.html +67 -0
- data/spec/dummy/public/422.html +67 -0
- data/spec/dummy/public/500.html +66 -0
- data/spec/dummy/public/apple-touch-icon-precomposed.png +0 -0
- data/spec/dummy/public/apple-touch-icon.png +0 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/public/robots.txt +1 -0
- data/spec/dummy/spec/rails_helper.rb +118 -0
- data/spec/dummy/spec/spec_helper.rb +96 -0
- data/spec/dummy/spec/system/hello_world_spec.rb +19 -0
- data/spec/dummy/tsconfig.json +21 -0
- data/spec/dummy/vendor/.keep +0 -0
- data/spec/dummy/yarn.lock +4697 -0
- data/spec/generator_specs/e2e_template/files/app/controllers/home_controller.rb +4 -0
- data/spec/generator_specs/e2e_template/files/app/javascript/components/App.js +12 -0
- data/spec/generator_specs/e2e_template/files/app/javascript/packs/application.js +10 -0
- data/spec/generator_specs/e2e_template/files/app/views/home/index.html.erb +2 -0
- data/spec/generator_specs/e2e_template/files/app/views/layouts/application.html.erb +17 -0
- data/spec/generator_specs/e2e_template/files/config/routes.rb +3 -0
- data/spec/generator_specs/e2e_template/files/spec/system/test_react_component_renders_spec.rb +13 -0
- data/spec/generator_specs/e2e_template/template.rb +21 -0
- data/spec/generator_specs/generator_spec.rb +169 -0
- data/spec/{configuration_spec.rb → shakapacker/configuration_spec.rb} +10 -10
- data/spec/{dev_server_runner_spec.rb → shakapacker/dev_server_runner_spec.rb} +1 -1
- data/spec/{engine_rake_tasks_spec.rb → shakapacker/engine_rake_tasks_spec.rb} +2 -2
- data/spec/{manifest_spec.rb → shakapacker/manifest_spec.rb} +1 -1
- data/spec/shakapacker/rake_tasks_spec.rb +93 -0
- data/spec/{spec_helper_initializer.rb → shakapacker/spec_helper_initializer.rb} +1 -1
- data/spec/shakapacker/test_app/config/webpack/webpack.config.js +0 -0
- data/spec/shakapacker/test_app/some.config.js +0 -0
- data/spec/{version_checker_spec.rb → shakapacker/version_checker_spec.rb} +9 -9
- data/spec/{webpack_runner_spec.rb → shakapacker/webpack_runner_spec.rb} +1 -1
- metadata +173 -64
- data/gemfiles/Gemfile-rails.5.2.x +0 -9
- data/spec/rake_tasks_spec.rb +0 -34
- /data/docs/{developing_webpacker.md → developing_shakapacker.md} +0 -0
- /data/spec/backward_compatibility_specs/{command_spec_bc.rb → command_spec.rb} +0 -0
- /data/spec/backward_compatibility_specs/{compiler_spec_bc.rb → compiler_spec.rb} +0 -0
- /data/spec/backward_compatibility_specs/{compiler_strategy_spec_bc.rb → compiler_strategy_spec.rb} +0 -0
- /data/spec/backward_compatibility_specs/{configuration_spec_bc.rb → configuration_spec.rb} +0 -0
- /data/spec/backward_compatibility_specs/{dev_server_runner_spec_bc.rb → dev_server_runner_spec.rb} +0 -0
- /data/spec/backward_compatibility_specs/{dev_server_spec_bc.rb → dev_server_spec.rb} +0 -0
- /data/spec/backward_compatibility_specs/{digest_strategy_spec_bc.rb → digest_strategy_spec.rb} +0 -0
- /data/spec/backward_compatibility_specs/{engine_rake_tasks_spec_bc.rb → engine_rake_tasks_spec.rb} +0 -0
- /data/spec/backward_compatibility_specs/{env_spec_bc.rb → env_spec.rb} +0 -0
- /data/spec/backward_compatibility_specs/{helper_spec_bc.rb → helper_spec.rb} +0 -0
- /data/spec/backward_compatibility_specs/{instance_spec_bc.rb → instance_spec.rb} +0 -0
- /data/spec/backward_compatibility_specs/{manifest_spec_bc.rb → manifest_spec.rb} +0 -0
- /data/spec/backward_compatibility_specs/{mtime_strategy_spec_bc.rb → mtime_strategy_spec.rb} +0 -0
- /data/spec/backward_compatibility_specs/{rake_tasks_spec_bc.rb → rake_tasks_spec.rb} +0 -0
- /data/spec/backward_compatibility_specs/{webpack_runner_spec_bc.rb → webpack_runner_spec.rb} +0 -0
- /data/spec/backward_compatibility_specs/{webpacker_spec_bc.rb → webpacker_spec.rb} +0 -0
- /data/spec/{test_app/config/webpack/webpack.config.js → dummy/app/assets/images/.keep} +0 -0
- /data/spec/{test_app/some.config.js → dummy/app/controllers/concerns/.keep} +0 -0
- /data/spec/{command_spec.rb → shakapacker/command_spec.rb} +0 -0
- /data/spec/{compiler_spec.rb → shakapacker/compiler_spec.rb} +0 -0
- /data/spec/{compiler_strategy_spec.rb → shakapacker/compiler_strategy_spec.rb} +0 -0
- /data/spec/{dev_server_spec.rb → shakapacker/dev_server_spec.rb} +0 -0
- /data/spec/{digest_strategy_spec.rb → shakapacker/digest_strategy_spec.rb} +0 -0
- /data/spec/{env_spec.rb → shakapacker/env_spec.rb} +0 -0
- /data/spec/{helper_spec.rb → shakapacker/helper_spec.rb} +0 -0
- /data/spec/{instance_spec.rb → shakapacker/instance_spec.rb} +0 -0
- /data/spec/{mtime_strategy_spec.rb → shakapacker/mtime_strategy_spec.rb} +0 -0
- /data/spec/{webpacker_spec.rb → shakapacker/shakapacker_spec.rb} +0 -0
- /data/spec/{test_app → shakapacker/test_app}/.gitignore +0 -0
- /data/spec/{test_app → shakapacker/test_app}/Rakefile +0 -0
- /data/spec/{test_app → shakapacker/test_app}/app/javascript/entrypoints/application.js +0 -0
- /data/spec/{test_app → shakapacker/test_app}/app/javascript/entrypoints/generated/something.js +0 -0
- /data/spec/{test_app → shakapacker/test_app}/app/javascript/entrypoints/multi_entry.css +0 -0
- /data/spec/{test_app → shakapacker/test_app}/app/javascript/entrypoints/multi_entry.js +0 -0
- /data/spec/{test_app → shakapacker/test_app}/bin/shakapacker +0 -0
- /data/spec/{test_app → shakapacker/test_app}/bin/shakapacker-dev-server +0 -0
- /data/spec/{test_app → shakapacker/test_app}/config/application.rb +0 -0
- /data/spec/{test_app → shakapacker/test_app}/config/environment.rb +0 -0
- /data/spec/{test_app → shakapacker/test_app}/config/initializers/inspect_autoload_paths.rb +0 -0
- /data/spec/{test_app → shakapacker/test_app}/config/shakapacker.yml +0 -0
- /data/spec/{test_app → shakapacker/test_app}/config/shakapacker_css_extract_ignore_order_warnings.yml +0 -0
- /data/spec/{test_app → shakapacker/test_app}/config/shakapacker_defaults_fallback.yml +0 -0
- /data/spec/{test_app → shakapacker/test_app}/config/shakapacker_manifest_path.yml +0 -0
- /data/spec/{test_app → shakapacker/test_app}/config/shakapacker_nested_entries.yml +0 -0
- /data/spec/{test_app → shakapacker/test_app}/config/shakapacker_no_precompile.yml +0 -0
- /data/spec/{test_app → shakapacker/test_app}/config/shakapacker_other_location.yml +0 -0
- /data/spec/{test_app → shakapacker/test_app}/config/shakapacker_public_root.yml +0 -0
- /data/spec/{test_app → shakapacker/test_app}/config.ru +0 -0
- /data/spec/{test_app → shakapacker/test_app}/package.json +0 -0
- /data/spec/{test_app → shakapacker/test_app}/public/packs/manifest.json +0 -0
- /data/spec/{test_app → shakapacker/test_app}/yarn.lock +0 -0
@@ -1,3 +1,5 @@
|
|
1
|
+
require "thor"
|
2
|
+
|
1
3
|
module Shakapacker
|
2
4
|
DEPRECATION_GUIDE_URL = "https://github.com/shakacode/shakapacker/docs/v7_upgrade.md"
|
3
5
|
DEPRECATION_MESSAGE = <<~MSG
|
@@ -9,6 +11,7 @@ module Shakapacker
|
|
9
11
|
For more information about this process, check:
|
10
12
|
#{DEPRECATION_GUIDE_URL}
|
11
13
|
MSG
|
14
|
+
SHELL = Thor::Shell::Color.new
|
12
15
|
|
13
16
|
def get_config_file_path_with_backward_compatibility(config_path)
|
14
17
|
if config_path.to_s.end_with?("shakapacker.yml") && !File.exist?(config_path)
|
@@ -70,11 +73,7 @@ module Shakapacker
|
|
70
73
|
end
|
71
74
|
|
72
75
|
def puts_deprecation_message(message)
|
73
|
-
|
74
|
-
\e[33m
|
75
|
-
#{message}
|
76
|
-
\e[0m
|
77
|
-
MSG
|
76
|
+
SHELL.say "\n#{message}\n", :yellow
|
78
77
|
end
|
79
78
|
|
80
79
|
def puts_rake_deprecation_message(webpacker_task_name)
|
data/lib/shakapacker/version.rb
CHANGED
@@ -1,23 +1,27 @@
|
|
1
1
|
namespace :shakapacker do
|
2
2
|
desc "Verifies that bin/shakapacker is present"
|
3
3
|
task :check_binstubs do
|
4
|
-
|
5
|
-
|
6
|
-
|
4
|
+
verify_file_existance("bin/shakapacker", "bin/webpacker")
|
5
|
+
verify_file_existance("bin/shakapacker-dev-server", "bin/webpacker-dev-server")
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
def verify_file_existance(main_file, alternative_file)
|
10
|
+
unless File.exist?(Rails.root.join(main_file))
|
11
|
+
if File.exist?(Rails.root.join(alternative_file))
|
7
12
|
Shakapacker.puts_deprecation_message(
|
8
13
|
Shakapacker.short_deprecation_message(
|
9
|
-
|
10
|
-
|
14
|
+
alternative_file,
|
15
|
+
main_file
|
11
16
|
)
|
12
17
|
)
|
13
|
-
exit
|
14
18
|
else
|
15
19
|
puts <<~MSG
|
16
|
-
|
20
|
+
Couldn't find shakapacker binstubs!
|
17
21
|
Possible solutions:
|
18
|
-
|
19
|
-
|
20
|
-
|
22
|
+
- Ensure you have run `rails shakapacker:install`.
|
23
|
+
- Run `rails shakapacker:binstubs` if you have already installed shakapacker.
|
24
|
+
- Ensure the `bin` directory, `bin/shakapacker`, and `bin/shakapacker-dev-server` are not included in .gitignore.
|
21
25
|
MSG
|
22
26
|
exit!
|
23
27
|
end
|
@@ -5,12 +5,7 @@ namespace :shakapacker do
|
|
5
5
|
task compile: ["shakapacker:verify_install", :environment] do
|
6
6
|
Shakapacker.with_node_env(ENV.fetch("NODE_ENV", "production")) do
|
7
7
|
Shakapacker.ensure_log_goes_to_stdout do
|
8
|
-
|
9
|
-
# Successful compilation!
|
10
|
-
else
|
11
|
-
# Failed compilation
|
12
|
-
exit!
|
13
|
-
end
|
8
|
+
exit! unless Shakapacker.compile
|
14
9
|
end
|
15
10
|
end
|
16
11
|
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
const index = require('../index')
|
2
|
+
|
3
|
+
describe('index', () => {
|
4
|
+
describe('webpackConfig', () => {
|
5
|
+
test('is a global object', () => {
|
6
|
+
const { webpackConfig, globalMutableWebpackConfig } = require('../index')
|
7
|
+
|
8
|
+
expect(webpackConfig).toBe(globalMutableWebpackConfig)
|
9
|
+
})
|
10
|
+
|
11
|
+
test('Shows warning with deprecation message', () => {
|
12
|
+
const consoleSpy = jest.spyOn(console, "warn");
|
13
|
+
|
14
|
+
const { webpackConfig } = require('../index')
|
15
|
+
|
16
|
+
expect(consoleSpy).toHaveBeenCalledWith(
|
17
|
+
expect.stringMatching(/The 'webpackConfig' is deprecated/)
|
18
|
+
)
|
19
|
+
consoleSpy.mockRestore();
|
20
|
+
})
|
21
|
+
})
|
22
|
+
})
|
@@ -65,9 +65,9 @@ describe('Base config', () => {
|
|
65
65
|
})
|
66
66
|
|
67
67
|
test('should return output', () => {
|
68
|
-
expect(baseConfig.output.filename).toEqual('js/[name].js')
|
68
|
+
expect(baseConfig.output.filename).toEqual('js/[name]-[contenthash].js')
|
69
69
|
expect(baseConfig.output.chunkFilename).toEqual(
|
70
|
-
'js/[name].chunk.js'
|
70
|
+
'js/[name]-[contenthash].chunk.js'
|
71
71
|
)
|
72
72
|
})
|
73
73
|
|
@@ -65,9 +65,9 @@ describe('Base config', () => {
|
|
65
65
|
})
|
66
66
|
|
67
67
|
test('should return output', () => {
|
68
|
-
expect(baseConfig.output.filename).toEqual('js/[name].js')
|
68
|
+
expect(baseConfig.output.filename).toEqual('js/[name]-[contenthash].js')
|
69
69
|
expect(baseConfig.output.chunkFilename).toEqual(
|
70
|
-
'js/[name].chunk.js'
|
70
|
+
'js/[name]-[contenthash].chunk.js'
|
71
71
|
)
|
72
72
|
})
|
73
73
|
|
@@ -0,0 +1,53 @@
|
|
1
|
+
/* global test expect, describe, afterAll, beforeEach */
|
2
|
+
|
3
|
+
const { chdirTestApp, resetEnv } = require('../../utils/helpers')
|
4
|
+
const rootPath = process.cwd()
|
5
|
+
chdirTestApp()
|
6
|
+
|
7
|
+
describe('Development specific config', () => {
|
8
|
+
beforeEach(() => {
|
9
|
+
jest.resetModules()
|
10
|
+
resetEnv()
|
11
|
+
process.env['NODE_ENV'] = 'development'
|
12
|
+
})
|
13
|
+
afterAll(() => process.chdir(rootPath))
|
14
|
+
|
15
|
+
describe('with config.useContentHash = true', () => {
|
16
|
+
test('sets filename to use contentHash', () => {
|
17
|
+
const config = require("../../config");
|
18
|
+
config.useContentHash = true
|
19
|
+
const environmnetConfig = require('../development')
|
20
|
+
|
21
|
+
expect(environmnetConfig.output.filename).toEqual('js/[name]-[contenthash].js')
|
22
|
+
expect(environmnetConfig.output.chunkFilename).toEqual(
|
23
|
+
'js/[name]-[contenthash].chunk.js'
|
24
|
+
)
|
25
|
+
})
|
26
|
+
})
|
27
|
+
|
28
|
+
describe('with config.useContentHash = false', () => {
|
29
|
+
test('sets filename without using contentHash', () => {
|
30
|
+
const config = require("../../config");
|
31
|
+
config.useContentHash = false
|
32
|
+
const environmnetConfig = require('../development')
|
33
|
+
|
34
|
+
expect(environmnetConfig.output.filename).toEqual('js/[name].js')
|
35
|
+
expect(environmnetConfig.output.chunkFilename).toEqual(
|
36
|
+
'js/[name].chunk.js'
|
37
|
+
)
|
38
|
+
})
|
39
|
+
})
|
40
|
+
|
41
|
+
describe('with unset config.useContentHash', () => {
|
42
|
+
test('sets filename without using contentHash', () => {
|
43
|
+
const config = require("../../config");
|
44
|
+
delete config.useContentHash
|
45
|
+
const environmnetConfig = require('../development')
|
46
|
+
|
47
|
+
expect(environmnetConfig.output.filename).toEqual('js/[name].js')
|
48
|
+
expect(environmnetConfig.output.chunkFilename).toEqual(
|
49
|
+
'js/[name].chunk.js'
|
50
|
+
)
|
51
|
+
})
|
52
|
+
})
|
53
|
+
})
|
@@ -0,0 +1,53 @@
|
|
1
|
+
/* global test expect, describe, afterAll, beforeEach */
|
2
|
+
|
3
|
+
const { chdirTestApp, resetEnv } = require('../../utils/helpers')
|
4
|
+
const rootPath = process.cwd()
|
5
|
+
chdirTestApp()
|
6
|
+
|
7
|
+
describe('Production specific config', () => {
|
8
|
+
beforeEach(() => {
|
9
|
+
jest.resetModules()
|
10
|
+
resetEnv()
|
11
|
+
process.env['NODE_ENV'] = 'production'
|
12
|
+
})
|
13
|
+
afterAll(() => process.chdir(rootPath))
|
14
|
+
|
15
|
+
describe('with config.useContentHash = true', () => {
|
16
|
+
test('sets filename to use contentHash', () => {
|
17
|
+
const config = require("../../config");
|
18
|
+
config.useContentHash = true
|
19
|
+
const environmnetConfig = require('../production')
|
20
|
+
|
21
|
+
expect(environmnetConfig.output.filename).toEqual('js/[name]-[contenthash].js')
|
22
|
+
expect(environmnetConfig.output.chunkFilename).toEqual(
|
23
|
+
'js/[name]-[contenthash].chunk.js'
|
24
|
+
)
|
25
|
+
})
|
26
|
+
})
|
27
|
+
|
28
|
+
describe('with config.useContentHash = false', () => {
|
29
|
+
test('sets filename to use contentHash', () => {
|
30
|
+
const config = require("../../config");
|
31
|
+
config.useContentHash = false
|
32
|
+
const environmnetConfig = require('../production')
|
33
|
+
|
34
|
+
expect(environmnetConfig.output.filename).toEqual('js/[name]-[contenthash].js')
|
35
|
+
expect(environmnetConfig.output.chunkFilename).toEqual(
|
36
|
+
'js/[name]-[contenthash].chunk.js'
|
37
|
+
)
|
38
|
+
})
|
39
|
+
})
|
40
|
+
|
41
|
+
describe('with unset config.useContentHash', () => {
|
42
|
+
test('sets filename to use contentHash', () => {
|
43
|
+
const config = require("../../config");
|
44
|
+
delete config.useContentHash
|
45
|
+
const environmnetConfig = require('../production')
|
46
|
+
|
47
|
+
expect(environmnetConfig.output.filename).toEqual('js/[name]-[contenthash].js')
|
48
|
+
expect(environmnetConfig.output.chunkFilename).toEqual(
|
49
|
+
'js/[name]-[contenthash].chunk.js'
|
50
|
+
)
|
51
|
+
})
|
52
|
+
})
|
53
|
+
})
|
@@ -7,8 +7,8 @@ const { sync: globSync } = require('glob')
|
|
7
7
|
const WebpackAssetsManifest = require('webpack-assets-manifest')
|
8
8
|
const webpack = require('webpack')
|
9
9
|
const rules = require('../rules')
|
10
|
-
const { isProduction } = require('../env')
|
11
10
|
const config = require('../config')
|
11
|
+
const { isProduction } = require('../env')
|
12
12
|
const { moduleExists } = require('../utils/helpers')
|
13
13
|
|
14
14
|
const getEntryObject = () => {
|
@@ -68,7 +68,7 @@ const getPlugins = () => {
|
|
68
68
|
]
|
69
69
|
|
70
70
|
if (moduleExists('css-loader') && moduleExists('mini-css-extract-plugin')) {
|
71
|
-
const hash = isProduction ? '-[contenthash:8]' : ''
|
71
|
+
const hash = isProduction || config.useContentHash ? '-[contenthash:8]' : ''
|
72
72
|
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
|
73
73
|
plugins.push(
|
74
74
|
new MiniCssExtractPlugin({
|
@@ -87,7 +87,8 @@ const getPlugins = () => {
|
|
87
87
|
|
88
88
|
// Don't use contentHash except for production for performance
|
89
89
|
// https://webpack.js.org/guides/build-performance/#avoid-production-specific-tooling
|
90
|
-
const hash = isProduction ? '-[contenthash]' : ''
|
90
|
+
const hash = isProduction || config.useContentHash ? '-[contenthash]' : ''
|
91
|
+
|
91
92
|
module.exports = {
|
92
93
|
mode: 'production',
|
93
94
|
output: {
|
@@ -6,6 +6,7 @@ const CompressionPlugin = require('compression-webpack-plugin')
|
|
6
6
|
const TerserPlugin = require('terser-webpack-plugin')
|
7
7
|
const baseConfig = require('./base')
|
8
8
|
const { moduleExists } = require('../utils/helpers')
|
9
|
+
const config = require('../config')
|
9
10
|
|
10
11
|
const getPlugins = () => {
|
11
12
|
const plugins = []
|
@@ -76,4 +77,12 @@ const productionConfig = {
|
|
76
77
|
}
|
77
78
|
}
|
78
79
|
|
80
|
+
if (config.useContentHash === true) {
|
81
|
+
// eslint-disable-next-line no-console
|
82
|
+
console.warn(`⚠️ WARNING
|
83
|
+
Setting 'useContentHash' to 'false' in the production environment (specified by NODE_ENV environment variable) is not allowed!
|
84
|
+
Content hashes get added to the filenames regardless of setting useContentHash in 'shakapacker.yml' to false.
|
85
|
+
`)
|
86
|
+
}
|
87
|
+
|
79
88
|
module.exports = merge(baseConfig, productionConfig)
|
data/package/index.js
CHANGED
@@ -25,7 +25,7 @@ const generateWebpackConfig = () => {
|
|
25
25
|
return immutable
|
26
26
|
}
|
27
27
|
|
28
|
-
|
28
|
+
const shakapackerObject = {
|
29
29
|
config, // shakapacker.yml
|
30
30
|
devServer,
|
31
31
|
generateWebpackConfig,
|
@@ -38,3 +38,26 @@ module.exports = {
|
|
38
38
|
inliningCss,
|
39
39
|
...webpackMerge
|
40
40
|
}
|
41
|
+
|
42
|
+
// For backward compatibility
|
43
|
+
const shakapackerProxyHandler = {
|
44
|
+
get(target, prop) {
|
45
|
+
if (prop === 'webpackConfig') {
|
46
|
+
// eslint-disable-next-line no-console
|
47
|
+
console.warn(`⚠️
|
48
|
+
DEPRECATION NOTICE:
|
49
|
+
The 'webpackConfig' is deprecated and will be removed in a future version.
|
50
|
+
Please use 'globalMutableWebpackConfig' instead, or use
|
51
|
+
'generateWebpackConfig()' to avoid unwanted config mutation across the app.
|
52
|
+
|
53
|
+
For more information, see version 7 upgrade documentation at:
|
54
|
+
https://github.com/shakacode/shakapacker/blob/master/docs/v7_upgrade.md
|
55
|
+
`)
|
56
|
+
return globalMutableWebpackConfig()
|
57
|
+
}
|
58
|
+
|
59
|
+
return target[prop]
|
60
|
+
}
|
61
|
+
}
|
62
|
+
|
63
|
+
module.exports = new Proxy(shakapackerObject, shakapackerProxyHandler)
|
data/package/utils/helpers.js
CHANGED
@@ -2,7 +2,7 @@ const isArray = (value) => Array.isArray(value)
|
|
2
2
|
const isBoolean = (str) => /^true/.test(str) || /^false/.test(str)
|
3
3
|
const chdirTestApp = () => {
|
4
4
|
try {
|
5
|
-
return process.chdir('spec/test_app')
|
5
|
+
return process.chdir('spec/shakapacker/test_app')
|
6
6
|
} catch (e) {
|
7
7
|
return null
|
8
8
|
}
|
data/package.json
CHANGED
@@ -0,0 +1 @@
|
|
1
|
+
defaults
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# Ignore the default SQLite database.
|
2
|
+
/db/*.sqlite3
|
3
|
+
/db/*.sqlite3-journal
|
4
|
+
/db/*.sqlite3-*
|
5
|
+
|
6
|
+
# Ignore all logfiles and tempfiles.
|
7
|
+
/log
|
8
|
+
/tmp
|
9
|
+
|
10
|
+
/storage
|
11
|
+
|
12
|
+
/public/assets
|
13
|
+
.byebug_history
|
14
|
+
|
15
|
+
# Ignore master key for decrypting credentials and more.
|
16
|
+
/config/master.key
|
17
|
+
|
18
|
+
/public/packs
|
19
|
+
/public/packs-test
|
20
|
+
/node_modules
|
data/spec/dummy/Gemfile
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
|
5
|
+
|
6
|
+
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
|
7
|
+
gem "rails", "~> 6.1"
|
8
|
+
# Use sqlite3 as the database for Active Record
|
9
|
+
gem "sqlite3", "~> 1.4"
|
10
|
+
# Use Puma as the app server
|
11
|
+
gem "puma", "~> 4.1"
|
12
|
+
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
|
13
|
+
gem "jbuilder", "~> 2.7"
|
14
|
+
# Use Redis adapter to run Action Cable in production
|
15
|
+
# gem 'redis', '~> 4.0'
|
16
|
+
# Use Active Model has_secure_password
|
17
|
+
# gem 'bcrypt', '~> 3.1.7'
|
18
|
+
|
19
|
+
# Use Active Storage variant
|
20
|
+
# gem 'image_processing', '~> 1.2'
|
21
|
+
|
22
|
+
# Reduces boot times through caching; required in config/boot.rb
|
23
|
+
gem "bootsnap", ">= 1.4.2", require: false
|
24
|
+
|
25
|
+
group :development, :test, :production do
|
26
|
+
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
|
27
|
+
gem "byebug", platforms: [:mri, :mingw, :x64_mingw]
|
28
|
+
end
|
29
|
+
|
30
|
+
group :development, :test do
|
31
|
+
gem "rspec-rails", "~> 6.0.0"
|
32
|
+
end
|
33
|
+
|
34
|
+
group :development do
|
35
|
+
# Access an interactive console on exception pages or by calling 'console' anywhere in the code.
|
36
|
+
gem "web-console", ">= 3.3.0"
|
37
|
+
gem "listen", "~> 3.2"
|
38
|
+
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
|
39
|
+
gem "spring"
|
40
|
+
gem "spring-watcher-listen", "~> 2.0.0"
|
41
|
+
end
|
42
|
+
|
43
|
+
group :test do
|
44
|
+
# Adds support for Capybara system testing and selenium driver
|
45
|
+
# There is an important fix in 3.39.1.
|
46
|
+
gem "capybara", "~> 3.39.1"
|
47
|
+
# gem 'capybara-webkit'
|
48
|
+
gem "selenium-webdriver", ">= 4.9"
|
49
|
+
# Easy installation and use of web drivers to run system tests with browsers
|
50
|
+
gem "webdrivers"
|
51
|
+
end
|
52
|
+
|
53
|
+
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
|
54
|
+
gem "tzinfo-data", platforms: [:mingw, :mswin, :x64_mingw, :jruby]
|
55
|
+
|
56
|
+
gem "shakapacker", path: "../.."
|
57
|
+
gem "react_on_rails", "13.3.3"
|
58
|
+
|
59
|
+
gem "net-smtp", "~> 0.3.3"
|
60
|
+
|
61
|
+
# Psych 4+ comes with breakibg changes in Ruby 3.1.0. Though the issue are
|
62
|
+
# addressed in Rails 7. So remove this the next line in Rails 7.
|
63
|
+
gem "psych", "< 4"
|
@@ -0,0 +1,9 @@
|
|
1
|
+
# You can run these commands in separate shells
|
2
|
+
web: rails s -p 3000
|
3
|
+
|
4
|
+
# Next line runs a watch process with webpack to compile the changed files.
|
5
|
+
# When making frequent changes to client side assets, you will prefer building webpack assets
|
6
|
+
# upon saving rather than when you refresh your browser page.
|
7
|
+
# Note, if using React on Rails localization you will need to run
|
8
|
+
# `bundle exec rake react_on_rails:locale` before you run bin/shakapacker
|
9
|
+
webpack: sh -c 'rm -rf public/packs/* || true && bin/shakapacker -w'
|
@@ -0,0 +1 @@
|
|
1
|
+
This dummy project is based on [React on Rails Demo With SSR, HMR fast refresh, and TypeScript](https://github.com/shakacode/react_on_rails_demo_ssr_hmr) project.
|
data/spec/dummy/Rakefile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
/*
|
2
|
+
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
3
|
+
* listed below.
|
4
|
+
*
|
5
|
+
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, or any plugin's
|
6
|
+
* vendor/assets/stylesheets directory can be referenced here using a relative path.
|
7
|
+
*
|
8
|
+
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
|
9
|
+
* compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
|
10
|
+
* files in this directory. Styles in this file should be added after the last require_* statement.
|
11
|
+
* It is generally better to create a new file per style scope.
|
12
|
+
*
|
13
|
+
*= require_tree .
|
14
|
+
*= require_self
|
15
|
+
*/
|
@@ -0,0 +1,25 @@
|
|
1
|
+
.bright {
|
2
|
+
color: green;
|
3
|
+
font-weight: bold;
|
4
|
+
}
|
5
|
+
|
6
|
+
.logo {
|
7
|
+
height: 10vmin;
|
8
|
+
pointer-events: none;
|
9
|
+
}
|
10
|
+
|
11
|
+
|
12
|
+
@media (prefers-reduced-motion: no-preference) {
|
13
|
+
.logo {
|
14
|
+
animation: logo-spin infinite 20s linear;
|
15
|
+
}
|
16
|
+
}
|
17
|
+
|
18
|
+
@keyframes logo-spin {
|
19
|
+
from {
|
20
|
+
transform: rotate(0deg);
|
21
|
+
}
|
22
|
+
to {
|
23
|
+
transform: rotate(360deg);
|
24
|
+
}
|
25
|
+
}
|
@@ -0,0 +1,47 @@
|
|
1
|
+
import * as React from 'react'
|
2
|
+
import { useState, useEffect } from 'react'
|
3
|
+
import type { FunctionComponent } from 'react'
|
4
|
+
|
5
|
+
import style from './HelloWorld.module.css'
|
6
|
+
import logo from './logo.svg'
|
7
|
+
|
8
|
+
export interface Props {
|
9
|
+
readonly name: string
|
10
|
+
}
|
11
|
+
|
12
|
+
// Note, you need to declare the `FunctionComponent` type so that it complies
|
13
|
+
// with `ReactOnRails.register` type.
|
14
|
+
const HelloWorld: FunctionComponent<Props> = (props: Props) => {
|
15
|
+
const [name, setName] = useState(props.name)
|
16
|
+
|
17
|
+
useEffect(() => {
|
18
|
+
console.log(
|
19
|
+
'%c%s%c%s',
|
20
|
+
'color: green; background-color: lightgreen; font-weight: bold;',
|
21
|
+
'ShakaCode is hiring!',
|
22
|
+
'color: green; background-color: lightgreen; font-weight: normal;',
|
23
|
+
'Check out our open positions: https://www.shakacode.com/career/',
|
24
|
+
);
|
25
|
+
}, [])
|
26
|
+
|
27
|
+
return (
|
28
|
+
<>
|
29
|
+
<img src={logo} className={style.logo} alt="logo" />
|
30
|
+
<h3>Hello, {name || 'World'}!</h3>
|
31
|
+
<hr />
|
32
|
+
<form>
|
33
|
+
<label className={style.bright} htmlFor="name">
|
34
|
+
Say hello to:{' '}
|
35
|
+
<input
|
36
|
+
id="name"
|
37
|
+
type="text"
|
38
|
+
value={name}
|
39
|
+
onChange={(e) => setName(e.target.value)}
|
40
|
+
/>
|
41
|
+
</label>
|
42
|
+
</form>
|
43
|
+
</>
|
44
|
+
)
|
45
|
+
}
|
46
|
+
|
47
|
+
export default HelloWorld
|
@@ -0,0 +1,7 @@
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 841.9 595.3">
|
2
|
+
<g fill="#61DAFB">
|
3
|
+
<path d="M666.3 296.5c0-32.5-40.7-63.3-103.1-82.4 14.4-63.6 8-114.2-20.2-130.4-6.5-3.8-14.1-5.6-22.4-5.6v22.3c4.6 0 8.3.9 11.4 2.6 13.6 7.8 19.5 37.5 14.9 75.7-1.1 9.4-2.9 19.3-5.1 29.4-19.6-4.8-41-8.5-63.5-10.9-13.5-18.5-27.5-35.3-41.6-50 32.6-30.3 63.2-46.9 84-46.9V78c-27.5 0-63.5 19.6-99.9 53.6-36.4-33.8-72.4-53.2-99.9-53.2v22.3c20.7 0 51.4 16.5 84 46.6-14 14.7-28 31.4-41.3 49.9-22.6 2.4-44 6.1-63.6 11-2.3-10-4-19.7-5.2-29-4.7-38.2 1.1-67.9 14.6-75.8 3-1.8 6.9-2.6 11.5-2.6V78.5c-8.4 0-16 1.8-22.6 5.6-28.1 16.2-34.4 66.7-19.9 130.1-62.2 19.2-102.7 49.9-102.7 82.3 0 32.5 40.7 63.3 103.1 82.4-14.4 63.6-8 114.2 20.2 130.4 6.5 3.8 14.1 5.6 22.5 5.6 27.5 0 63.5-19.6 99.9-53.6 36.4 33.8 72.4 53.2 99.9 53.2 8.4 0 16-1.8 22.6-5.6 28.1-16.2 34.4-66.7 19.9-130.1 62-19.1 102.5-49.9 102.5-82.3zm-130.2-66.7c-3.7 12.9-8.3 26.2-13.5 39.5-4.1-8-8.4-16-13.1-24-4.6-8-9.5-15.8-14.4-23.4 14.2 2.1 27.9 4.7 41 7.9zm-45.8 106.5c-7.8 13.5-15.8 26.3-24.1 38.2-14.9 1.3-30 2-45.2 2-15.1 0-30.2-.7-45-1.9-8.3-11.9-16.4-24.6-24.2-38-7.6-13.1-14.5-26.4-20.8-39.8 6.2-13.4 13.2-26.8 20.7-39.9 7.8-13.5 15.8-26.3 24.1-38.2 14.9-1.3 30-2 45.2-2 15.1 0 30.2.7 45 1.9 8.3 11.9 16.4 24.6 24.2 38 7.6 13.1 14.5 26.4 20.8 39.8-6.3 13.4-13.2 26.8-20.7 39.9zm32.3-13c5.4 13.4 10 26.8 13.8 39.8-13.1 3.2-26.9 5.9-41.2 8 4.9-7.7 9.8-15.6 14.4-23.7 4.6-8 8.9-16.1 13-24.1zM421.2 430c-9.3-9.6-18.6-20.3-27.8-32 9 .4 18.2.7 27.5.7 9.4 0 18.7-.2 27.8-.7-9 11.7-18.3 22.4-27.5 32zm-74.4-58.9c-14.2-2.1-27.9-4.7-41-7.9 3.7-12.9 8.3-26.2 13.5-39.5 4.1 8 8.4 16 13.1 24 4.7 8 9.5 15.8 14.4 23.4zM420.7 163c9.3 9.6 18.6 20.3 27.8 32-9-.4-18.2-.7-27.5-.7-9.4 0-18.7.2-27.8.7 9-11.7 18.3-22.4 27.5-32zm-74 58.9c-4.9 7.7-9.8 15.6-14.4 23.7-4.6 8-8.9 16-13 24-5.4-13.4-10-26.8-13.8-39.8 13.1-3.1 26.9-5.8 41.2-7.9zm-90.5 125.2c-35.4-15.1-58.3-34.9-58.3-50.6 0-15.7 22.9-35.6 58.3-50.6 8.6-3.7 18-7 27.7-10.1 5.7 19.6 13.2 40 22.5 60.9-9.2 20.8-16.6 41.1-22.2 60.6-9.9-3.1-19.3-6.5-28-10.2zM310 490c-13.6-7.8-19.5-37.5-14.9-75.7 1.1-9.4 2.9-19.3 5.1-29.4 19.6 4.8 41 8.5 63.5 10.9 13.5 18.5 27.5 35.3 41.6 50-32.6 30.3-63.2 46.9-84 46.9-4.5-.1-8.3-1-11.3-2.7zm237.2-76.2c4.7 38.2-1.1 67.9-14.6 75.8-3 1.8-6.9 2.6-11.5 2.6-20.7 0-51.4-16.5-84-46.6 14-14.7 28-31.4 41.3-49.9 22.6-2.4 44-6.1 63.6-11 2.3 10.1 4.1 19.8 5.2 29.1zm38.5-66.7c-8.6 3.7-18 7-27.7 10.1-5.7-19.6-13.2-40-22.5-60.9 9.2-20.8 16.6-41.1 22.2-60.6 9.9 3.1 19.3 6.5 28.1 10.2 35.4 15.1 58.3 34.9 58.3 50.6-.1 15.7-23 35.6-58.4 50.6zM320.8 78.4z"/>
|
4
|
+
<circle cx="420.9" cy="296.5" r="45.7"/>
|
5
|
+
<path d="M520.5 78.1z"/>
|
6
|
+
</g>
|
7
|
+
</svg>
|
@@ -0,0 +1,17 @@
|
|
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
|
+
// Uncomment to copy all static images under ../images to the output folder and reference
|
11
|
+
// them with the image_pack_tag helper in views (e.g <%= image_pack_tag 'rails.png' %>)
|
12
|
+
// or the `imagePath` JavaScript helper below.
|
13
|
+
//
|
14
|
+
// const images = require.context('../images', true)
|
15
|
+
// const imagePath = (name) => images(name, true)
|
16
|
+
|
17
|
+
console.log('Hello World from Webpacker')
|