{"id":16687975,"url":"https://github.com/danielpclark/webpacker-rs","last_synced_at":"2025-04-10T00:34:00.390Z","repository":{"id":57672043,"uuid":"157766393","full_name":"danielpclark/webpacker-rs","owner":"danielpclark","description":"Rust wrapper for WebpackerCli/Webpacker/Webpack for Rust web framework asset management","archived":false,"fork":false,"pushed_at":"2021-01-18T22:17:55.000Z","size":21,"stargazers_count":6,"open_issues_count":0,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-02T16:25:30.654Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"lgpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/danielpclark.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":"2018-11-15T20:08:21.000Z","updated_at":"2021-01-18T22:17:59.000Z","dependencies_parsed_at":"2022-08-31T01:24:07.749Z","dependency_job_id":null,"html_url":"https://github.com/danielpclark/webpacker-rs","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danielpclark%2Fwebpacker-rs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danielpclark%2Fwebpacker-rs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danielpclark%2Fwebpacker-rs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danielpclark%2Fwebpacker-rs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/danielpclark","download_url":"https://codeload.github.com/danielpclark/webpacker-rs/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239088383,"owners_count":19579432,"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":[],"created_at":"2024-10-12T15:26:14.951Z","updated_at":"2025-02-16T04:33:11.505Z","avatar_url":"https://github.com/danielpclark.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Webpacker-rs\n\nWebpacker-rs is a Rust wrapper for using WebpackerCli/Webpacker/Webpack in your Rust web\nframework's deployment and asset management.\n\n## Usage\n\nAdd the following to your Cargo.toml\n\n```toml\n[dependencies]\nwebpacker = \"~0.3\"\n\n[build-dependencies]\nwebpacker = \"~0.3\"\n```\n\nBefore you can build you need to initialize the webpacker environment with:\n\n    gem install webpacker_cli\n    webpacker-cli init\n\nNow your build script will be able to compile. In your build script you can do the following:\n\n```rust\nuse webpacker;\nfn main() {\n    // Validating dependencies…\n    assert!(webpacker::valid_project_dir());\n\n    // Compiling assets…\n    let _ = webpacker::compile();\n}\n```\n\nAnd then in your application during web start up you can generate\na hash of the file manifest with:\n\n```rust\nuse webpacker;\n\n// Returns `Manifest` object which is an\n// immutable Hashmap\nwebpacker::manifest()\n```\n\nYou can use the `Manifest` object in your routing tables.\n\n## Gotham\n\nIn [Gotham](https://gotham.rs/) one way you can use the manifest for the router as follows:\n\n```rust\npub fn router() -\u003e Router {\n    build_simple_router(|route| {\n        for (key, value) in webpacker::manifest(None).unwrap() {\n            route\n                .get(\u0026format!(\"public/{}\", key))\n                .to_file(format!(\"public{}\", value));\n        }\n    })\n}\n```\n\nAnd in each of your webpages you link to your assets as though they were in the `public/` folder. \nThis will map the normal file names like `application.js` to their hashed version\n`/packs/application-285f2db5acb1800187f0.js`.  _I'm not sure having the router do this lets the cache\ninvalidation work as intended._\n\nThe recommended way to use this is to have a helper method write the mapped file name right to\nthe generated webpage HTML source.  So if you're using [tera](https://github.com/Keats/tera) then you\ncould do something like:\n\n```rust\npub static ASSET_DIRECTORY: \u0026'static str = \"public\";\n\nlazy_static! {\n    pub static ref MANIFEST: Manifest = webpacker::manifest(None).unwrap();\n}\n\nmod assets {\n    use super::{ASSET_DIRECTORY, MANIFEST};\n    use webpacker::asset_path::AssetPath;\n    use std::ops::Deref;\n\n    pub fn source(key: \u0026str) -\u003e String {\n        AssetPath::new(ASSET_DIRECTORY, key, MANIFEST.deref()).into()\n    }\n}\n\npub fn index_page(state: State) -\u003e (State, (mime::Mime, String)) {\n    let mut context = Context::new();\n    context.insert(\"application_source\", \u0026assets::source(\"application.js\"));\n\n    let rendered = TERA.render(\"landing_page/index.html.tera\", \u0026context).unwrap();\n\n    (state, (mime::TEXT_HTML, rendered))\n}\n```\n\n```html\n\u003cscript src=\"{{ application_source }}\"\u003e\u003c/script\u003e\n```\n\nDoing this preferred way means you should have the folder `/public/*` routed with something like this:\n\n```rust\npub fn router() -\u003e Router {\n    build_simple_router(|route| {\n        route.get(\"public/*\").to_dir(\n            FileOptions::new(\"public\")\n                .with_cache_control(\"no-cache\")\n                .with_gzip(true)\n                .build(),\n        );\n    })  \n}\n```\n\n`FileOptions` here provides Async file support.\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/danielpclark/webpacker-cli\n\n\n## License\n\nThe gem is available as open source under the terms of the [GNU Lesser General Public License version 3](https://opensource.org/licenses/LGPL-3.0).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanielpclark%2Fwebpacker-rs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdanielpclark%2Fwebpacker-rs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanielpclark%2Fwebpacker-rs/lists"}