This repository was archived by the owner on Mar 29, 2025. It is now read-only.
Add Webpack, Babel, and Modern ES6 Syntax Support #67
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Features
Performance
Below is a table comparing metrics for the current and "webpack-ified" version of the site.
Local
refers to non-CDN content loaded from the local web server.While local JS file size increases slightly, a significant load advantage is gained by combining and minifying into a single
main.[hash].js
file. The same advantage can be seen in themain.[hash].css
file size. Overall site load time is dramatically reduced.Preview
Live preview of this pull request can be found here: https://determined-stallman-63e0ba.netlify.com/
Project Structure
The base Hugo site has been moved into the
site/
directory, while all local CSS and JS files have been moved to thesrc/
directory. The structure is based on the victor-hugo project.The project entry point is the
src/index.js
file, which is traversed by Webpack and converted intopublic/main.[hash].js
andpublic/main.[hash].css
files, respectively.The generated
main.[hash].css
file is imported insite/themes/hugo-tutorials/layouts/partials/header.html
:The generated
main.[hash].js
file is imported insite/themes/hugo-tutorials/layouts/partials/footer.html
:Caveats
The
scripts/build.sh
script has been modified to perform annpm build
command, rather than a directhugo
command. Thepackage.json
includes a collection of commands, butnpm build
basically executes the following two successive commands:cross-env NODE_ENV=production webpack --config webpack.prod.js --hot --inline
- Performs production webpack build.hugo -d ../public -s site -v
- Builds Hugo in the default[root]/public
directory.Note: Since the
build.sh
script relies on pulling from the existing tutorial repo, the functionality of this script has not been tested for production. I believe it should function as before, since the output directory (public
) remains the same once thenpm build
command is executed, but caution is advised the first time this is deployed.This change is