metalsmith-webpack-suite
v1.2.0
Published
> A boilerplate implementation to effectively merge webpack and metalsmith in > development and production environments.
Downloads
2
Readme
metalsmith-webpack-suite
A boilerplate implementation to effectively merge webpack and metalsmith in development and production environments.
:cloud: Installation
Cloning the repo or downloading a release might be the best idea.
You may build on top of this project or extract parts you need for your own projects.
Afterwars, simply install all dependencies by running:
yarn || npm install
:rocket: Technology
This boilerplate tries to combine the best out of metalsmith and webpack.
Content generation via metalsmithpreviewp
- Simple, pretty much not special metalsmith implementation
- metalsmith-assets to copy webpack files
- metalsmith-markdownit to render markdown
- metalsmith-layouts to apply layouts
Scripts and stylesheets via webpack
- Full power of webpack including tree shaking and minimize
- Uses webpack-dev-server (actually webpack-dev-middleware) under the hood for dev
- Styles get included via require within
page.js
and extracted to a css file via ExtractTextPlugin
:bookmark_tabs: Project File Structure
|Pattern|Description|
|-|-|
|./content/*
| website content files, mainly markdown files|
|./layouts/*.html
| metalsmith-layouts layout files|
|./src/config/paths.js
| path configuration
|./src/assets/css,js
| page javascript and stylesheet files|
|./src/scripts/*.js
| build process & dev environment scripts|
|./dist/assets/**/*
| webpack output directory|
|./dist/site/**/*
| metalsmith output directory|
:hammer_and_wrench: Development and tooling
You can start a fully featured development server via yarn dev
(or npm run dev
).
It will spawn a html server at http://localhost:3000
including browser-sync for live reload.
:recycle: Live reload details
Browser sync spawns a basic webserver with the webpack-dev-middleware injected.
The live reload gets very effective by combining 3 different reload techniques:
- browser-sync: Rebuilds metalsmith when content or layouts change.
- webpack-dev-middleware: Triggers browser-sync when webpack files like scripts or styles change
- nodemon: Restarts dev server when build scripts or config changes
:bulb: Tipps & tricks
- The dev server supports the
rs
shortcut while running. Simply type and hit enter to restart the server manually - The
metalsmith-helpers.js
in the scripts folder exports two metalsmith debugging plugins: AStatisticsPlugin
for a general overview and aDebugPlugin
for in-deepth insights - The metalsmith-layouts config contains a little helper for handlebars to output variable content. Usage:
<pre>{{debug YOUR_VARIABLE}}</pre>
(Hint: usethis
as variable to debug display the whole file metadata) - Check
npm run
for an overview of all available scripts.
:gear: Build process
You can run a fresh page build via yarn build
(Or npm run build
)
npm-scripts
: SetDEBUG
environment variable tometalsmith*
to enable metalsmith debuggingnpm-scripts
: Clean up./dist/*
directorieswebpack
: Build javascript and stylesheet files via webpackmetalsmith
: Copy webpack assets to site directorymetalsmith
: Fingerprint webpack assetsmetalsmith
: Compile markdown filesmetalsmith
: Apply layoutsmetalsmith
: Show statistics
Et voilà. You can find your generated website in ./dist/site/
. See below how you can preview and deploy the result.
:ship: Deployment & production server
With yarn deploy
(or npm run deploy
) you can deploy your latest website directly to GitHub pages via gh-pages
Running yarn server
(or npm run server
) will spawn a simple production server which is great for testing the final version.
:sparkling_heart: Contributing
This project follows the standard coding and the conventional changelog commit message style. Also it is configured to never decrease the code coverage of its tests.
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue. But before doing anything, please read the CONTRIBUTING.md guidelines.