Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/vseventer/hugo-webpack-boilerplate
Hugo and Webpack boilerplate.
https://github.com/vseventer/hugo-webpack-boilerplate
boilerplate hugo hugo-boilerplate webpack webpack-boilerplate
Last synced: 3 months ago
JSON representation
Hugo and Webpack boilerplate.
- Host: GitHub
- URL: https://github.com/vseventer/hugo-webpack-boilerplate
- Owner: vseventer
- License: mit
- Archived: true
- Created: 2017-03-01T18:20:14.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2017-09-30T17:51:36.000Z (about 7 years ago)
- Last Synced: 2024-07-12T01:56:23.300Z (4 months ago)
- Topics: boilerplate, hugo, hugo-boilerplate, webpack, webpack-boilerplate
- Language: JavaScript
- Homepage:
- Size: 22.5 KB
- Stars: 43
- Watchers: 4
- Forks: 6
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.txt
Awesome Lists containing this project
- awesome-hugo - Hugo Webpack Boilerplate
README
# hugo-webpack-boilerplate
> [Hugo](https://gohugo.io) and [Webpack](https://webpack.js.org/) boilerplate.## Install
`npm install hugo-webpack-boilerplate`## Usage
We all love [Hugo](https://gohugo.io), but it is cumbersome to use anything beyond simple HTML, CSS, and JavaScript. What about LESS/SASS, ES6, minification, tree-shaking, or asset revving? Sure, you can roll your own, but these are all things [Webpack](https://webpack.js.org/) was designed for.Given Webpack typically takes a JavaScript file as entry point, but Hugo generates mostly HTML, it is quite complicated to come up with a useful workflow. This repository is an attempt to bind Hugo and Webpack together, giving Webpack full power over the files generated by Hugo. You can continue to use Hugo as you normally would, but enjoy the additional benefits of Webpack.
In your `webpack.config.js`, use:
```js
// Exports.
module.exports = require('hugo-webpack-boilerplate');
```Alternatively, if you are not using Hugo’s default `publishDir`, use:
```js
// Exports.
module.exports = require('hugo-webpack-boilerplate').fromConfig({
hugoPublishDir: 'hugo-publish-dir', // Defaults to public/
outDir: 'my-publish-dir' // Defaults to dist/
});
```Currently, only the Hugo `publishDir` and `outDir` are customizable. Over time, this module will be extended to allow further customizations.
### Example 1
This example considers a simple HTML file, a SASS stylesheet, image, and ES6 JavaScript file. The assets live under `static/` (Hugo’s default), so for example, the image should be located at `static/img/example.jpg`. Note the usage of `~` (tilde), which will make sure Webpack can find the assets. Also, this module relies on [interpolation by the `html-loader`](https://github.com/webpack-contrib/html-loader#interpolation), so make sure to import assets using `require`, as shown below.When running `webpack -p`, Webpack will take all these assets, [`optimize-minimize`](https://webpack.js.org/guides/production-build/) them, and put them in the `dist/` folder. Alternatively, you can run `webpack -w` to start the local development server.
#### Input
`layouts/index.html`
```htmlThis is an example
```
#### Output
`dist/index.html`
```htmlThis is an example
```
## FAQ
* I’m getting UnCSS errors, like `Could not load script: "file:///~js/script.js"`?UnCSS attempts to load scripts from disk, which will not work if they are referenced by `~`. The error is however non-blocking, and the UnCSS output is still useful. Just note that any selectors dynamically added will not be in the resulting stylesheet.
* The watching task causes Webpack to continuously reload?
There is a [bug in watchpack](https://github.com/webpack/watchpack/issues/25) causing the watcher to reload the same files over and over until the files settle. Apart from being an inconvenience, it does not affect your bundles.
* Can I use configure or add custom Webpack loaders or plugins?
Right now, no, there is no way to do this. Feel free to submit an issue or PR if you’d like to see any additions. It should be pretty simple to add this to the `fromConfig` function in `src/index.js`.
## Changelog
See the [CHANGELOG](./CHANGELOG.md) for a list of changes.## License
The MIT License (MIT)Copyright (c) 2017 Mark van Seventer
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.