Add the following code to your project's shard.yml under:
dependencies
to use in production
- OR -
development_dependencies
to use in development
assemble files in assets folder into executable binary use backed_file_system
at compile time, then mount it to new file system folder at runtime.
Let us use a kemal as a example.
We save our assets file here
╰─ $ tree src/assets/
src/assets/
└── materialize
├── css
│ └── materialize.min.css
└── js
└── materialize.min.js
What we want is assemble those assets file into binary when build.
Then, when copy binary to target environment, starting it, will create new folder like this with assets.
╰─ $ tree public
public/
└── materialize
├── css
│ └── materialize.min.css
└── js
└── materialize.min.js
3 directories, 2 files
Any files you add to the public
directory will be served automatically by Kemal by default.
So, it will load stylesheet correctly when you write ECR template like this.
<html>
<head>
<link rel="stylesheet" href="/materialize/css/materialize.min.css" />
</head>
<body>
<%= yield_content "footer" %>
</body>
</html>
Add the dependency to your shard.yml
:
dependencies:
baked_file_system_mounter:
github: zw963/baked_file_system_mounter
Run shards install
In this example, we mount two folder, one for assets, one for migration.
# src/config/baked_file_system_mounter.cr
require "baked_file_system_mounter"
#
# so, we assemble all files in `src/assets`,`db` into executable binary when we build,
BakedFileSystemMounter.assemble(
{
"src/assets" => "public",
"db" => "db"
}
)
# we assemble the db into db folder too
# Then mount those files in `src/assets` into `public` folder(will create it if not exists)
# will serve by kemal when server is start.
# mount `db` into `db` folder too for run migrate when server is starting on production..
if APP_ENV == "production"
STDERR.puts "Mounting from baked file system ..."
BakedFileSystemStorage.mount
end
TODO: Write development instructions here
git checkout -b my-new-feature
)git commit -am 'Add some feature'
)git push origin my-new-feature
)