shakapacker 6.5.4 → 7.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.eslintrc.js +1 -0
- data/.github/FUNDING.yml +1 -0
- data/.github/ISSUE_TEMPLATE/bug_report.md +11 -7
- data/.github/ISSUE_TEMPLATE/feature_request.md +21 -0
- data/.github/PULL_REQUEST_TEMPLATE.md +14 -0
- 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 +5 -7
- data/.gitignore +6 -3
- data/.rspec +1 -0
- data/CHANGELOG.md +83 -2
- data/CONTRIBUTING.md +84 -18
- data/Gemfile.development_dependencies +3 -1
- data/README.md +159 -97
- data/Rakefile +46 -6
- 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 +3 -3
- 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 +9 -13
- data/docs/v7_upgrade.md +59 -0
- data/gemfiles/Gemfile-rails-edge +1 -1
- data/gemfiles/Gemfile-rails.6.0.x +1 -1
- data/gemfiles/Gemfile-rails.6.1.x +1 -1
- data/gemfiles/Gemfile-rails.7.0.x +1 -1
- 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} +28 -11
- data/lib/install/config/webpack/webpack.config.js +3 -2
- data/lib/install/template.rb +51 -34
- 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 +40 -29
- data/lib/shakapacker/instance.rb +50 -0
- 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 +28 -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 -38
- 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-bc.js +22 -0
- 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 +15 -15
- data/package/environments/__tests__/development.js +53 -0
- data/package/environments/__tests__/production.js +92 -0
- data/package/environments/base.js +5 -4
- data/package/environments/development.js +4 -46
- data/package/environments/production.js +10 -1
- data/package/index.js +35 -5
- data/package/rules/__tests__/__utils__/webpack.js +50 -0
- data/package/rules/__tests__/babel.js +63 -0
- data/package/rules/__tests__/esbuild.js +64 -0
- data/package/rules/__tests__/file.js +27 -0
- data/package/rules/__tests__/index.js +0 -4
- data/package/rules/__tests__/swc.js +63 -0
- data/package/rules/babel.js +13 -24
- data/package/rules/esbuild.js +2 -13
- data/package/rules/file.js +2 -2
- data/package/rules/jscommon.js +26 -0
- data/package/rules/swc.js +2 -13
- 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 +11 -5
- data/{webpacker.gemspec → shakapacker.gemspec} +3 -3
- data/spec/backward_compatibility_specs/command_spec.rb +116 -0
- data/spec/backward_compatibility_specs/compiler_spec.rb +59 -0
- data/spec/backward_compatibility_specs/compiler_strategy_spec.rb +22 -0
- data/spec/backward_compatibility_specs/configuration_spec.rb +286 -0
- data/{test/dev_server_runner_test.rb → spec/backward_compatibility_specs/dev_server_runner_spec.rb} +37 -39
- data/spec/backward_compatibility_specs/dev_server_spec.rb +47 -0
- data/spec/backward_compatibility_specs/digest_strategy_spec.rb +35 -0
- data/spec/backward_compatibility_specs/engine_rake_tasks_spec.rb +44 -0
- data/spec/backward_compatibility_specs/env_spec.rb +23 -0
- data/spec/backward_compatibility_specs/helper_spec.rb +243 -0
- data/spec/backward_compatibility_specs/instance_spec.rb +31 -0
- data/spec/backward_compatibility_specs/manifest_spec.rb +100 -0
- data/spec/backward_compatibility_specs/mtime_strategy_spec.rb +55 -0
- data/spec/backward_compatibility_specs/rake_tasks_spec.rb +37 -0
- data/spec/backward_compatibility_specs/spec_helper_initializer.rb +24 -0
- data/{test/webpack_runner_test.rb → spec/backward_compatibility_specs/webpack_runner_spec.rb} +15 -16
- data/spec/backward_compatibility_specs/webpacker_spec.rb +41 -0
- data/spec/backward_compatibility_specs/webpacker_test_app/.gitignore +2 -0
- data/{test/test_app → spec/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/{test/test_app → spec/backward_compatibility_specs/webpacker_test_app}/config/webpacker.yml +1 -1
- data/{test/test_app → spec/backward_compatibility_specs/webpacker_test_app}/config/webpacker_css_extract_ignore_order_warnings.yml +1 -1
- data/{test/test_app → spec/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/backward_compatibility_specs/webpacker_test_app/config/webpacker_other_location.yml +85 -0
- data/{test/test_app → spec/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/{test/test_app → spec/backward_compatibility_specs/webpacker_test_app}/public/packs/manifest.json +8 -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/{test → spec}/mounted_app/test/dummy/config/application.rb +1 -1
- data/{test → spec}/mounted_app/test/dummy/config/webpacker.yml +11 -5
- 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/{test/test_app/bin/webpacker-dev-server → spec/shakapacker/test_app/bin/shakapacker} +3 -3
- data/{test/test_app/bin/webpacker → spec/shakapacker/test_app/bin/shakapacker-dev-server} +3 -3
- data/{test → spec/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/{test/test_app/config/webpacker_other_location.yml → spec/shakapacker/test_app/config/shakapacker_manifest_path.yml} +6 -5
- 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/shakapacker/version_checker_spec.rb +951 -0
- data/spec/shakapacker/webpack_runner_spec.rb +55 -0
- data/spec/spec_helper.rb +98 -0
- data/yarn.lock +846 -844
- metadata +314 -213
- data/.github/ISSUE_TEMPLATE/feature-request.md +0 -18
- data/config/webpacker.yml +0 -1
- data/gemfiles/Gemfile-rails.5.2.x +0 -9
- data/lib/tasks/yarn.rake +0 -44
- data/lib/webpacker/instance.rb +0 -45
- 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/test/command_test.rb +0 -109
- data/test/compiler_strategy_test.rb +0 -27
- data/test/compiler_test.rb +0 -60
- data/test/configuration_test.rb +0 -186
- data/test/dev_server_test.rb +0 -47
- data/test/digest_strategy_test.rb +0 -33
- data/test/engine_rake_tasks_test.rb +0 -39
- data/test/env_test.rb +0 -23
- data/test/helper_test.rb +0 -248
- data/test/manifest_test.rb +0 -89
- data/test/mtime_strategy_test.rb +0 -42
- data/test/rake_tasks_test.rb +0 -37
- data/test/test_app/config/webpacker_no_precompile.yml +0 -7
- data/test/test_helper.rb +0 -33
- data/test/version_checker_test.rb +0 -826
- data/test/webpacker_test.rb +0 -49
- /data/{test/mounted_app/test/dummy → spec/backward_compatibility_specs/webpacker_test_app}/Rakefile +0 -0
- /data/{test/test_app → spec/backward_compatibility_specs/webpacker_test_app}/app/packs/entrypoints/generated/something.js +0 -0
- /data/{test/test_app → spec/backward_compatibility_specs/webpacker_test_app}/app/packs/entrypoints/multi_entry.css +0 -0
- /data/{test/test_app → spec/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/{test/test_app → spec/backward_compatibility_specs/webpacker_test_app}/config/environment.rb +0 -0
- /data/{test/test_app → spec/backward_compatibility_specs/webpacker_test_app}/config/initializers/inspect_autoload_paths.rb +0 -0
- /data/{test/test_app → spec/backward_compatibility_specs/webpacker_test_app}/config/webpack/webpack.config.js +0 -0
- /data/{test/test_app → spec/backward_compatibility_specs/webpacker_test_app}/config/webpacker_manifest_path.yml +0 -0
- /data/{test/test_app → spec/backward_compatibility_specs/webpacker_test_app}/config/webpacker_nested_entries.yml +0 -0
- /data/{test/mounted_app/test/dummy → spec/backward_compatibility_specs/webpacker_test_app}/config.ru +0 -0
- /data/{test/test_app → spec/backward_compatibility_specs/webpacker_test_app}/some.config.js +0 -0
- /data/{test/test_app → spec/backward_compatibility_specs/webpacker_test_app}/yarn.lock +0 -0
- /data/{test → spec}/fixtures/beta_package-lock.v1.json +0 -0
- /data/{test → spec}/fixtures/beta_package-lock.v2.json +0 -0
- /data/{test → spec}/fixtures/beta_package.json +0 -0
- /data/{test → spec}/fixtures/beta_yarn.v1.lock +0 -0
- /data/{test → spec}/fixtures/beta_yarn.v2.lock +0 -0
- /data/{test → spec}/fixtures/git_url_package-lock.v1.json +0 -0
- /data/{test → spec}/fixtures/git_url_package-lock.v2.json +0 -0
- /data/{test → spec}/fixtures/git_url_package.json +0 -0
- /data/{test → spec}/fixtures/git_url_yarn.v1.lock +0 -0
- /data/{test → spec}/fixtures/git_url_yarn.v2.lock +0 -0
- /data/{test → spec}/fixtures/github_url_package-lock.v1.json +0 -0
- /data/{test → spec}/fixtures/github_url_package-lock.v2.json +0 -0
- /data/{test → spec}/fixtures/github_url_package.json +0 -0
- /data/{test → spec}/fixtures/github_url_yarn.v1.lock +0 -0
- /data/{test → spec}/fixtures/github_url_yarn.v2.lock +0 -0
- /data/{test → spec}/fixtures/relative_path_package-lock.v1.json +0 -0
- /data/{test → spec}/fixtures/relative_path_package-lock.v2.json +0 -0
- /data/{test → spec}/fixtures/relative_path_package.json +0 -0
- /data/{test → spec}/fixtures/relative_path_yarn.v1.lock +0 -0
- /data/{test → spec}/fixtures/relative_path_yarn.v2.lock +0 -0
- /data/{test → spec}/fixtures/semver_caret_package-lock.v1.json +0 -0
- /data/{test → spec}/fixtures/semver_caret_package-lock.v2.json +0 -0
- /data/{test → spec}/fixtures/semver_caret_package.json +0 -0
- /data/{test → spec}/fixtures/semver_caret_yarn.v1.lock +0 -0
- /data/{test → spec}/fixtures/semver_caret_yarn.v2.lock +0 -0
- /data/{test → spec}/fixtures/semver_exact_package-lock.v1.json +0 -0
- /data/{test → spec}/fixtures/semver_exact_package-lock.v2.json +0 -0
- /data/{test → spec}/fixtures/semver_exact_package.json +0 -0
- /data/{test → spec}/fixtures/semver_exact_yarn.v1.lock +0 -0
- /data/{test → spec}/fixtures/semver_exact_yarn.v2.lock +0 -0
- /data/{test → spec}/fixtures/semver_tilde_package-lock.v1.json +0 -0
- /data/{test → spec}/fixtures/semver_tilde_package-lock.v2.json +0 -0
- /data/{test → spec}/fixtures/semver_tilde_package.json +0 -0
- /data/{test → spec}/fixtures/semver_tilde_yarn.v1.lock +0 -0
- /data/{test → spec}/fixtures/semver_tilde_yarn.v2.lock +0 -0
- /data/{test → spec}/fixtures/without_package-lock.v1.json +0 -0
- /data/{test → spec}/fixtures/without_package-lock.v2.json +0 -0
- /data/{test → spec}/fixtures/without_package.json +0 -0
- /data/{test → spec}/fixtures/without_yarn.v1.lock +0 -0
- /data/{test → spec}/fixtures/without_yarn.v2.lock +0 -0
- /data/{test → spec}/mounted_app/Rakefile +0 -0
- /data/{test/test_app → spec/mounted_app/test/dummy}/Rakefile +0 -0
- /data/{test → spec}/mounted_app/test/dummy/bin/rails +0 -0
- /data/{test → spec}/mounted_app/test/dummy/bin/rake +0 -0
- /data/{test → spec}/mounted_app/test/dummy/config/environment.rb +0 -0
- /data/{test/test_app → spec/mounted_app/test/dummy}/config.ru +0 -0
- /data/{test → spec}/mounted_app/test/dummy/package.json +0 -0
- /data/{test → spec/shakapacker}/test_app/package.json +0 -0
@@ -0,0 +1,107 @@
|
|
1
|
+
/* global test expect, describe, afterAll, beforeEach */
|
2
|
+
|
3
|
+
// environment.js expects to find config/webapacker.yml and resolved modules from
|
4
|
+
// the root of a Rails project
|
5
|
+
|
6
|
+
const { resetEnv, chdirWebpackerTestApp } = require('../../utils/helpers')
|
7
|
+
|
8
|
+
const rootPath = process.cwd()
|
9
|
+
chdirWebpackerTestApp()
|
10
|
+
|
11
|
+
const { resolve } = require('path')
|
12
|
+
|
13
|
+
const baseConfig = require('../base')
|
14
|
+
const config = require("../../config");
|
15
|
+
|
16
|
+
describe('Base config', () => {
|
17
|
+
beforeEach(() => jest.resetModules() && resetEnv())
|
18
|
+
afterAll(() => process.chdir(rootPath))
|
19
|
+
|
20
|
+
describe('config', () => {
|
21
|
+
test('should return entry', () => {
|
22
|
+
expect(baseConfig.entry.application).toEqual(
|
23
|
+
resolve('app', 'packs', 'entrypoints', 'application.js')
|
24
|
+
)
|
25
|
+
})
|
26
|
+
|
27
|
+
test('should return false for css_extract_ignore_order_warnings when using default config', () => {
|
28
|
+
expect(config.css_extract_ignore_order_warnings).toEqual(false)
|
29
|
+
})
|
30
|
+
|
31
|
+
test('should return true for css_extract_ignore_order_warnings when configured', () => {
|
32
|
+
process.env.WEBPACKER_CONFIG = 'config/webpacker_css_extract_ignore_order_warnings.yml'
|
33
|
+
const config = require("../../config");
|
34
|
+
|
35
|
+
expect(config.css_extract_ignore_order_warnings).toEqual(true)
|
36
|
+
})
|
37
|
+
|
38
|
+
test('should return only 2 entry points with config.nested_entries == false', () => {
|
39
|
+
expect(config.nested_entries).toEqual(false)
|
40
|
+
|
41
|
+
expect(baseConfig.entry.multi_entry.sort()).toEqual([
|
42
|
+
resolve('app', 'packs', 'entrypoints', 'multi_entry.css'),
|
43
|
+
resolve('app', 'packs', 'entrypoints', 'multi_entry.js')
|
44
|
+
])
|
45
|
+
expect(baseConfig.entry['generated/something']).toEqual(undefined)
|
46
|
+
})
|
47
|
+
|
48
|
+
test('should returns top level and nested entry points with config.nested_entries == true', () => {
|
49
|
+
process.env.WEBPACKER_CONFIG = 'config/webpacker_nested_entries.yml'
|
50
|
+
const config = require("../../config");
|
51
|
+
const baseConfig = require('../base')
|
52
|
+
|
53
|
+
expect(config.nested_entries).toEqual(true)
|
54
|
+
|
55
|
+
expect(baseConfig.entry.application).toEqual(
|
56
|
+
resolve('app', 'packs', 'entrypoints', 'application.js')
|
57
|
+
)
|
58
|
+
expect(baseConfig.entry.multi_entry.sort()).toEqual([
|
59
|
+
resolve('app', 'packs', 'entrypoints', 'multi_entry.css'),
|
60
|
+
resolve('app', 'packs', 'entrypoints', 'multi_entry.js')
|
61
|
+
])
|
62
|
+
expect(baseConfig.entry['generated/something']).toEqual(
|
63
|
+
resolve('app', 'packs', 'entrypoints', 'generated', 'something.js')
|
64
|
+
)
|
65
|
+
})
|
66
|
+
|
67
|
+
test('should return output', () => {
|
68
|
+
expect(baseConfig.output.filename).toEqual('js/[name]-[contenthash].js')
|
69
|
+
expect(baseConfig.output.chunkFilename).toEqual(
|
70
|
+
'js/[name]-[contenthash].chunk.js'
|
71
|
+
)
|
72
|
+
})
|
73
|
+
|
74
|
+
test('should return default loader rules for each file in config/loaders', () => {
|
75
|
+
const rules = require('../../rules')
|
76
|
+
|
77
|
+
const defaultRules = Object.keys(rules)
|
78
|
+
const configRules = baseConfig.module.rules
|
79
|
+
|
80
|
+
expect(defaultRules.length).toEqual(3)
|
81
|
+
expect(configRules.length).toEqual(3)
|
82
|
+
})
|
83
|
+
|
84
|
+
test('should return default plugins', () => {
|
85
|
+
expect(baseConfig.plugins.length).toEqual(2)
|
86
|
+
})
|
87
|
+
|
88
|
+
test('should return default resolveLoader', () => {
|
89
|
+
expect(baseConfig.resolveLoader.modules).toEqual(['node_modules'])
|
90
|
+
})
|
91
|
+
|
92
|
+
test('should return default resolve.modules with additions', () => {
|
93
|
+
expect(baseConfig.resolve.modules).toEqual([
|
94
|
+
resolve('app', 'packs'),
|
95
|
+
resolve('app/assets'),
|
96
|
+
resolve('/etc/yarn'),
|
97
|
+
resolve('some.config.js'),
|
98
|
+
resolve('app/elm'),
|
99
|
+
'node_modules'
|
100
|
+
])
|
101
|
+
})
|
102
|
+
|
103
|
+
test('returns plugins property as Array', () => {
|
104
|
+
expect(baseConfig.plugins).toBeInstanceOf(Array)
|
105
|
+
})
|
106
|
+
})
|
107
|
+
})
|
@@ -1,10 +1,11 @@
|
|
1
1
|
/* global test expect, describe, afterAll, beforeEach */
|
2
2
|
|
3
|
-
// environment.js expects to find config/
|
3
|
+
// environment.js expects to find config/shakapacker.yml and resolved modules from
|
4
4
|
// the root of a Rails project
|
5
5
|
|
6
6
|
const { chdirTestApp, chdirCwd, resetEnv } = require('../../utils/helpers')
|
7
7
|
|
8
|
+
const rootPath = process.cwd()
|
8
9
|
chdirTestApp()
|
9
10
|
|
10
11
|
const { resolve } = require('path')
|
@@ -14,13 +15,12 @@ const config = require("../../config");
|
|
14
15
|
|
15
16
|
describe('Base config', () => {
|
16
17
|
beforeEach(() => jest.resetModules() && resetEnv())
|
17
|
-
|
18
|
-
afterAll(chdirCwd)
|
18
|
+
afterAll(() => process.chdir(rootPath))
|
19
19
|
|
20
20
|
describe('config', () => {
|
21
21
|
test('should return entry', () => {
|
22
22
|
expect(baseConfig.entry.application).toEqual(
|
23
|
-
resolve('app', '
|
23
|
+
resolve('app', 'javascript', 'entrypoints', 'application.js')
|
24
24
|
)
|
25
25
|
})
|
26
26
|
|
@@ -29,7 +29,7 @@ describe('Base config', () => {
|
|
29
29
|
})
|
30
30
|
|
31
31
|
test('should return true for css_extract_ignore_order_warnings when configured', () => {
|
32
|
-
process.env.
|
32
|
+
process.env.SHAKAPACKER_CONFIG = 'config/shakapacker_css_extract_ignore_order_warnings.yml'
|
33
33
|
const config = require("../../config");
|
34
34
|
|
35
35
|
expect(config.css_extract_ignore_order_warnings).toEqual(true)
|
@@ -39,35 +39,35 @@ describe('Base config', () => {
|
|
39
39
|
expect(config.nested_entries).toEqual(false)
|
40
40
|
|
41
41
|
expect(baseConfig.entry.multi_entry.sort()).toEqual([
|
42
|
-
resolve('app', '
|
43
|
-
resolve('app', '
|
42
|
+
resolve('app', 'javascript', 'entrypoints', 'multi_entry.css'),
|
43
|
+
resolve('app', 'javascript', 'entrypoints', 'multi_entry.js')
|
44
44
|
])
|
45
45
|
expect(baseConfig.entry['generated/something']).toEqual(undefined)
|
46
46
|
})
|
47
47
|
|
48
48
|
test('should returns top level and nested entry points with config.nested_entries == true', () => {
|
49
|
-
process.env.
|
49
|
+
process.env.SHAKAPACKER_CONFIG = 'config/shakapacker_nested_entries.yml'
|
50
50
|
const config = require("../../config");
|
51
51
|
const baseConfig = require('../base')
|
52
52
|
|
53
53
|
expect(config.nested_entries).toEqual(true)
|
54
54
|
|
55
55
|
expect(baseConfig.entry.application).toEqual(
|
56
|
-
resolve('app', '
|
56
|
+
resolve('app', 'javascript', 'entrypoints', 'application.js')
|
57
57
|
)
|
58
58
|
expect(baseConfig.entry.multi_entry.sort()).toEqual([
|
59
|
-
resolve('app', '
|
60
|
-
resolve('app', '
|
59
|
+
resolve('app', 'javascript', 'entrypoints', 'multi_entry.css'),
|
60
|
+
resolve('app', 'javascript', 'entrypoints', 'multi_entry.js')
|
61
61
|
])
|
62
62
|
expect(baseConfig.entry['generated/something']).toEqual(
|
63
|
-
resolve('app', '
|
63
|
+
resolve('app', 'javascript', 'entrypoints', 'generated', 'something.js')
|
64
64
|
)
|
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
|
|
@@ -91,7 +91,7 @@ describe('Base config', () => {
|
|
91
91
|
|
92
92
|
test('should return default resolve.modules with additions', () => {
|
93
93
|
expect(baseConfig.resolve.modules).toEqual([
|
94
|
-
resolve('app', '
|
94
|
+
resolve('app', 'javascript'),
|
95
95
|
resolve('app/assets'),
|
96
96
|
resolve('/etc/yarn'),
|
97
97
|
resolve('some.config.js'),
|
@@ -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,92 @@
|
|
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
|
+
test("doesn't shows any warning message", () => {
|
28
|
+
const consoleWarnSpy = jest.spyOn(console, 'warn');
|
29
|
+
const config = require("../../config");
|
30
|
+
config.useContentHash = true
|
31
|
+
const environmnetConfig = require('../production')
|
32
|
+
|
33
|
+
expect(consoleWarnSpy).not.toHaveBeenCalledWith(
|
34
|
+
expect.stringMatching(/Setting 'useContentHash' to 'false' in the production environment/)
|
35
|
+
)
|
36
|
+
|
37
|
+
consoleWarnSpy.mockRestore()
|
38
|
+
})
|
39
|
+
})
|
40
|
+
|
41
|
+
describe('with config.useContentHash = false', () => {
|
42
|
+
test('sets filename to use contentHash', () => {
|
43
|
+
const config = require("../../config");
|
44
|
+
config.useContentHash = false
|
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
|
+
test('shows a warning message', () => {
|
54
|
+
const consoleWarnSpy = jest.spyOn(console, 'warn');
|
55
|
+
const config = require("../../config");
|
56
|
+
config.useContentHash = false
|
57
|
+
const environmnetConfig = require('../production')
|
58
|
+
|
59
|
+
expect(consoleWarnSpy).toHaveBeenCalledWith(
|
60
|
+
expect.stringMatching(/Setting 'useContentHash' to 'false' in the production environment/)
|
61
|
+
)
|
62
|
+
|
63
|
+
consoleWarnSpy.mockRestore()
|
64
|
+
})
|
65
|
+
})
|
66
|
+
|
67
|
+
describe('with unset config.useContentHash', () => {
|
68
|
+
test('sets filename to use contentHash', () => {
|
69
|
+
const config = require("../../config");
|
70
|
+
delete config.useContentHash
|
71
|
+
const environmnetConfig = require('../production')
|
72
|
+
|
73
|
+
expect(environmnetConfig.output.filename).toEqual('js/[name]-[contenthash].js')
|
74
|
+
expect(environmnetConfig.output.chunkFilename).toEqual(
|
75
|
+
'js/[name]-[contenthash].chunk.js'
|
76
|
+
)
|
77
|
+
})
|
78
|
+
|
79
|
+
test("doesn't shows any warning message", () => {
|
80
|
+
const consoleWarnSpy = jest.spyOn(console, 'warn');
|
81
|
+
const config = require("../../config");
|
82
|
+
delete config.useContentHash
|
83
|
+
const environmnetConfig = require('../production')
|
84
|
+
|
85
|
+
expect(consoleWarnSpy).not.toHaveBeenCalledWith(
|
86
|
+
expect.stringMatching(/Setting 'useContentHash' to 'false' in the production environment/)
|
87
|
+
)
|
88
|
+
|
89
|
+
consoleWarnSpy.mockRestore()
|
90
|
+
})
|
91
|
+
})
|
92
|
+
})
|
@@ -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 = () => {
|
@@ -16,7 +16,7 @@ const getEntryObject = () => {
|
|
16
16
|
const rootPath = join(config.source_path, config.source_entry_path)
|
17
17
|
if (config.source_entry_path === '/' && config.nested_entries) {
|
18
18
|
throw new Error(
|
19
|
-
"Your
|
19
|
+
"Your shakapacker config specified using a source_entry_path of '/' with 'nested_entries' == " +
|
20
20
|
"'true'. Doing this would result in packs for every one of your source files"
|
21
21
|
)
|
22
22
|
}
|
@@ -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: {
|
@@ -1,55 +1,13 @@
|
|
1
1
|
const { merge } = require('webpack-merge')
|
2
2
|
|
3
3
|
const baseConfig = require('./base')
|
4
|
-
const
|
4
|
+
const webpackDevServerConfig = require('../webpackDevServerConfig')
|
5
5
|
const { runningWebpackDevServer } = require('../env')
|
6
6
|
|
7
|
-
const
|
8
|
-
|
9
|
-
let devConfig = {
|
7
|
+
const devConfig = {
|
10
8
|
mode: 'development',
|
11
|
-
devtool: 'cheap-module-source-map'
|
12
|
-
}
|
13
|
-
|
14
|
-
if (runningWebpackDevServer) {
|
15
|
-
const liveReload = devServer.live_reload !== undefined ? devServer.live_reload : !devServer.hmr
|
16
|
-
|
17
|
-
const devServerConfig = {
|
18
|
-
devMiddleware: {
|
19
|
-
publicPath
|
20
|
-
},
|
21
|
-
compress: devServer.compress,
|
22
|
-
allowedHosts: devServer.allowed_hosts,
|
23
|
-
host: devServer.host,
|
24
|
-
port: devServer.port,
|
25
|
-
https: devServer.https,
|
26
|
-
hot: devServer.hmr,
|
27
|
-
liveReload,
|
28
|
-
historyApiFallback: { disableDotRule: true },
|
29
|
-
headers: devServer.headers,
|
30
|
-
static: {
|
31
|
-
publicPath: contentBase
|
32
|
-
}
|
33
|
-
}
|
34
|
-
|
35
|
-
if (devServer.static) {
|
36
|
-
devServerConfig.static = { ...devServerConfig.static, ...devServer.static }
|
37
|
-
}
|
38
|
-
|
39
|
-
if (devServer.client) {
|
40
|
-
devServerConfig.client = devServer.client
|
41
|
-
}
|
42
|
-
|
43
|
-
devConfig = merge(devConfig, {
|
44
|
-
stats: {
|
45
|
-
colors: true,
|
46
|
-
entrypoints: false,
|
47
|
-
errorDetails: true,
|
48
|
-
modules: false,
|
49
|
-
moduleTrace: false
|
50
|
-
},
|
51
|
-
devServer: devServerConfig
|
52
|
-
})
|
9
|
+
devtool: 'cheap-module-source-map',
|
10
|
+
...(runningWebpackDevServer && { devServer: webpackDevServerConfig() })
|
53
11
|
}
|
54
12
|
|
55
13
|
module.exports = merge(baseConfig, devConfig)
|
@@ -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 = []
|
@@ -52,7 +53,7 @@ const productionConfig = {
|
|
52
53
|
minimizer: [
|
53
54
|
tryCssMinimizer(),
|
54
55
|
new TerserPlugin({
|
55
|
-
parallel: Number.parseInt(process.env.
|
56
|
+
parallel: Number.parseInt(process.env.SHAKAPACKER_PARALLEL, 10) || true,
|
56
57
|
terserOptions: {
|
57
58
|
parse: {
|
58
59
|
// Let terser parse ecma 8 code but always output
|
@@ -76,4 +77,12 @@ const productionConfig = {
|
|
76
77
|
}
|
77
78
|
}
|
78
79
|
|
80
|
+
if (config.useContentHash === false) {
|
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
@@ -10,19 +10,26 @@ const config = require('./config')
|
|
10
10
|
const devServer = require('./dev_server')
|
11
11
|
const env = require('./env')
|
12
12
|
const { moduleExists, canProcess } = require('./utils/helpers')
|
13
|
-
const inliningCss = require('./inliningCss')
|
13
|
+
const inliningCss = require('./utils/inliningCss')
|
14
14
|
|
15
|
-
const
|
15
|
+
const globalMutableWebpackConfig = () => {
|
16
16
|
const { nodeEnv } = env
|
17
17
|
const path = resolve(__dirname, 'environments', `${nodeEnv}.js`)
|
18
18
|
const environmentConfig = existsSync(path) ? require(path) : baseConfig
|
19
19
|
return environmentConfig
|
20
20
|
}
|
21
21
|
|
22
|
-
|
23
|
-
|
22
|
+
const generateWebpackConfig = () => {
|
23
|
+
const environmentConfig = globalMutableWebpackConfig()
|
24
|
+
const immutable = webpackMerge.merge({}, environmentConfig)
|
25
|
+
return immutable
|
26
|
+
}
|
27
|
+
|
28
|
+
const shakapackerObject = {
|
29
|
+
config, // shakapacker.yml
|
24
30
|
devServer,
|
25
|
-
|
31
|
+
generateWebpackConfig,
|
32
|
+
globalMutableWebpackConfig: globalMutableWebpackConfig(),
|
26
33
|
baseConfig,
|
27
34
|
env,
|
28
35
|
rules,
|
@@ -31,3 +38,26 @@ module.exports = {
|
|
31
38
|
inliningCss,
|
32
39
|
...webpackMerge
|
33
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)
|
@@ -0,0 +1,50 @@
|
|
1
|
+
const webpack = require("webpack");
|
2
|
+
const MemoryFS = require("memory-fs");
|
3
|
+
const thenify = require("thenify");
|
4
|
+
const path = require("path");
|
5
|
+
|
6
|
+
const createTrackLoader = () => {
|
7
|
+
const filesTracked = {};
|
8
|
+
return [
|
9
|
+
filesTracked,
|
10
|
+
(source) => {
|
11
|
+
filesTracked[source.resource] = true;
|
12
|
+
return source;
|
13
|
+
},
|
14
|
+
];
|
15
|
+
};
|
16
|
+
|
17
|
+
const node_modules = path.resolve("node_modules");
|
18
|
+
const node_modules_included = path.resolve("node_modules/included");
|
19
|
+
const app_javascript = path.resolve("app/javascript");
|
20
|
+
|
21
|
+
const createInMemoryFs = () => {
|
22
|
+
const fs = new MemoryFS();
|
23
|
+
|
24
|
+
fs.mkdirpSync(node_modules);
|
25
|
+
fs.mkdirpSync(node_modules_included);
|
26
|
+
fs.mkdirpSync(app_javascript);
|
27
|
+
|
28
|
+
return fs;
|
29
|
+
};
|
30
|
+
|
31
|
+
const createTestCompiler = (config, fs = createInMemoryFs()) => {
|
32
|
+
Object.values(config.entry).forEach((file) => {
|
33
|
+
fs.writeFileSync(file, "console.log(1);");
|
34
|
+
});
|
35
|
+
|
36
|
+
const compiler = webpack(config);
|
37
|
+
compiler.run = thenify(compiler.run);
|
38
|
+
compiler.inputFileSystem = fs;
|
39
|
+
compiler.outputFileSystem = fs;
|
40
|
+
return compiler;
|
41
|
+
};
|
42
|
+
|
43
|
+
module.exports = {
|
44
|
+
createTrackLoader,
|
45
|
+
node_modules,
|
46
|
+
node_modules_included,
|
47
|
+
app_javascript,
|
48
|
+
createInMemoryFs,
|
49
|
+
createTestCompiler,
|
50
|
+
};
|
@@ -0,0 +1,63 @@
|
|
1
|
+
const path = require("path");
|
2
|
+
const {
|
3
|
+
app_javascript,
|
4
|
+
node_modules,
|
5
|
+
node_modules_included,
|
6
|
+
createTestCompiler,
|
7
|
+
createTrackLoader,
|
8
|
+
} = require("./__utils__/webpack");
|
9
|
+
const babelConfig = require("../babel");
|
10
|
+
|
11
|
+
jest.mock("../../config", () => {
|
12
|
+
const original = jest.requireActual("../../config");
|
13
|
+
return {
|
14
|
+
...original,
|
15
|
+
additional_paths: [...original.additional_paths, "node_modules/included"],
|
16
|
+
};
|
17
|
+
});
|
18
|
+
|
19
|
+
const createWebpackConfig = (file, use) => {
|
20
|
+
return {
|
21
|
+
entry: { file },
|
22
|
+
module: {
|
23
|
+
rules: [
|
24
|
+
{
|
25
|
+
...babelConfig,
|
26
|
+
use,
|
27
|
+
},
|
28
|
+
],
|
29
|
+
},
|
30
|
+
output: {
|
31
|
+
path: "/",
|
32
|
+
filename: "scripts-bundled.js",
|
33
|
+
},
|
34
|
+
};
|
35
|
+
};
|
36
|
+
|
37
|
+
describe("babel", () => {
|
38
|
+
test("process source path", async () => {
|
39
|
+
const normalPath = `${app_javascript}/a.js`;
|
40
|
+
const [tracked, loader] = createTrackLoader();
|
41
|
+
const compiler = createTestCompiler(
|
42
|
+
createWebpackConfig(normalPath, loader)
|
43
|
+
);
|
44
|
+
await compiler.run();
|
45
|
+
expect(tracked[normalPath]).toBeTruthy();
|
46
|
+
});
|
47
|
+
|
48
|
+
test("exclude node_modules", async () => {
|
49
|
+
const ignored = `${node_modules}/a.js`;
|
50
|
+
const [tracked, loader] = createTrackLoader();
|
51
|
+
const compiler = createTestCompiler(createWebpackConfig(ignored, loader));
|
52
|
+
await compiler.run();
|
53
|
+
expect(tracked[ignored]).toBeUndefined();
|
54
|
+
});
|
55
|
+
|
56
|
+
test("explicitly included node_modules should be transpiled", async () => {
|
57
|
+
const included = `${node_modules_included}/a.js`;
|
58
|
+
const [tracked, loader] = createTrackLoader();
|
59
|
+
const compiler = createTestCompiler(createWebpackConfig(included, loader));
|
60
|
+
await compiler.run();
|
61
|
+
expect(tracked[included]).toBeTruthy();
|
62
|
+
});
|
63
|
+
});
|