{"id":15405089,"url":"https://github.com/razum2um/webpacker-remote","last_synced_at":"2025-03-28T01:52:31.218Z","repository":{"id":40382728,"uuid":"328968903","full_name":"razum2um/webpacker-remote","owner":"razum2um","description":"🔗 Integrate CRA builds into Webpacker","archived":false,"fork":false,"pushed_at":"2022-12-28T20:38:46.000Z","size":28,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-18T19:51:57.361Z","etag":null,"topics":["create-react-app","rails","webpack","webpacker"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/razum2um.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-01-12T11:42:54.000Z","updated_at":"2023-03-10T16:32:17.000Z","dependencies_parsed_at":"2023-01-31T07:30:47.366Z","dependency_job_id":null,"html_url":"https://github.com/razum2um/webpacker-remote","commit_stats":null,"previous_names":["lunatic-cat/webpacker-remote"],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/razum2um%2Fwebpacker-remote","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/razum2um%2Fwebpacker-remote/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/razum2um%2Fwebpacker-remote/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/razum2um%2Fwebpacker-remote/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/razum2um","download_url":"https://codeload.github.com/razum2um/webpacker-remote/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245955190,"owners_count":20699889,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["create-react-app","rails","webpack","webpacker"],"created_at":"2024-10-01T16:14:59.133Z","updated_at":"2025-03-28T01:52:31.199Z","avatar_url":"https://github.com/razum2um.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Webpacker::Remote\n\n![](https://github.com/lunatic-cat/webpacker-remote/workflows/ci/badge.svg)\n[![Gem Version](https://badge.fury.io/rb/webpacker-remote.svg)](https://badge.fury.io/rb/webpacker-remote)\n[![codecov](https://codecov.io/gh/lunatic-cat/webpacker-remote/branch/master/graph/badge.svg?token=X5K67X3V0Z)](https://app.codecov.io/gh/lunatic-cat/webpacker-remote)\n\n- support for `create-react-app` developed in a separate repo\n- support for multiple external frontend builds, right now `webpacker` is [a singleton](https://github.com/rails/webpacker/blob/6ba995aed2b609a27e4e35ec28b2a7f688cce0cf/lib/webpacker/helper.rb#L5L7)\n- support [shakapacker](https://github.com/shakacode/shakapacker)\n- support for both webpack-asset-manifest-3 and webpack-asset-manifest-5 (including `assets` and without this key)\n\n## Usage\n\n- ensure you're using `webpack-asset-manifest` to generate proper manifest structure\n- build `webpack` bundle \u0026 upload `build` directory (incl. `manifest.json`) before deploy\n- in `config/initializers/remote_webpacker.rb`\n\n```rb\n# given we can fetch `https://asset_host/build/manifest.json`\n# and it contains paths relative to `https://asset_host/build/`\nREMOTE_WEBPACKER = Webpacker::Remote.new(root_path: 'https://asset_host/build/', config_path: 'manifest.json')\n```\n\n- in `app/views/layouts/application.html.erb` (**not** `javascript_pack_tag`)\n\n```rb\n\u003c%= javascript_pack_tag 'main', webpacker: REMOTE_WEBPACKER %\u003e\n#=\u003e \u003cscript src='https://asset_host/build/static/js/main.2e302672.chunk.js'\u003e\n```\n\n**NOTE** if you're on `webpacker` (not `shakapacker`), then you should use `javascript_packs_with_chunks_tag`\n\nOf course, you can use as many build as you like and do blue-green deployments using gems like `rollout`\n\n## CRA Requirements\n\nFor `create-react-app` you should use `webpack-assets-manifest` instead of built-in `webpack-manifest-plugin`. You have to patch configuration like this:\n\n- in `package.json`\n\n```diff\n+    \"customize-cra\": \"^1.0.0\",\n+    \"react-app-rewired\": \"^2.2.1\"\n+    \"webpack-assets-manifest\": \"^5.1.0\"\n...\n-    \"build\": \"react-scripts build\"\n+    \"build\": \"react-app-rewired build\"\n```\n\n- add `config-overrides.js`\n\n```js\nconst { override } = require(\"customize-cra\");\nconst WebpackAssetsManifest = require('webpack-assets-manifest')\n\nconst whenInMode = (mode, fn) =\u003e config =\u003e (config.mode == mode) ? fn(config) : config;\n\nconst removeWebpackPlugin = pluginName =\u003e config =\u003e {\n  config.plugins = config.plugins.filter(\n    p =\u003e p.constructor.name !== pluginName\n  );\n  return config;\n};\n\nconst addWebpackPlugin = plugin =\u003e config =\u003e {\n  config.plugins.push(plugin);\n  return config;\n};\n\nconst webpackerAssetManifestConfig = {\n  integrity: false,\n  entrypoints: true,\n  writeToDisk: true,\n  output: 'manifest.json'\n};\n\nmodule.exports = override(\n  removeWebpackPlugin('ManifestPlugin'),\n  whenInMode('production', addWebpackPlugin(new WebpackAssetsManifest(webpackerAssetManifestConfig)))\n);\n```\n\n- check `PUBLIC_URL='https://...' npm run build` and `build/manifest.json` should look like this:\n\n```json\n{\n  \"entrypoints\": {\n    \"main\": {\n      \"assets\": {\n        \"js\": [\n          \"static/js/main.hashsum.js\"\n        ],\n        \"css\": [\n          \"static/css/main.hashsum.css\"\n        ]\n      }\n    }\n  },\n  \"main.css\": \"static/css/main.hashsum.css\",\n  \"main.js\": \"static/js/main.hashsum.js\"\n}\n```\n\n## Tests\n\nSpecify webpacker gem explicitly:\n\n```sh\nWEBPACKER_GEM_VERSION='shakapacker|6.2.1' bundle exec rspec\nWEBPACKER_GEM_VERSION='webpacker|5.4.3' bundle exec rspec\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frazum2um%2Fwebpacker-remote","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frazum2um%2Fwebpacker-remote","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frazum2um%2Fwebpacker-remote/lists"}