Webpacker-rs
Webpacker-rs is a Rust wrapper for using WebpackerCli/Webpacker/Webpack in your Rust web framework's deployment and asset management.
Usage
Add the following to your Cargo.toml
[]
= "~0.1"
[]
= "~0.1"
In your build script you can do the following:
use webpacker;
And then in your application during web start up you can generate a hash of the file manifest with:
use webpacker;
// Returns `Manifest` object which is an
// immutable Hashmap
manifest
You can use the Manifest
object in your routing tables.
Gotham
In Gotham one way you can use the manifest for the router as follows:
And in each of your webpages you link to your assets as though they were in the public/
folder.
This will map the normal file names like application.js
to their hashed version
/packs/application-285f2db5acb1800187f0.js
. I'm not sure having the router do this lets the cache
invalidation work as intended.
The recommended way to use this is to have a helper method write the mapped file name right to the generated webpage HTML source. So if you're using tera then you could do something like:
lazy_static!
Note the manifest value will have a preceeding slash so you don't need one after the folder name public
.
Also it would be nicer to create a helper method for yourself that precedes your asset with concatenation of
public
or whatever directory name you choose to serve it under.
Doing this preferred way means you should have the folder /public/packs/*
routed with something like this:
FileOptions
here provides Async file support.
Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/danielpclark/webpacker-cli
License
The gem is available as open source under the terms of the GNU Lesser General Public License version 3.