shakapacker 6.6.0 → 7.0.0.rc.1
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/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 +39 -0
- data/.github/workflows/ruby.yml +2 -6
- data/.gitignore +3 -0
- data/CHANGELOG.md +48 -4
- data/CONTRIBUTING.md +78 -22
- data/Gemfile.development_dependencies +1 -1
- data/README.md +115 -88
- data/Rakefile +46 -5
- data/config/shakapacker.yml +1 -0
- data/docs/deployment.md +11 -10
- data/docs/{developing_webpacker.md → developing_shakapacker.md} +5 -5
- data/docs/react.md +10 -6
- data/docs/style_loader_vs_mini_css.md +2 -2
- data/docs/troubleshooting.md +22 -18
- data/docs/using_esbuild_loader.md +5 -3
- data/docs/using_swc_loader.md +2 -2
- data/docs/v6_upgrade.md +2 -2
- data/docs/v7_upgrade.md +56 -0
- data/lib/install/bin/shakapacker +13 -0
- data/lib/install/bin/shakapacker-dev-server +13 -0
- data/lib/install/binstubs.rb +3 -1
- data/lib/install/config/{webpacker.yml → shakapacker.yml} +13 -8
- data/lib/install/config/webpack/webpack.config.js +3 -2
- data/lib/install/template.rb +30 -18
- data/lib/{webpacker → shakapacker}/base_strategy.rb +2 -2
- data/lib/{webpacker → shakapacker}/commands.rb +4 -4
- data/lib/{webpacker → shakapacker}/compiler.rb +43 -15
- data/lib/{webpacker → shakapacker}/compiler_strategy.rb +6 -6
- data/lib/{webpacker → shakapacker}/configuration.rb +52 -21
- data/lib/shakapacker/deprecation_helper.rb +87 -0
- data/lib/{webpacker → shakapacker}/dev_server.rb +27 -4
- data/lib/{webpacker → shakapacker}/dev_server_proxy.rb +4 -4
- data/lib/shakapacker/dev_server_runner.rb +104 -0
- data/lib/{webpacker → shakapacker}/digest_strategy.rb +6 -6
- data/lib/{webpacker → shakapacker}/env.rb +8 -8
- data/lib/{webpacker → shakapacker}/helper.rb +20 -20
- data/lib/{webpacker → shakapacker}/instance.rb +13 -10
- data/lib/{webpacker → shakapacker}/manifest.rb +14 -14
- data/lib/{webpacker → shakapacker}/mtime_strategy.rb +5 -5
- data/lib/shakapacker/railtie.rb +70 -0
- data/lib/shakapacker/runner.rb +28 -0
- data/lib/shakapacker/utils/version_syntax_converter.rb +2 -2
- data/lib/{webpacker → shakapacker}/version.rb +2 -2
- data/lib/{webpacker → shakapacker}/version_checker.rb +8 -8
- data/lib/shakapacker/webpack_runner.rb +67 -0
- data/lib/shakapacker.rb +51 -1
- data/lib/tasks/shakapacker/binstubs.rake +15 -0
- data/lib/tasks/shakapacker/check_binstubs.rake +29 -0
- data/lib/tasks/shakapacker/check_node.rake +31 -0
- data/lib/tasks/shakapacker/check_yarn.rake +33 -0
- data/lib/tasks/shakapacker/clean.rake +23 -0
- data/lib/tasks/shakapacker/clobber.rake +18 -0
- data/lib/tasks/shakapacker/compile.rake +26 -0
- data/lib/tasks/shakapacker/info.rake +21 -0
- data/lib/tasks/shakapacker/install.rake +17 -0
- data/lib/tasks/shakapacker/verify_config.rake +12 -0
- data/lib/tasks/shakapacker/verify_install.rake +4 -0
- data/lib/tasks/shakapacker/yarn_install.rake +24 -0
- data/lib/tasks/shakapacker.rake +18 -0
- data/lib/tasks/webpacker/binstubs.rake +5 -11
- data/lib/tasks/webpacker/check_binstubs.rake +6 -9
- data/lib/tasks/webpacker/check_node.rake +5 -27
- data/lib/tasks/webpacker/check_yarn.rake +5 -29
- data/lib/tasks/webpacker/clean.rake +5 -19
- data/lib/tasks/webpacker/clobber.rake +6 -13
- data/lib/tasks/webpacker/compile.rake +5 -33
- data/lib/tasks/webpacker/info.rake +5 -17
- data/lib/tasks/webpacker/install.rake +5 -13
- data/lib/tasks/webpacker/verify_config.rake +6 -11
- data/lib/tasks/webpacker/verify_install.rake +7 -2
- data/lib/tasks/webpacker/yarn_install.rake +5 -20
- data/lib/tasks/webpacker.rake +15 -13
- data/lib/webpacker/dev_server_runner.rb +9 -96
- data/lib/webpacker/webpack_runner.rb +9 -58
- data/lib/webpacker.rb +3 -47
- data/package/__tests__/config-bc.js +27 -0
- data/package/__tests__/config.js +6 -5
- data/package/__tests__/dev_server-bc.js +46 -0
- data/package/__tests__/dev_server.js +9 -8
- data/package/__tests__/development-bc.js +66 -0
- data/package/__tests__/development.js +36 -5
- data/package/__tests__/env-bc.js +59 -0
- data/package/__tests__/env.js +3 -2
- data/package/__tests__/index.js +13 -0
- data/package/__tests__/production-bc.js +51 -0
- data/package/__tests__/production.js +25 -3
- data/package/__tests__/staging-bc.js +53 -0
- data/package/__tests__/staging.js +27 -4
- data/package/__tests__/test-bc.js +43 -0
- data/package/__tests__/test.js +22 -4
- data/package/babel/preset.js +1 -4
- data/package/config.js +25 -7
- data/package/dev_server.js +7 -4
- data/package/env.js +22 -3
- data/package/environments/__tests__/base-bc.js +107 -0
- data/package/environments/__tests__/base.js +13 -13
- data/package/environments/base.js +1 -1
- data/package/environments/development.js +4 -46
- data/package/environments/production.js +1 -1
- data/package/index.js +27 -4
- data/package/rules/__tests__/__utils__/webpack.js +1 -1
- data/package/rules/__tests__/file.js +27 -0
- data/package/rules/__tests__/swc.js +1 -2
- data/package/rules/file.js +2 -2
- data/package/utils/configPath.js +19 -0
- data/package/utils/defaultConfigPath.js +2 -0
- data/package/utils/get_style_rule.js +5 -2
- data/package/utils/helpers.js +25 -2
- data/package/utils/inliningCss.js +7 -0
- data/package/utils/snakeToCamelCase +7 -0
- data/package/webpackDevServerConfig.js +68 -0
- data/package.json +2 -2
- data/{webpacker.gemspec → shakapacker.gemspec} +3 -3
- data/spec/{command_spec.rb → backward_compatibility_specs/command_spec.rb} +2 -0
- data/spec/{compiler_spec.rb → backward_compatibility_specs/compiler_spec.rb} +6 -4
- data/spec/{compiler_strategy_spec.rb → backward_compatibility_specs/compiler_strategy_spec.rb} +2 -0
- data/spec/{configuration_spec.rb → backward_compatibility_specs/configuration_spec.rb} +25 -20
- data/spec/{dev_server_runner_spec.rb → backward_compatibility_specs/dev_server_runner_spec.rb} +10 -2
- data/spec/{dev_server_spec.rb → backward_compatibility_specs/dev_server_spec.rb} +4 -2
- data/spec/{digest_strategy_spec.rb → backward_compatibility_specs/digest_strategy_spec.rb} +2 -0
- data/spec/{engine_rake_tasks_spec.rb → backward_compatibility_specs/engine_rake_tasks_spec.rb} +12 -15
- data/spec/{env_spec.rb → backward_compatibility_specs/env_spec.rb} +3 -1
- data/spec/{helper_spec.rb → backward_compatibility_specs/helper_spec.rb} +2 -0
- data/spec/backward_compatibility_specs/instance_spec.rb +31 -0
- data/spec/{manifest_spec.rb → backward_compatibility_specs/manifest_spec.rb} +4 -2
- data/spec/{mtime_strategy_spec.rb → backward_compatibility_specs/mtime_strategy_spec.rb} +2 -0
- data/spec/backward_compatibility_specs/rake_tasks_spec.rb +37 -0
- data/spec/backward_compatibility_specs/spec_helper_initializer.rb +24 -0
- data/spec/{webpack_runner_spec.rb → backward_compatibility_specs/webpack_runner_spec.rb} +3 -1
- data/spec/{webpacker_spec.rb → backward_compatibility_specs/webpacker_spec.rb} +3 -23
- data/spec/backward_compatibility_specs/webpacker_test_app/.gitignore +2 -0
- data/spec/{test_app → backward_compatibility_specs/webpacker_test_app}/app/packs/entrypoints/application.js +1 -1
- data/{lib/install → spec/backward_compatibility_specs/webpacker_test_app}/bin/webpacker +0 -0
- data/spec/backward_compatibility_specs/webpacker_test_app/config/application.rb +11 -0
- data/spec/{test_app → backward_compatibility_specs/webpacker_test_app}/config/webpacker.yml +1 -1
- data/spec/{test_app → backward_compatibility_specs/webpacker_test_app}/config/webpacker_css_extract_ignore_order_warnings.yml +1 -1
- data/spec/{test_app → backward_compatibility_specs/webpacker_test_app}/config/webpacker_defaults_fallback.yml +1 -1
- data/spec/backward_compatibility_specs/webpacker_test_app/config/webpacker_no_precompile.yml +7 -0
- data/spec/{test_app → backward_compatibility_specs/webpacker_test_app}/config/webpacker_other_location.yml +1 -1
- data/spec/{test_app → backward_compatibility_specs/webpacker_test_app}/config/webpacker_public_root.yml +1 -1
- data/spec/backward_compatibility_specs/webpacker_test_app/package.json +13 -0
- data/spec/backward_compatibility_specs/webpacker_test_app/tmp/shakapacker/last-compilation-digest-production +1 -0
- 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/images/.keep +0 -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/concerns/.keep +0 -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/mounted_app/test/dummy/config/application.rb +1 -1
- data/spec/mounted_app/test/dummy/config/webpacker.yml +3 -3
- data/spec/shakapacker/command_spec.rb +116 -0
- data/spec/shakapacker/compiler_spec.rb +59 -0
- data/spec/shakapacker/compiler_strategy_spec.rb +22 -0
- data/spec/shakapacker/configuration_spec.rb +323 -0
- data/spec/shakapacker/dev_server_runner_spec.rb +72 -0
- data/spec/shakapacker/dev_server_spec.rb +133 -0
- data/spec/shakapacker/digest_strategy_spec.rb +35 -0
- data/spec/shakapacker/engine_rake_tasks_spec.rb +43 -0
- data/spec/shakapacker/env_spec.rb +23 -0
- data/spec/shakapacker/helper_spec.rb +243 -0
- data/spec/shakapacker/instance_spec.rb +31 -0
- data/spec/shakapacker/manifest_spec.rb +100 -0
- data/spec/shakapacker/mtime_strategy_spec.rb +55 -0
- data/spec/shakapacker/rake_tasks_spec.rb +93 -0
- data/spec/shakapacker/shakapacker_spec.rb +41 -0
- data/spec/shakapacker/spec_helper_initializer.rb +24 -0
- data/spec/shakapacker/test_app/.gitignore +2 -0
- data/spec/shakapacker/test_app/Rakefile +3 -0
- data/spec/shakapacker/test_app/app/javascript/entrypoints/application.js +10 -0
- data/spec/shakapacker/test_app/app/javascript/entrypoints/generated/something.js +2 -0
- data/spec/shakapacker/test_app/app/javascript/entrypoints/multi_entry.css +4 -0
- data/spec/shakapacker/test_app/app/javascript/entrypoints/multi_entry.js +4 -0
- data/spec/{test_app/bin/webpacker-dev-server → shakapacker/test_app/bin/shakapacker} +3 -3
- data/spec/{test_app/bin/webpacker → shakapacker/test_app/bin/shakapacker-dev-server} +3 -3
- data/spec/{test_app → shakapacker/test_app}/config/application.rb +1 -1
- data/spec/shakapacker/test_app/config/environment.rb +4 -0
- data/spec/shakapacker/test_app/config/initializers/inspect_autoload_paths.rb +1 -0
- data/spec/shakapacker/test_app/config/shakapacker.yml +82 -0
- data/spec/shakapacker/test_app/config/shakapacker_css_extract_ignore_order_warnings.yml +84 -0
- data/spec/shakapacker/test_app/config/shakapacker_defaults_fallback.yml +11 -0
- data/spec/shakapacker/test_app/config/shakapacker_manifest_path.yml +80 -0
- data/spec/shakapacker/test_app/config/shakapacker_nested_entries.yml +83 -0
- data/spec/shakapacker/test_app/config/shakapacker_no_precompile.yml +7 -0
- data/spec/shakapacker/test_app/config/shakapacker_other_location.yml +85 -0
- data/spec/shakapacker/test_app/config/shakapacker_public_root.yml +18 -0
- data/spec/shakapacker/test_app/config/webpack/webpack.config.js +0 -0
- data/spec/shakapacker/test_app/config.ru +5 -0
- data/spec/shakapacker/test_app/public/packs/manifest.json +58 -0
- data/spec/shakapacker/test_app/some.config.js +0 -0
- data/spec/shakapacker/test_app/yarn.lock +11 -0
- data/spec/{version_checker_spec.rb → shakapacker/version_checker_spec.rb} +25 -24
- data/spec/shakapacker/webpack_runner_spec.rb +55 -0
- data/spec/spec_helper.rb +0 -25
- metadata +253 -72
- data/config/webpacker.yml +0 -1
- data/gemfiles/Gemfile-rails.5.2.x +0 -9
- data/lib/webpacker/railtie.rb +0 -70
- data/lib/webpacker/runner.rb +0 -23
- data/package/configPath.js +0 -3
- data/package/inliningCss.js +0 -7
- data/spec/rake_tasks_spec.rb +0 -32
- data/spec/test_app/config/webpacker_no_precompile.yml +0 -7
- /data/spec/{test_app → backward_compatibility_specs/webpacker_test_app}/Rakefile +0 -0
- /data/spec/{test_app → backward_compatibility_specs/webpacker_test_app}/app/packs/entrypoints/generated/something.js +0 -0
- /data/spec/{test_app → backward_compatibility_specs/webpacker_test_app}/app/packs/entrypoints/multi_entry.css +0 -0
- /data/spec/{test_app → backward_compatibility_specs/webpacker_test_app}/app/packs/entrypoints/multi_entry.js +0 -0
- /data/{lib/install → spec/backward_compatibility_specs/webpacker_test_app}/bin/webpacker-dev-server +0 -0
- /data/spec/{test_app → backward_compatibility_specs/webpacker_test_app}/config/environment.rb +0 -0
- /data/spec/{test_app → backward_compatibility_specs/webpacker_test_app}/config/initializers/inspect_autoload_paths.rb +0 -0
- /data/spec/{test_app → backward_compatibility_specs/webpacker_test_app}/config/webpack/webpack.config.js +0 -0
- /data/spec/{test_app → backward_compatibility_specs/webpacker_test_app}/config/webpacker_manifest_path.yml +0 -0
- /data/spec/{test_app → backward_compatibility_specs/webpacker_test_app}/config/webpacker_nested_entries.yml +0 -0
- /data/spec/{test_app → backward_compatibility_specs/webpacker_test_app}/config.ru +0 -0
- /data/spec/{test_app → backward_compatibility_specs/webpacker_test_app}/public/packs/manifest.json +0 -0
- /data/spec/{test_app → backward_compatibility_specs/webpacker_test_app}/some.config.js +0 -0
- /data/spec/{test_app → backward_compatibility_specs/webpacker_test_app}/yarn.lock +0 -0
- /data/spec/{test_app → shakapacker/test_app}/package.json +0 -0
data/README.md
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
# Shakapacker
|
|
1
|
+
# Shakapacker (v7)
|
|
2
2
|
|
|
3
|
-
_Official, actively maintained successor to [rails/webpacker](https://github.com/rails/webpacker).
|
|
3
|
+
_Official, actively maintained successor to [rails/webpacker](https://github.com/rails/webpacker).ShakaCode stands behind the long-term maintenance and development of this project for the Rails community._
|
|
4
4
|
|
|
5
|
+
* ⚠️ See the [6-stable](https://github.com/shakacode/shakapacker/tree/6-stable) branch for Shakapacker v6.x code and documentation. :warning:
|
|
6
|
+
* See [V7 Upgrade](./docs/v7_upgrade.md) for upgrading from the v6 release.
|
|
5
7
|
* See [V6 Upgrade](./docs/v6_upgrade.md) for upgrading from v5 or prior v6 releases.
|
|
6
8
|
|
|
7
9
|
[](https://github.com/shakacode/shakapacker/actions)
|
|
@@ -15,18 +17,18 @@ _Official, actively maintained successor to [rails/webpacker](https://github.com
|
|
|
15
17
|
|
|
16
18
|
Shakpacker makes it easy to use the JavaScript pre-processor and bundler [Webpack v5+](https://webpack.js.org/)
|
|
17
19
|
to manage frontend JavaScript in Rails. It can coexist with the asset pipeline,
|
|
18
|
-
leaving Webpack responsible solely for frontend JavaScript, or
|
|
20
|
+
leaving Webpack responsible solely for frontend JavaScript, or can be used exclusively, making it also responsible for images, fonts, and CSS.
|
|
19
21
|
|
|
20
22
|
Check out 6.1.1+ for [SWC](https://swc.rs/) and [esbuild-loader](https://github.com/privatenumber/esbuild-loader) support! They are faster than Babel!
|
|
21
23
|
|
|
22
|
-
See a comparison of [Shakapacker with jsbundling-rails](https://github.com/rails/jsbundling-rails/blob/main/docs/comparison_with_webpacker.md).
|
|
24
|
+
See a comparison of [Shakapacker with jsbundling-rails](https://github.com/rails/jsbundling-rails/blob/main/docs/comparison_with_webpacker.md). For a in-depth discussion of choosing between `shakapacker` and `jsbundling-rails`, see the discussion [Webpacker alternatives - which path should we go to? #8783](https://github.com/decidim/decidim/discussions/8783) and the resulting PR [Switch away from Webpacker to Shakapacker #10389](https://github.com/decidim/decidim/pull/10389).
|
|
23
25
|
|
|
24
26
|
For discussions, see our [Slack Channel](https://reactrails.slack.com/join/shared_invite/enQtNjY3NTczMjczNzYxLTlmYjdiZmY3MTVlMzU2YWE0OWM0MzNiZDI0MzdkZGFiZTFkYTFkOGVjODBmOWEyYWQ3MzA2NGE1YWJjNmVlMGE).
|
|
25
27
|
|
|
26
28
|
---
|
|
27
29
|
### ShakaCode Support
|
|
28
30
|
|
|
29
|
-
[ShakaCode](https://www.shakacode.com) offers support for upgrading from
|
|
31
|
+
[ShakaCode](https://www.shakacode.com) offers support for upgrading from Webpacker and using Shakapacker. If interested, contact Justin Gordon, [justin@shakacode.com](mailto:justin@shakacode.com). We're also [hiring](https://jobs.lever.co/shakacode/3bdbfdb3-4495-4611-a279-01dddb351abe)!
|
|
30
32
|
|
|
31
33
|
Here's a testimonial of how ShakaCode can help, from [Florian Gößler](https://github.com/FGoessler) of [Blinkist](https://www.blinkist.com/), January 2, 2023:
|
|
32
34
|
> Hey Justin 👋
|
|
@@ -37,6 +39,8 @@ Here's a testimonial of how ShakaCode can help, from [Florian Gößler](https://
|
|
|
37
39
|
>
|
|
38
40
|
> Have a great 2023 and maybe we get to work together again later in the year! 🙌
|
|
39
41
|
|
|
42
|
+
Read the [full review here](https://clutch.co/profile/shakacode#reviews?sort_by=date_DESC#review-2118154). Here's [another review of a Shakapacker migration that led to more work](https://clutch.co/profile/shakacode#reviews?sort_by=date_DESC#review-2096078).
|
|
43
|
+
|
|
40
44
|
---
|
|
41
45
|
|
|
42
46
|
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
|
|
@@ -100,8 +104,8 @@ Here's a testimonial of how ShakaCode can help, from [Florian Gößler](https://
|
|
|
100
104
|
|
|
101
105
|
## Features
|
|
102
106
|
- Rails view helpers that fully support Webpack output, including HMR and code splitting.
|
|
103
|
-
- Convenient but not required webpack configuration. The only requirement is that your webpack configuration
|
|
104
|
-
- HMR with the
|
|
107
|
+
- Convenient but not required webpack configuration. The only requirement is that your webpack configuration creates a manifest.
|
|
108
|
+
- HMR with the `shakapacker-dev-server`, such as for hot-reloading React!
|
|
105
109
|
- Automatic code splitting using multiple entry points to optimize JavaScript downloads.
|
|
106
110
|
- [Webpack v5+](https://webpack.js.org/)
|
|
107
111
|
- ES6 with [babel](https://babeljs.io/), [SWC](https://swc.rs/), or [Esbuild](https://github.com/privatenumber/esbuild-loader)
|
|
@@ -133,14 +137,16 @@ Add `shakapacker` gem to your `Gemfile`:
|
|
|
133
137
|
bundle add shakapacker --strict
|
|
134
138
|
```
|
|
135
139
|
|
|
136
|
-
Then
|
|
140
|
+
Then run the following to install Shakapacker:
|
|
137
141
|
|
|
138
142
|
```bash
|
|
139
143
|
./bin/bundle install
|
|
140
|
-
./bin/rails
|
|
144
|
+
./bin/rails shakapacker:install
|
|
141
145
|
```
|
|
142
146
|
|
|
143
|
-
|
|
147
|
+
Before initiating the installation process, ensure you have committed all the changes. While installing Shakapacker, there might be some conflict between the existing file content and what Shakapacker tries to copy. You can either approve all the prompts for overriding these files or use the `FORCE=true` environment variable before the installation command to force the override without any prompt.
|
|
148
|
+
|
|
149
|
+
When `package.json` and/or `yarn.lock` changes, such as when pulling down changes to your local environment in team settings, be sure to keep your NPM packages up-to-date:
|
|
144
150
|
|
|
145
151
|
```bash
|
|
146
152
|
yarn
|
|
@@ -154,32 +160,32 @@ yarn add @babel/core @babel/plugin-transform-runtime @babel/preset-env @babel/ru
|
|
|
154
160
|
webpack webpack-assets-manifest webpack-cli webpack-merge webpack-sources webpack-dev-server
|
|
155
161
|
```
|
|
156
162
|
|
|
157
|
-
Previously, these "webpack" and "babel" packages were direct dependencies for `
|
|
163
|
+
Previously, these "webpack" and "babel" packages were direct dependencies for `shakapacker`. By
|
|
158
164
|
making these peer dependencies, you have control over the versions used in your webpack and babel configs.
|
|
159
165
|
|
|
160
166
|
### Note for Yarn v2 usage
|
|
161
167
|
|
|
162
168
|
If you are using Yarn v2 (berry), please note that PnP modules are not supported.
|
|
163
169
|
|
|
164
|
-
|
|
170
|
+
To use Shakapacker with Yarn v2, make sure you set `nodeLinker: node-modules` in your `.yarnrc.yml` file as per the [Yarn docs](https://yarnpkg.com/getting-started/migration#step-by-step) to opt out of Plug'n'Play behavior.
|
|
165
171
|
|
|
166
172
|
## Concepts
|
|
167
173
|
|
|
168
|
-
At
|
|
174
|
+
At its core, Shakapacker's essential function is to:
|
|
169
175
|
|
|
170
176
|
1. Provide configuration by a single file used by both Rails view helpers and JavaScript webpack compilation code.
|
|
171
|
-
2. Provide Rails view helpers, utilizing this configuration file
|
|
172
|
-
3. Provide a community
|
|
177
|
+
2. Provide Rails view helpers, utilizing this configuration file so that a webpage can load JavaScript, CSS, and other static assets compiled by webpack, supporting bundle splitting, fingerprinting, and HMR.
|
|
178
|
+
3. Provide a community-supported, default webpack compilation that generates the necessary bundles and manifest, using the same configuration file. This compilation can be extended for any needs.
|
|
173
179
|
|
|
174
180
|
## Usage
|
|
175
181
|
|
|
176
182
|
### Configuration and Code
|
|
177
183
|
|
|
178
|
-
You will need your file system to correspond to the setup of your `
|
|
184
|
+
You will need your file system to correspond to the setup of your `config/shakapacker.yml` file.
|
|
179
185
|
|
|
180
186
|
Suppose you have the following configuration:
|
|
181
187
|
|
|
182
|
-
`
|
|
188
|
+
`shakapacker.yml`
|
|
183
189
|
```yml
|
|
184
190
|
default: &default
|
|
185
191
|
source_path: app/javascript
|
|
@@ -210,16 +216,20 @@ Webpack intelligently includes only necessary files. In this example, the file `
|
|
|
210
216
|
|
|
211
217
|
`nested_entries` allows you to have webpack entry points nested in subdirectories. This defaults to false so you don't accidentally create entry points for an entire tree of files. In other words, with `nested_entries: false`, you can have your entire `source_path` used for your source (using the `source_entry_path: /`) and you place files at the top level that you want as entry points. `nested_entries: true` allows you to have entries that are in subdirectories. This is useful if you have entries that are generated, so you can have a `generated` subdirectory and easily separate generated files from the rest of your codebase.
|
|
212
218
|
|
|
219
|
+
#### Setting custom config path
|
|
220
|
+
|
|
221
|
+
You can use the environment variable `SHAKAPACKER_CONFIG` to enforce a particular path to the config file rather than the default `config/shakapacker.yml`.
|
|
222
|
+
|
|
213
223
|
### View Helpers
|
|
214
224
|
The Shakapacker view helpers generate the script and link tags to get the webpack output onto your views.
|
|
215
225
|
|
|
216
|
-
Be sure to consult the API documentation in the source code of [helper.rb](./lib/
|
|
226
|
+
Be sure to consult the API documentation in the source code of [helper.rb](./lib/shakapacker/helper.rb).
|
|
217
227
|
|
|
218
|
-
**Note:**
|
|
228
|
+
**Note:** For your styles or static assets files to be available in your view, you would need to link them in your "pack" or entry file. Otherwise, Webpack won't know to package up those files.
|
|
219
229
|
|
|
220
230
|
#### View Helpers `javascript_pack_tag` and `stylesheet_pack_tag`
|
|
221
231
|
|
|
222
|
-
These view helpers take your `
|
|
232
|
+
These view helpers take your `shakapacker.yml` configuration file and the resulting webpack compilation `manifest.json` and generate the HTML to load the assets.
|
|
223
233
|
|
|
224
234
|
You can then link the JavaScript pack in Rails views using the `javascript_pack_tag` helper. If you have styles imported in your pack file, you can link them by using `stylesheet_pack_tag`:
|
|
225
235
|
|
|
@@ -229,24 +239,24 @@ You can then link the JavaScript pack in Rails views using the `javascript_pack_
|
|
|
229
239
|
```
|
|
230
240
|
|
|
231
241
|
The `javascript_pack_tag` and `stylesheet_pack_tag` helpers will include all the transpiled
|
|
232
|
-
packs with the chunks in your view, which creates
|
|
242
|
+
packs with the chunks in your view, which creates HTML tags for all the chunks.
|
|
233
243
|
|
|
234
244
|
You can provide multiple packs and other attributes. Note, `defer` defaults to showing.
|
|
235
245
|
|
|
236
246
|
```erb
|
|
237
|
-
<%= javascript_pack_tag 'calendar', 'map', 'data-
|
|
247
|
+
<%= javascript_pack_tag 'calendar', 'map', 'data-turbo-track': 'reload' %>
|
|
238
248
|
```
|
|
239
249
|
|
|
240
|
-
The resulting HTML would look like:
|
|
250
|
+
The resulting HTML would look like this:
|
|
241
251
|
```
|
|
242
|
-
<script src="/packs/vendor-16838bab065ae1e314.js" data-
|
|
243
|
-
<script src="/packs/calendar~runtime-16838bab065ae1e314.js" data-
|
|
244
|
-
<script src="/packs/calendar-1016838bab065ae1e314.js" data-
|
|
245
|
-
<script src="/packs/map~runtime-16838bab065ae1e314.js" data-
|
|
246
|
-
<script src="/packs/map-16838bab065ae1e314.js" data-
|
|
252
|
+
<script src="/packs/vendor-16838bab065ae1e314.js" data-turbo-track="reload" defer></script>
|
|
253
|
+
<script src="/packs/calendar~runtime-16838bab065ae1e314.js" data-turbo-track="reload" defer></script>
|
|
254
|
+
<script src="/packs/calendar-1016838bab065ae1e314.js" data-turbo-track="reload" defer"></script>
|
|
255
|
+
<script src="/packs/map~runtime-16838bab065ae1e314.js" data-turbo-track="reload" defer></script>
|
|
256
|
+
<script src="/packs/map-16838bab065ae1e314.js" data-turbo-track="reload" defer></script>
|
|
247
257
|
```
|
|
248
258
|
|
|
249
|
-
In this output, both the calendar and map codes might refer to other common libraries. Those get placed something like the vendor bundle. The view helper removes any duplication.
|
|
259
|
+
In this output, both the calendar and map codes might refer to other common libraries. Those get placed in something like the vendor bundle. The view helper removes any duplication.
|
|
250
260
|
|
|
251
261
|
Note, the default of "defer" for the `javascript_pack_tag`. You can override that to `false`. If you expose jquery globally with `expose-loader,` by using `import $ from "expose-loader?exposes=$,jQuery!jquery"` in your `app/javascript/application.js`, pass the option `defer: false` to your `javascript_pack_tag`.
|
|
252
262
|
|
|
@@ -269,7 +279,7 @@ While this also generally applies to `stylesheet_pack_tag`, you may use multiple
|
|
|
269
279
|
|
|
270
280
|
#### View Helper `append_javascript_pack_tag`, `prepend_javascript_pack_tag` and `append_stylesheet_pack_tag`
|
|
271
281
|
|
|
272
|
-
If you need configure your script pack names or stylesheet pack names from the view for a route or partials, then you will need some logic to ensure you call the helpers only once with multiple arguments. The new view helpers, `append_javascript_pack_tag` and `append_stylesheet_pack_tag` can solve this problem. The helper `append_javascript_pack_tag` will queue up script packs when the `javascript_pack_tag` is finally used. Similarly,`append_stylesheet_pack_tag` will queue up style packs when the `stylesheet_pack_tag` is finally used.
|
|
282
|
+
If you need to configure your script pack names or stylesheet pack names from the view for a route or partials, then you will need some logic to ensure you call the helpers only once with multiple arguments. The new view helpers, `append_javascript_pack_tag` and `append_stylesheet_pack_tag` can solve this problem. The helper `append_javascript_pack_tag` will queue up script packs when the `javascript_pack_tag` is finally used. Similarly,`append_stylesheet_pack_tag` will queue up style packs when the `stylesheet_pack_tag` is finally used.
|
|
273
283
|
|
|
274
284
|
Main view:
|
|
275
285
|
```erb
|
|
@@ -337,7 +347,7 @@ is the same as using this in the main layout:
|
|
|
337
347
|
<%= javascript_pack_tag 'main', 'calendar', 'map', application' %>
|
|
338
348
|
```
|
|
339
349
|
|
|
340
|
-
For alternative options
|
|
350
|
+
For alternative options for setting the additional packs, [see this discussion](https://github.com/shakacode/shakapacker/issues/39).
|
|
341
351
|
|
|
342
352
|
#### View Helper: `asset_pack_path`
|
|
343
353
|
|
|
@@ -378,17 +388,17 @@ If you want to use images in your stylesheets:
|
|
|
378
388
|
|
|
379
389
|
### Server-Side Rendering (SSR)
|
|
380
390
|
|
|
381
|
-
Note, if you are using server-side rendering of JavaScript with dynamic code-splitting, as is often done with extensions to
|
|
391
|
+
Note, if you are using server-side rendering of JavaScript with dynamic code-splitting, as is often done with extensions to Shakapacker, like [React on Rails](https://github.com/shakacode/react_on_rails), your JavaScript should create the link prefetch HTML tags that you will use, so you won't need to use to `asset_pack_path` in those circumstances.
|
|
382
392
|
|
|
383
393
|
### Development
|
|
384
394
|
|
|
385
|
-
|
|
395
|
+
Shakapacker ships with two binstubs: `./bin/shakapacker` and `./bin/shakapacker-dev-server`. Both are thin wrappers around the standard `webpack.js` and `webpack-dev-server.js` executables to ensure that the right configuration files and environmental variables are loaded based on your environment.
|
|
386
396
|
|
|
387
397
|
_Note: older Shakapacker installations had set a missing NODE_ENV in the binstubs. Please remove this for versions 6.5.2 and newer._
|
|
388
398
|
|
|
389
399
|
#### Automatic Webpack Code Building
|
|
390
400
|
|
|
391
|
-
Shakapacker can be configured to automatically compile on demand when needed using
|
|
401
|
+
Shakapacker can be configured to automatically compile on demand when needed using `compile` option in the `shakapacker.yml`. This happens when you refer to any of the pack assets using the Shakapacker helper methods. This means that you don't have to run any separate processes. Compilation errors are logged to the standard Rails log. However, this auto-compilation happens when a web request is made that requires an updated webpack build, not when files change. Thus, that can be **painfully slow** for front-end development in this default way. Instead, you should either run the `bin/shakapacker --watch` or run `./bin/shakapacker-dev-server` during development.
|
|
392
402
|
|
|
393
403
|
The `compile: true` option can be more useful for test and production builds.
|
|
394
404
|
|
|
@@ -397,43 +407,43 @@ The `compile: true` option can be more useful for test and production builds.
|
|
|
397
407
|
Shakapacker ships with two different strategies that are used to determine whether assets need recompilation per the `compile: true` option:
|
|
398
408
|
|
|
399
409
|
- `digest` - This strategy calculates SHA1 digest of files in your watched paths (see below). The calculated digest is then stored in a temp file. To check whether the assets need to be recompiled, Shakapacker calculates the SHA1 of the watched files and compares it with the one stored. If the digests are equal, no recompilation occurs. If the digests are different or the temp file is missing, files are recompiled.
|
|
400
|
-
- `mtime` - This strategy looks at last modified at timestamps of both files AND directories in your watched paths. The timestamp of the most recent file or directory is then compared with the timestamp of `manifest.json` file generated. If the manifest file timestamp is newer than one of the most recently modified
|
|
410
|
+
- `mtime` - This strategy looks at the last "modified at" timestamps of both files AND directories in your watched paths. The timestamp of the most recent file or directory is then compared with the timestamp of `manifest.json` file generated. If the manifest file timestamp is newer than one of the most recently modified files or directories in the watched paths, no recompilation occurs. If the manifest file is older, files are recompiled.
|
|
401
411
|
|
|
402
412
|
The `mtime` strategy is generally faster than the `digest` one, but it requires stable timestamps, this makes it perfect for a development environment, such as needing to rebuild bundles for tests, or if you're not changing frontend assets much.
|
|
403
413
|
|
|
404
414
|
In production or CI environments, the `digest` strategy is more suitable, unless you are using incremental builds or caching and can guarantee that the timestamps will not change after e.g. cache restore. However, many production or CI environments will explicitly compile assets, so `compile: false` is more appropriate. Otherwise, you'll waste time either checking file timestamps or computing digests.
|
|
405
415
|
|
|
406
|
-
You can control what strategy is used by `compiler_strategy` option in `
|
|
416
|
+
You can control what strategy is used by the `compiler_strategy` option in `shakapacker.yml` config file. By default `mtime` strategy is used in development environment, `digest` is used elsewhere.
|
|
407
417
|
|
|
408
|
-
**Note:** If you are not using the
|
|
418
|
+
**Note:** If you are not using the `shakapacker-dev-server`, your packs will be served by the Rails public file server. If you've enabled caching (Rails application `config.action_controller.perform_caching` setting), your changes will likely not be picked up due to `Cache-Control` header being set and assets being cached in the browser memory. For more details see [issue](https://github.com/shakacode/shakapacker/issues/88)[ #88](https://github.com/shakacode/shakapacker/issues/88)](https://github.com/shakacode/shakapacker/issues/88).
|
|
409
419
|
|
|
410
|
-
If you want to use live code reloading, or you have enough JavaScript that on-demand compilation is too slow, you'll need to run `./bin/
|
|
420
|
+
If you want to use live code reloading, or you have enough JavaScript that on-demand compilation is too slow, you'll need to run `./bin/shakapacker-dev-server`. This process will watch for changes in the relevant files, defined by `shakapacker.yml` configuration settings for `source_path`, `source_entry_path`, and `additional_paths`, and it will then automatically reload the browser to match. This feature is also known as [Hot Module Replacement](https://webpack.js.org/concepts/hot-module-replacement/).
|
|
411
421
|
|
|
412
422
|
#### Common Development Commands
|
|
413
423
|
|
|
414
424
|
```bash
|
|
415
425
|
# webpack dev server
|
|
416
|
-
./bin/
|
|
426
|
+
./bin/shakapacker-dev-server
|
|
417
427
|
|
|
418
428
|
# watcher
|
|
419
|
-
./bin/
|
|
429
|
+
./bin/shakapacker --watch --progress
|
|
420
430
|
|
|
421
431
|
# standalone build
|
|
422
|
-
./bin/
|
|
432
|
+
./bin/shakapacker --progress
|
|
423
433
|
```
|
|
424
434
|
|
|
425
|
-
Once you start this webpack development server,
|
|
435
|
+
Once you start this webpack development server, Shakapacker will automatically start proxying all webpack asset requests to this server. When you stop this server, Rails will detect that it's not running and Rails will revert back to on-demand compilation _if_ you have the `compile` option set to true in your `config/shakapacker.yml`
|
|
426
436
|
|
|
427
|
-
You can use environment variables as options supported by [webpack-dev-server](https://webpack.js.org/configuration/dev-server/) in the form `
|
|
437
|
+
You can use environment variables as options supported by [webpack-dev-server](https://webpack.js.org/configuration/dev-server/) in the form `SHAKAPACKER_DEV_SERVER_<OPTION>`. Please note that these environmental variables will always take precedence over the ones already set in the configuration file, and that the _same_ environmental variables must be available to the `rails server` process.
|
|
428
438
|
|
|
429
439
|
```bash
|
|
430
|
-
|
|
440
|
+
SHAKAPACKER_DEV_SERVER_PORT=4305 SHAKAPACKER_DEV_SERVER_HOST=example.com SHAKAPACKER_DEV_SERVER_INLINE=true SHAKAPACKER_DEV_SERVER_HOT=false ./bin/shakapacker-dev-server
|
|
431
441
|
```
|
|
432
442
|
|
|
433
|
-
By default, the webpack dev server listens on `localhost:3035` in development for security purposes. However, if you want your app to be available on port 4035 over local LAN IP or a VM instance like vagrant, you can set the `port` and `host` when running `./bin/
|
|
443
|
+
By default, the webpack dev server listens on `localhost:3035` in development for security purposes. However, if you want your app to be available on port 4035 over local LAN IP or a VM instance like vagrant, you can set the `port` and `host` when running `./bin/shakapacker-dev-server` binstub:
|
|
434
444
|
|
|
435
445
|
```bash
|
|
436
|
-
|
|
446
|
+
SHAKAPACKER_DEV_SERVER_PORT=4305 SHAKAPACKER_DEV_SERVER_HOST=0.0.0.0 ./bin/shakapacker-dev-server
|
|
437
447
|
```
|
|
438
448
|
|
|
439
449
|
**Note:** You need to allow webpack-dev-server host as an allowed origin for `connect-src` if you are running your application in a restrict CSP environment (like Rails 5.2+). This can be done in Rails 5.2+ in the CSP initializer `config/initializers/content_security_policy.rb` with a snippet like this:
|
|
@@ -449,17 +459,19 @@ end
|
|
|
449
459
|
|
|
450
460
|
### Webpack Configuration
|
|
451
461
|
|
|
452
|
-
First, you don't _need_ to use Shakapacker's webpack configuration. However, the `shakapacker` NPM package provides convenient access to configuration code that reads the `config/
|
|
462
|
+
First, you don't _need_ to use Shakapacker's webpack configuration. However, the `shakapacker` NPM package provides convenient access to configuration code that reads the `config/shakapacker.yml` file which the view helpers also use. If you have your customized webpack configuration, at the minimum, you must ensure:
|
|
453
463
|
|
|
454
|
-
1. Your output files go the right directory
|
|
455
|
-
2. Your output includes a manifest, via package [`webpack-assets-manifest`](https://github.com/webdeveric/webpack-assets-manifest) that maps output names (your 'packs') to the fingerprinted versions, including bundle-splitting dependencies. That's the main secret sauce of
|
|
464
|
+
1. Your output files go to the right directory
|
|
465
|
+
2. Your output includes a manifest, via package [`webpack-assets-manifest`](https://github.com/webdeveric/webpack-assets-manifest) that maps output names (your 'packs') to the fingerprinted versions, including bundle-splitting dependencies. That's the main secret sauce of Shakapacker!
|
|
456
466
|
|
|
457
467
|
The most practical webpack configuration is to take the default from Shakapacker and then use [webpack-merge](https://github.com/survivejs/webpack-merge) to merge your customizations with the default. For example, suppose you want to add some `resolve.extensions`:
|
|
458
468
|
|
|
459
469
|
```js
|
|
460
470
|
// use the new NPM package name, `shakapacker`.
|
|
461
471
|
// merge is webpack-merge from https://github.com/survivejs/webpack-merge
|
|
462
|
-
const {
|
|
472
|
+
const { generateWebpackConfig, merge } = require('shakapacker')
|
|
473
|
+
|
|
474
|
+
const baseWebpackConfig = generateWebpackConfig()
|
|
463
475
|
|
|
464
476
|
const options = {
|
|
465
477
|
resolve: {
|
|
@@ -499,7 +511,9 @@ Then `require` this file in your `config/webpack/webpack.config.js`:
|
|
|
499
511
|
```js
|
|
500
512
|
// config/webpack/webpack.config.js
|
|
501
513
|
// use the new NPM package name, `shakapacker`.
|
|
502
|
-
const {
|
|
514
|
+
const { generateWebpackConfig, merge } = require('shakapacker')
|
|
515
|
+
|
|
516
|
+
const webpackConfig = generateWebpackConfig()
|
|
503
517
|
const customConfig = require('./custom')
|
|
504
518
|
|
|
505
519
|
module.exports = merge(webpackConfig, customConfig)
|
|
@@ -509,7 +523,9 @@ If you need access to configs within Shakapacker's configuration, you can import
|
|
|
509
523
|
|
|
510
524
|
```js
|
|
511
525
|
// config/webpack/webpack.config.js
|
|
512
|
-
const {
|
|
526
|
+
const { generateWebpackConfig } = require('shakapacker')
|
|
527
|
+
|
|
528
|
+
const webpackConfig = generateWebpackConfig()
|
|
513
529
|
|
|
514
530
|
console.log(webpackConfig.output_path)
|
|
515
531
|
console.log(webpackConfig.source_path)
|
|
@@ -518,7 +534,7 @@ console.log(webpackConfig.source_path)
|
|
|
518
534
|
console.log(JSON.stringify(webpackConfig, undefined, 2))
|
|
519
535
|
```
|
|
520
536
|
|
|
521
|
-
You may want to modify rules in the default configuration. For instance, if you are using a custom svg loader, you may want to remove `.svg` from the default file loader rules. You can search and filter the default rules like so:
|
|
537
|
+
You may want to modify the rules in the default configuration. For instance, if you are using a custom svg loader, you may want to remove `.svg` from the default file loader rules. You can search and filter the default rules like so:
|
|
522
538
|
|
|
523
539
|
```js
|
|
524
540
|
const svgRule = config.module.rules.find(rule => rule.test.test('.svg'));
|
|
@@ -536,7 +552,7 @@ By default, you will find the Shakapacker preset in your `package.json`. Note, y
|
|
|
536
552
|
]
|
|
537
553
|
},
|
|
538
554
|
```
|
|
539
|
-
Optionally, you can change your Babel configuration by removing these lines in your `package.json` and
|
|
555
|
+
Optionally, you can change your Babel configuration by removing these lines in your `package.json` and adding [a Babel](https://babeljs.io/docs/en/config-files) configuration file](https://babeljs.io/docs/en/config-files) to your project. For an example of customization based on the original, see [Customizing Babel Config](./docs/customizing_babel_config.md).
|
|
540
556
|
|
|
541
557
|
|
|
542
558
|
### SWC configuration
|
|
@@ -598,7 +614,9 @@ Then modify the webpack config to use it as a plugin:
|
|
|
598
614
|
|
|
599
615
|
```js
|
|
600
616
|
// config/webpack/webpack.config.js
|
|
601
|
-
const {
|
|
617
|
+
const { generateWebpackConfig, merge } = require("shakapacker");
|
|
618
|
+
|
|
619
|
+
const webpackConfig = generateWebpackConfig()
|
|
602
620
|
const ForkTSCheckerWebpackPlugin = require("fork-ts-checker-webpack-plugin");
|
|
603
621
|
|
|
604
622
|
module.exports = merge(webpackConfig, {
|
|
@@ -608,7 +626,7 @@ module.exports = merge(webpackConfig, {
|
|
|
608
626
|
|
|
609
627
|
#### CSS
|
|
610
628
|
|
|
611
|
-
To enable CSS support in your application, add following packages:
|
|
629
|
+
To enable CSS support in your application, add the following packages:
|
|
612
630
|
|
|
613
631
|
```bash
|
|
614
632
|
yarn add css-loader style-loader mini-css-extract-plugin css-minimizer-webpack-plugin
|
|
@@ -618,7 +636,10 @@ Optionally, add the `CSS` extension to webpack config for easy resolution.
|
|
|
618
636
|
|
|
619
637
|
```js
|
|
620
638
|
// config/webpack/webpack.config.js
|
|
621
|
-
const {
|
|
639
|
+
const { generateWebpackConfig, merge } = require('shakapacker')
|
|
640
|
+
|
|
641
|
+
const webpackConfig = generateWebpackConfig()
|
|
642
|
+
|
|
622
643
|
const customConfig = {
|
|
623
644
|
resolve: {
|
|
624
645
|
extensions: ['.css']
|
|
@@ -668,7 +689,7 @@ yarn add coffeescript coffee-loader
|
|
|
668
689
|
|
|
669
690
|
#### Other frameworks
|
|
670
691
|
|
|
671
|
-
Please follow
|
|
692
|
+
Please follow Webpack integration guide for the relevant framework or library,
|
|
672
693
|
|
|
673
694
|
1. [Svelte](https://github.com/sveltejs/svelte-loader#install)
|
|
674
695
|
2. [Angular](https://v2.angular.io/docs/ts/latest/guide/webpack.html#!#configure-webpack)
|
|
@@ -697,7 +718,10 @@ module.exports = {
|
|
|
697
718
|
|
|
698
719
|
```js
|
|
699
720
|
// config/webpack/webpack.config.js
|
|
700
|
-
const {
|
|
721
|
+
const { generateWebpackConfig, merge } = require('shakapacker')
|
|
722
|
+
|
|
723
|
+
const webpackConfig = generateWebpackConfig()
|
|
724
|
+
|
|
701
725
|
const vueConfig = require('./rules/vue')
|
|
702
726
|
|
|
703
727
|
module.exports = merge(vueConfig, webpackConfig)
|
|
@@ -705,9 +729,9 @@ module.exports = merge(vueConfig, webpackConfig)
|
|
|
705
729
|
|
|
706
730
|
### Custom Rails environments
|
|
707
731
|
|
|
708
|
-
Out of the box Shakapacker ships with - development, test and production environments in `config/
|
|
732
|
+
Out of the box Shakapacker ships with - development, test and production environments in `config/shakapacker.yml` however, in most production apps extra environments are needed as part of the deployment workflow. Shakapacker supports this out of the box from version 3.4.0+ onwards.
|
|
709
733
|
|
|
710
|
-
You can choose to define additional environment configurations in
|
|
734
|
+
You can choose to define additional environment configurations in shakapacker.yml,
|
|
711
735
|
|
|
712
736
|
```yml
|
|
713
737
|
staging:
|
|
@@ -723,15 +747,15 @@ staging:
|
|
|
723
747
|
public_output_path: packs-staging
|
|
724
748
|
```
|
|
725
749
|
|
|
726
|
-
Otherwise Shakapacker will use production environment as a fallback environment for loading configurations. Please note, `NODE_ENV` can either be set to `production`, `development` or `test`. This means you don't need to create additional environment files inside `config/
|
|
750
|
+
Otherwise, Shakapacker will use the production environment as a fallback environment for loading configurations. Please note, `NODE_ENV` can either be set to `production`, `development` or `test`. This means you don't need to create additional environment files inside `config/shakapacker/*` and instead use shakapacker.yml to load different configurations using `RAILS_ENV`.
|
|
727
751
|
|
|
728
|
-
For example, the below command will compile assets in production mode but will use staging configurations from `config/
|
|
752
|
+
For example, the below command will compile assets in production mode but will use staging configurations from `config/shakapacker.yml` if available or use fallback production environment configuration:
|
|
729
753
|
|
|
730
754
|
```bash
|
|
731
755
|
RAILS_ENV=staging bundle exec rails assets:precompile
|
|
732
756
|
```
|
|
733
757
|
|
|
734
|
-
And, this will compile in development mode and load configuration for cucumber environment if defined in
|
|
758
|
+
And, this will compile in development mode and load configuration for the cucumber environment if defined in `shakapacker.yml` or fallback to production configuration
|
|
735
759
|
|
|
736
760
|
```bash
|
|
737
761
|
RAILS_ENV=cucumber NODE_ENV=development bundle exec rails assets:precompile
|
|
@@ -741,24 +765,24 @@ Please note, binstubs compiles in development mode however rake tasks compiles i
|
|
|
741
765
|
|
|
742
766
|
```bash
|
|
743
767
|
# Compiles in development mode unless NODE_ENV is specified, per the binstub source
|
|
744
|
-
./bin/
|
|
745
|
-
./bin/
|
|
768
|
+
./bin/shakapacker
|
|
769
|
+
./bin/shakapacker-dev-server
|
|
746
770
|
|
|
747
|
-
# Compiles in production mode by default unless NODE_ENV is specified, per `lib/tasks/
|
|
771
|
+
# Compiles in production mode by default unless NODE_ENV is specified, per `lib/tasks/shakapacker/compile.rake`
|
|
748
772
|
bundle exec rails assets:precompile
|
|
749
|
-
bundle exec rails
|
|
773
|
+
bundle exec rails shakapacker:compile
|
|
750
774
|
```
|
|
751
775
|
|
|
752
776
|
### Upgrading
|
|
753
777
|
|
|
754
|
-
You can run following commands to upgrade Shakapacker to the latest stable version. This process involves upgrading the gem and related JavaScript packages:
|
|
778
|
+
You can run the following commands to upgrade Shakapacker to the latest stable version. This process involves upgrading the gem and related JavaScript packages:
|
|
755
779
|
|
|
756
780
|
```bash
|
|
757
781
|
# check your Gemfile for version restrictions
|
|
758
782
|
bundle update shakapacker
|
|
759
783
|
|
|
760
784
|
# overwrite your changes to the default install files and revert any unwanted changes from the install
|
|
761
|
-
rails
|
|
785
|
+
rails shakapacker:install
|
|
762
786
|
|
|
763
787
|
# yarn 1 instructions
|
|
764
788
|
yarn upgrade shakapacker --latest
|
|
@@ -776,22 +800,22 @@ Also, consult the [CHANGELOG](./CHANGELOG.md) for additional upgrade links.
|
|
|
776
800
|
|
|
777
801
|
### Paths
|
|
778
802
|
|
|
779
|
-
By default, Shakapacker ships with simple conventions for where the JavaScript app files and compiled webpack bundles will go in your Rails app. All these options are configurable from `config/
|
|
803
|
+
By default, Shakapacker ships with simple conventions for where the JavaScript app files and compiled webpack bundles will go in your Rails app. All these options are configurable from `config/shakapacker.yml` file.
|
|
780
804
|
|
|
781
|
-
The configuration for what webpack is supposed to compile by default rests on the convention that every file in `app/javascript/`**(default)** or whatever path you set for `source_entry_path` in the `
|
|
805
|
+
The configuration for what webpack is supposed to compile by default rests on the convention that every file in `app/javascript/`**(default)** or whatever path you set for `source_entry_path` in the `shakapacker.yml` configuration is turned into their own output files (or entry points, as webpack calls it). Therefore you don't want to put any file inside `app/javascript` directory that you do not want to be an entry file. As a rule of thumb, put all files you want to link in your views inside "app/javascript/" directory and keep everything else under subdirectories like `app/javascript/controllers`.
|
|
782
806
|
|
|
783
807
|
Suppose you want to change the source directory from `app/javascript` to `frontend` and output to `assets/packs`. This is how you would do it:
|
|
784
808
|
|
|
785
809
|
```yml
|
|
786
|
-
# config/
|
|
810
|
+
# config/shakapacker.yml
|
|
787
811
|
source_path: frontend # packs are the files in frontend/
|
|
788
812
|
public_output_path: assets/packs # outputs to => public/assets/packs
|
|
789
813
|
```
|
|
790
814
|
|
|
791
|
-
Similarly you can also control and configure `webpack-dev-server` settings from `config/
|
|
815
|
+
Similarly, you can also control and configure `webpack-dev-server` settings from `config/shakapacker.yml` file:
|
|
792
816
|
|
|
793
817
|
```yml
|
|
794
|
-
# config/
|
|
818
|
+
# config/shakapacker.yml
|
|
795
819
|
development:
|
|
796
820
|
dev_server:
|
|
797
821
|
host: localhost
|
|
@@ -804,7 +828,7 @@ If you want to have HMR and separate link tags, set `hmr: true` and `inline_css:
|
|
|
804
828
|
|
|
805
829
|
### Additional paths
|
|
806
830
|
|
|
807
|
-
If you are adding Shakapacker to an existing app that has most of the assets inside `app/assets` or inside an engine, and you want to share that with webpack modules, you can use the `additional_paths` option available in `config/
|
|
831
|
+
If you are adding Shakapacker to an existing app that has most of the assets inside `app/assets` or inside an engine, and you want to share that with webpack modules, you can use the `additional_paths` option available in `config/shakapacker.yml`. This lets you
|
|
808
832
|
add additional paths that webpack should look up when resolving modules:
|
|
809
833
|
|
|
810
834
|
```yml
|
|
@@ -819,20 +843,20 @@ import 'stylesheets/main'
|
|
|
819
843
|
import 'images/rails.png'
|
|
820
844
|
```
|
|
821
845
|
|
|
822
|
-
**Note:** Please be careful when adding paths here otherwise it will make the compilation slow, consider adding specific paths instead of whole parent directory if you just need to reference one or two modules
|
|
846
|
+
**Note:** Please be careful when adding paths here otherwise it will make the compilation slow, consider adding specific paths instead of the whole parent directory if you just need to reference one or two modules
|
|
823
847
|
|
|
824
|
-
**Also note:** While importing assets living outside your `source_path` defined in
|
|
848
|
+
**Also note:** While importing assets living outside your `source_path` defined in shakapacker.yml (like, for instance, assets under `app/assets`) from within your packs using _relative_ paths like `import '../../assets/javascripts/file.js'` will work in development, Shakapacker won't recompile the bundle in production unless a file that lives in one of it's watched paths has changed (check out `Shakapacker::MtimeStrategy#latest_modified_timestamp` or `Shakapacker::DigestStrategy#watched_files_digest` depending on strategy configured by `compiler_strategy` option in `shakapacker.yml`). That's why you'd need to add `app/assets` to the additional_paths as stated above and use `import 'javascripts/file.js'` instead.
|
|
825
849
|
|
|
826
850
|
|
|
827
851
|
## Deployment
|
|
828
852
|
|
|
829
|
-
Shakapacker hooks up a new `
|
|
853
|
+
Shakapacker hooks up a new `shakapacker:compile` task to `assets:precompile`, which gets run whenever you run `assets:precompile`. If you are not using Sprockets, `shakapacker:compile` is automatically aliased to `assets:precompile`. Similar to sprockets both rake tasks will compile packs in production mode but will use `RAILS_ENV` to load configuration from `config/shakapacker.yml` (if available).
|
|
830
854
|
|
|
831
|
-
This behavior is optional & can be disabled by either setting
|
|
855
|
+
This behavior is optional & can be disabled by either setting a `SHAKAPACKER_PRECOMPILE` environment variable to `false`, `no`, `n`, or `f`, or by setting a `shakapacker_precompile` key in your `shakapacker.yml` to `false`. ([source code](./lib/shakapacker/configuration.rb#L34))
|
|
832
856
|
|
|
833
857
|
When compiling assets for production on a remote server, such as a continuous integration environment, it's recommended to use `yarn install --frozen-lockfile` to install NPM packages on the remote host to ensure that the installed packages match the `yarn.lock` file.
|
|
834
858
|
|
|
835
|
-
If you are using a CDN setup,
|
|
859
|
+
If you are using a CDN setup, Shakapacker does NOT use the `ASSET_HOST` environment variable to prefix URLs for assets during bundle compilation. You must use the `SHAKAPACKER_ASSET_HOST` environment variable instead (`WEBPACKER_ASSET_HOST` if you're using any version of Webpacker or Shakapacker before Shakapacker v7).
|
|
836
860
|
|
|
837
861
|
## Example Apps
|
|
838
862
|
* [React on Rails Tutorial With SSR, HMR fast refresh, and TypeScript](https://github.com/shakacode/react_on_rails_tutorial_with_ssr_and_hmr_fast_refresh)
|
|
@@ -844,14 +868,19 @@ See the doc page for [Troubleshooting](./docs/troubleshooting.md).
|
|
|
844
868
|
|
|
845
869
|
## Contributing
|
|
846
870
|
|
|
847
|
-
We encourage you to contribute to Shakapacker
|
|
871
|
+
We encourage you to contribute to Shakapacker! See [CONTRIBUTING](CONTRIBUTING.md) for guidelines about how to proceed. We have a [Slack discussion channel](https://reactrails.slack.com/join/shared_invite/enQtNjY3NTczMjczNzYxLTlmYjdiZmY3MTVlMzU2YWE0OWM0MzNiZDI0MzdkZGFiZTFkYTFkOGVjODBmOWEyYWQ3MzA2NGE1YWJjNmVlMGE).
|
|
848
872
|
|
|
849
873
|
## License
|
|
850
874
|
|
|
851
|
-
|
|
875
|
+
Shakapacker is released under the [MIT License](https://opensource.org/licenses/MIT).
|
|
852
876
|
|
|
853
877
|
## Supporters
|
|
854
878
|
|
|
879
|
+
The following companies support our Open Source projects, and ShakaCode uses their products!
|
|
880
|
+
|
|
881
|
+
<br />
|
|
882
|
+
<br />
|
|
883
|
+
|
|
855
884
|
<a href="https://www.jetbrains.com">
|
|
856
885
|
<img src="https://user-images.githubusercontent.com/4244251/184881139-42e4076b-024b-4b30-8c60-c3cd0e758c0a.png" alt="JetBrains" height="120px">
|
|
857
886
|
</a>
|
|
@@ -876,8 +905,6 @@ Webpacker is released under the [MIT License](https://opensource.org/licenses/MI
|
|
|
876
905
|
<a href="https://www.honeybadger.io">
|
|
877
906
|
<img src="https://user-images.githubusercontent.com/4244251/184881133-79ee9c3c-8165-4852-958e-31687b9536f4.png" alt="Honeybadger" height="55px">
|
|
878
907
|
</a>
|
|
879
|
-
|
|
880
|
-
<
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
The following companies support our open source projects, and ShakaCode uses their products!
|
|
908
|
+
<a href="https://reviewable.io">
|
|
909
|
+
<img src="https://user-images.githubusercontent.com/20628911/230848305-c94510a4-82d7-468f-bf9f-eeb81d3f2ce0.png" alt="Reviewable" height="55px">
|
|
910
|
+
</a>
|
data/Rakefile
CHANGED
|
@@ -1,10 +1,51 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
require "bundler/gem_tasks"
|
|
3
|
+
require "pathname"
|
|
3
4
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
RSpec::Core::RakeTask.new(:test)
|
|
7
|
-
rescue LoadError
|
|
8
|
-
end
|
|
5
|
+
desc "Run all specs"
|
|
6
|
+
task test: ["run_spec:all_specs"]
|
|
9
7
|
|
|
10
8
|
task default: :test
|
|
9
|
+
|
|
10
|
+
namespace :run_spec do
|
|
11
|
+
desc "Run shakapacker specs"
|
|
12
|
+
task :gem do
|
|
13
|
+
puts "Running Shakapacker gem specs"
|
|
14
|
+
sh("bundle exec rspec spec/shakapacker/*_spec.rb")
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
desc "Run backward compatibility specs"
|
|
18
|
+
task :gem_bc do
|
|
19
|
+
puts "Running Shakapacker gem specs for backward compatibility"
|
|
20
|
+
sh("bundle exec rspec spec/backward_compatibility_specs/*_spec.rb")
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
desc "Run specs in the dummy app"
|
|
24
|
+
task :dummy do
|
|
25
|
+
puts "Running dummy app specs"
|
|
26
|
+
spec_dummy_dir = Pathname.new(File.join("spec", "dummy")).realpath
|
|
27
|
+
Bundler.with_unbundled_env do
|
|
28
|
+
sh_in_dir(".", "yalc publish")
|
|
29
|
+
sh_in_dir(spec_dummy_dir, [
|
|
30
|
+
"bundle install",
|
|
31
|
+
"yalc link shakapacker",
|
|
32
|
+
"yarn install",
|
|
33
|
+
"bundle exec rspec"
|
|
34
|
+
])
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
desc "Run generator specs"
|
|
39
|
+
task :generator do
|
|
40
|
+
sh("bundle exec rspec spec/generator_specs/*_spec.rb")
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
desc "Run all specs"
|
|
44
|
+
task all_specs: %i[gem gem_bc dummy generator] do
|
|
45
|
+
puts "Completed all RSpec tests"
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def sh_in_dir(dir, *shell_commands)
|
|
50
|
+
Shakapacker::Utils::Misc.sh_in_dir(dir, *shell_commands)
|
|
51
|
+
end
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
../lib/install/config/shakapacker.yml
|