Awesome
Seed Quickstart with Webpack
<!-- prettier-ignore -->I want to write fast, reliable and efficient web apps. Quickly.
And I like Rust and documentation.
!!! New Rust-only quickstart in development! => Seeder !!!
LIVE DEMO: quickstart-webpack.seed-rs.org
Main components:
- Seed - Rust framework, inspired by Elm. Seed's Awesome list.
- Tailwind CSS - CSS framework. All CSS classes in your project are typed for safe use in Rust code. Unused classes are automatically deleted for much smaller bundle size.
- Webpack - Bundler. Auto-reload on code change, dev-server accessible from mobile phones, prerendering for static websites... and many more useful features are prepared for you in this quickstart.
- Why Webpack instead of Rust-only build pipeline? - Wiki
- Production-ready starter project - Example project is based on the website with several pages, favicons, nice fonts, meta tags for social media, buttons for scrolling to top, header which is hidden on scrolling, etc. It can be prerendered, but it also contains loading screen. For more complex project (based on another quickstart) see seed-rs-realworld.
- Production-ready configuration - Project is linted, compiled, prerendered and deployed in CI pipeline (see
.github/workflows/main.yml
andnetlify.toml
). Linters are very strict.
Zero to Hero
How to create your new app, modify it and deploy it - step by step guide.
1. Create a new project
I want to show you how to create, build and host your website for free, so we will need a public GitHub repository.
-
The simplest way how to do it is to click on the green button Use this template on the GitHub profile of this quickstart.
-
Make sure Git doesn't automatically convert your newlines to CLRF because linters don't like it.
- Run
$ git config --global core.autocrlf
in your terminal and it should returninput
orfalse
. See Git docs for more info.
- Run
-
Clone your new repository to your local machine. I use GitKraken, but you are probably better developer than me - use your favorite terminal.
2. Install / check required tools
-
Make sure you have basic tools installed:
-
Platform-specific tools like
ssl
andpkg-config
:- Follow recommendations in build errors (during the next chapter).
- Note: Don't hesitate to write a tutorial and create PR or write a Wiki page for your platform.
-
These tools are required by some commands:
-
- Check:
$ wasm-pack -V
=>wasm-pack 0.9.1
- Install:
$ cargo install wasm-pack
- Check:
-
- Check:
$ cargo make -V
=>cargo-make 0.30.7
- Install:
$ cargo install cargo-make
- Check:
-
- Check:
$ cargo +nightly fmt -- -V
=>rustfmt 1.4.14-nightly (a5cb5d26 2020-04-14)
- Install:
$ rustup toolchain install nightly
$ rustup component add rustfmt --toolchain nightly
- Check:
-
3. Prepare your project for work
- Open terminal in your project
- Install Webpack and other dependencies -
$ yarn
- Try to start dev-server -
$ yarn start
- and then open localhost:8000 in a browser. - Stop server (try
Ctrl+c
). - Try to lint your project -
$ cargo make verify_only
- you shouldn't see any errors. - Modify files like
LICENCE
,README.md
andCargo.toml
as you wish and push changes into GitHub.
4. Write your website
- Open project in your favorite IDE. I use IntelliJ or VS Code.
- Run
$ yarn start
in terminal. - Open localhost:8000 in a browser.
- You can open it also in your mobile phone:
- Make sure your dev-server aka computer is in the same network as your phone.
- Find out your local IP address. Use e.g. this online tool: https://www.whatismybrowser.com/detect/what-is-my-local-ip-address.
- Open URL with found IP address and default port (e.g.
192.168.1.5:8000
) on your phone.
Note: You don't have to follow all steps below - reuse starter project code as you need.
Header
- Open
src/page/partial/header.rs
in your IDE. - Delete function
header_visibility
. - Write a new body for function
view
.
Footer
- Open
src/page/partial/footer.rs
in your IDE. - Write a new body for function
view
.
404
- Open
src/page/not_found.rs
in your IDE. - Write a new body for function
view
.
Home page
- Open
src/page/home.rs
in your IDE. - Write a new body for function
view
.
About page
- Open
src/page/about.rs
in your IDE. - Write a new body for function
view
.
App core
- Open
src/lib.rs
in your IDE. - Change
TITLE_SUFFIX
value. - Delete
MAIL_TO_KAVIK
andMAIL_TO_HELLWEB
. - Write a new body for function
view
.
Favicons
- Delete or replace files in
/favicons
. - Open
static/templates/favicons.hbs
in your IDE. - Delete content or update it.
- Note: Templates are written in Handlebars.
Loading page
- Open
static/templates/loading_page.hbs
in your IDE. - Delete content or update it.
Social media & basic settings
- Open
static/templates/social_media.hbs
in your IDE. - Delete content or update it.
Basic HTML
- Open
static/index.hbs
in your IDE. - Update content.
Fonts
- Delete or replace files and directories in
static/fonts
. - Open
/css/fonts.css
in your IDE. - Delete content or update it.
Images & other files
- Delete or replace files in
static/images
. - Delete
static/Martin_Kavik_resume.pdf
.
TailwindCSS
- Open
tailwind.config.js
in your IDE. - Update content or replace it with the default one:
module.exports = {
theme: {},
variants: {},
plugins: []
};
Custom CSS
- Open
/css/custom.css
in your IDE. - Delete content or update it.
5. Prepare your project for deploy
How to format, lint and test your project.
And how to setup Github Actions with deploy into Netlify.
Formatter & Linter
- Format:
$ cargo make fmt
(it overwrites files) or only$ cargo make fmt_check
- You can modify format settings in:
rustfmt.toml
Makefile.toml
- tasksfmt
andfmt_check
- Lint:
$ cargo make clippy
- You can modify linter settings in:
Makefile.toml
- taskclippy
Testing
- Run
$ cargo make test_h firefox
for headless testing in Firefox.- There are more similar commands - see
Makefile.toml
- Note: There is only one test in this project (
tests/test.rs
), see seed-rs-realworld for more examples.
- There are more similar commands - see
- If you want to test prerendered website:
$ yarn build:prerender
$ yarn serve:dist
- Open localhost:8000 in a browser.
- Tip: Always test it also in production environment because e.g. routing is a little bit different among servers.
- Always run
$ cargo make verify
before push to make sure CI pipeline will accept your code.- It'll format your code, lint it and start headless tests in Firefox.
- You can change its behaviour in
Makefile.tom
- taskverify
(similar taskverify_only
is used in CI).
Netlify
- Create a new Netlify site.
- [Optional] Change site name or/and use your own domain.
- [Optional] Turn on HTTPS.
- [Optional] Add badge to project's
/README.md
(Site detail >Settings
>General
>Status badges
). - Note somewhere Site id (Site detail >
Settings
>General
> API ID) - Create and note somewhere Access token (Click on your avatar >
User settings
>Applications
>New access token
> Name it for instanceGitHub
) - [Optional] Adjust
/netlify.toml
to suit your needs. Netlify docs.
Github Actions
- Open your GitHub repository in your favorite browser.
- Click on
Settings
and then onSecrets
. - Add secret
NETLIFY_SITE_ID
and set it's value to Site id. - Add secret
NETLIFY_ACCESS_TOKEN
and set it's value to Access token. - Click on
Actions
in the side menu and make sure thatActions
are enabled. - [Optional] Modify
/.github/workflows/main.yml
.- Replace
yarn build:prerender
withyarn build:release
if you don't want to prerender pages.
- Replace
- [Optional] Push your code and switch to tab
Actions
to check that everything works.
Manual Deployment
- Run
yarn build:realease
. - Check if build works by running
yarn serve:dist
and view in a browser. - Deploy the contents of the
dist
directory to a web server.
Travis CI
<details> <summary>Content (this guide and related config file are not maintained)</summary>- Sync your TravisCI account with your GitHub one.
- Find repository with your app in your list and click on
Settings
. - Add Environment Variable
NETLIFY_SITE_ID
and set it's value to Site id. - Add Environment Variable
NETLIFY_ACCESS_TOKEN
and set it's value to Access token. - Switch to tab
Current
and clickActivate repository
. - [Optional] Add badge to project's
/README.md
(Repository detail > Click on badge next to the rep. name >IMAGE URL
change toMARKDOWN
) - [Optional] Modify
/.travis.yml
.- Replace
yarn build:prerender
withyarn build:release
if you don't want to prerender pages. - Tip: If jobs don't want to start after push, check Repository detail >
More options
>Requests
.
- Replace
6. Add your project to Awesome list
- Create PR or issue in awesome-seed-rs.
Used in projects
- seed-rs/seed-rs.org
- MartinKavik/kavik.cz
- [create PR or Issue]
Contributing
- Improved documentation, fixed typos, updated dependencies, ... - create Issue or PR.
- Ideas, bugs, questions, ... - create Issue.
Note: Please squash commits and rebase before creating PR. Thanks!