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.
Localrefers 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].jsfile. The same advantage can be seen in themain.[hash].cssfile 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.jsfile, which is traversed by Webpack and converted intopublic/main.[hash].jsandpublic/main.[hash].cssfiles, respectively.The generated
main.[hash].cssfile is imported insite/themes/hugo-tutorials/layouts/partials/header.html:The generated
main.[hash].jsfile is imported insite/themes/hugo-tutorials/layouts/partials/footer.html:{{ $script := .Site.Data.webpack.main }} {{ with $script.js }} <script src="{{ relURL . }}"></script> {{ end }}Caveats
The
scripts/build.shscript has been modified to perform annpm buildcommand, rather than a directhugocommand. Thepackage.jsonincludes a collection of commands, butnpm buildbasically 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]/publicdirectory.Note: Since the
build.shscript 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 buildcommand is executed, but caution is advised the first time this is deployed.This change is