NPM Pack
Hugo 0.75.0
brings several improvements to Hugo Modules, a new CLI command to bridge the JavaScript dependencies into Hugo, a refresh of the versions of the most important upstream dependencies, and more. There are also some good bug fixes in this release. One notable one is covered by this commit – which covers a “stale content scenario in server” when you include content or page data via GetPage
from a shortcode.
NPM Pack
The new CLI command is called hugo mod npm pack
. We have marked it as experimental. It works great, go ahead and use it, but we need to test this out in real projects to get a feel of it; it is likely that it will change/improve in the upcoming versions of Hugo. The command creates a consolidated package.json
from the project and all of its theme components. On version conflicts, the version closest to the project is selected. We may revise that strategy in the future (minimal version selection maybe?), but this should give both control and the least amount of surprise for the site owner.
So, why did we do this? JavaScript is often a background actor in a Hugo project, and it doesn’t make sense to publish it to a NPM registry. The JS dependencies are mostly build tools (PostCSS, TailwindCSS, Babel), devDependencies
. This has been working fine as long as you kept the JS config files (including package.json
) in the project, adding duplication/work when using ready-to-use theme components. These tools work best when you have everything below a single file tree, which is very much different to how Hugo Modules work. An example of a module with TailwindCSS:
tailwind-module
├── assets
│ └── css
├── package.json
├── postcss.config.js
└── tailwind.config.js
If you included tailwind-module
in a Hugo project and processed it with PostCSS
, this is what happened in earlier versions:
- It used the directory where the
postcss.config.js
lives as a starting point to look for anyrequire
’d dependency. - TailwindCSS would, on the other hand, load its configuration file relative to where
PostCSS
was invoked (the project directory).
The above just doesn’t work and here is the technical notes on how we have fixed this:
- The new
hugo mod npm pack
creates a consolidatedpackage.json
based on files namedpackage.hugo.json
it finds in the dependency tree (one is created for you the first time you run this command). The end result will always bepackage.json
, which works seamlessly withnpm install
invoked automatically by Netlify and other CI vendors. - The main project’s
node_modules
folder is added to NODE_PATH when runningPostCSS
andBabel
. - We have introduced a new mount point
assets/_jsconfig
where we, by default, mount the JS configuration files that we’re interested in. This is where Hugo will start looking for these files, and the files' filenames will also be available in the Node environment, so you can do:
let tailwindConfig = process.env.HUGO_FILE_TAILWIND_CONFIG_JS || './tailwind.config.js';
const tailwind = require('tailwindcss')(tailwindConfig);
Module Enhancements
- We have added a
noVendor
Glob pattern config to the module config d4611c43 @bep #7647. This allows you to only vendor a subset of your dependencies. - We have added
ignoreImports
option to module imports config 20af9a07 @bep #7646, which allows you to import a module and load its config, but not follow its imports. - We have deprecated
--ignoreVendor
in favour of a--ignoreVendorPaths
, a patch matching Glob pattern 9a1e6d15 @bep. A typical use for this would be when you have vendored your dependencies, but want to edit one of them.
Statistics
This release represents 79 contributions by 19 contributors to the main Hugo code base. @bep leads the Hugo development with a significant amount of contributions, but also a big shoutout to @dependabot[bot], @moorereason, and @jmooring for their ongoing contributions. And a big thanks to @digitalcraftsman for his relentless work on keeping the themes site in pristine condition and to @davidsneighbour, @coliff and @kaushalmodi for all the great work on the documentation site.
Many have also been busy writing and fixing the documentation in hugoDocs, which has received 24 contributions by 15 contributors. A special thanks to @jmooring, @bep, @jornane, and @inwardmovement for their work on the documentation site.
Hugo now has:
- 46596+ stars
- 438+ contributors
- 352+ themes
Notes
- We now build with Go 1.15, which means that we no longer build release binaries for MacOS 32-bit.
- You may now get an error message about “error calling partial: partials that returns a value needs a non-zero argument.”. This error situation was not caught earlier, and comes from a limitation in Go’s templates: If you use the
return
keyword in a partial, the argument you pass to that partial (e.g. the “.") cannot be zero (and 0 and "” is considered a zero argument).
Enhancements
Templates
- Print layout name if it was specified when showing missing layout file error 9df60b62 @richtera #7617
- Add limit support to replaceRE cdfd1c99 @moorereason #7586
- Extend merge to accept multiple parameters 047af7cf @moorereason #7595
- Add limit option to replace template function f9ebaaed @moorereason #7586
Output
Other
- Set PWD in environment when running the Node apps 377ad87a @bep
- already -> already 292b0e26 @dholbach
- Regen docs helper be2404c8 @bep
- Regenerate CLI docs c8da8eb1 @bep
- Add “hugo mod npm pack” 85ba9bff @bep #7644#7656#7675
- bump github.com/aws/aws-sdk-go from 1.34.21 to 1.34.22 4fad43c8 @dependabot[bot]
- Add support to linkable line anchors on Chroma fb0f2cc7 @fjorgemota #7622
- Bump bundled Node.js from v8.12.0 to v12.18.3 748fd4cb @anthonyfok #7278
- Change confinement from strict to classic" b82f440c @anthonyfok
- bump github.com/getkin/kin-openapi from 0.14.0 to 0.22.0 c8143efa @dependabot[bot]
- bump github.com/aws/aws-sdk-go from 1.34.20 to 1.34.21 c80132bb @dependabot[bot]
- bump github.com/spf13/viper from 1.6.1 to 1.7.1 75fa4c5c @dependabot[bot]
- Run “go mod tidy” fd7969e0 @bep
- Update to Goldmark v1.2.1 b7fa3c4b @bep
- bump github.com/aws/aws-sdk-go from 1.27.1 to 1.34.20 746ba803 @dependabot[bot]
- bump github.com/mitchellh/mapstructure from 1.1.2 to 1.3.3 612b7d37 @dependabot[bot]
- Change confinement from strict to classic 6f4ff1a4 @anthonyfok
- bump github.com/spf13/cobra from 0.0.5 to 0.0.7 ddeca459 @dependabot[bot]
- bump github.com/sanity-io/litter from 1.2.0 to 1.3.0 31f2091f @dependabot[bot]
- Add noVendor to module config d4611c43 @bep #7647
- Add ignoreImports to module imports config 20af9a07 @bep #7646
- Make ignoreVendor a glob pattern 9a1e6d15 @bep #7642
- bump github.com/gorilla/websocket from 1.4.1 to 1.4.2 84adecf9 @dependabot[bot]
- bump github.com/fsnotify/fsnotify from 1.4.7 to 1.4.9 573558a0 @dependabot[bot]
- bump github.com/kyokomi/emoji 8b10c22f @dependabot[bot]
- bump github.com/markbates/inflect from 1.0.0 to 1.0.4 195bd124 @dependabot[bot]
- bump github.com/frankban/quicktest from 1.7.2 to 1.10.2 6a544ece @dependabot[bot]
- Encode & in livereload injected code 4b430d45 @axllent
- bump github.com/niklasfasching/go-org from 1.3.1 to 1.3.2 b9f10c75 @dependabot[bot]
- bump github.com/bep/golibsass from 0.6.0 to 0.7.0 537c598e @dependabot[bot]
- bump golang.org/x/text from 0.3.2 to 0.3.3 67348676 @dependabot[bot]
- bump github.com/evanw/esbuild from 0.6.5 to 0.6.32 f9cc0ec7 @dependabot[bot]
- bump github.com/nicksnyder/go-i18n from 1.10.0 to 1.10.1 b5483eed @dependabot[bot]
- Revert “Update dependabot.yml” 90285f47 @bep
- Update replaceRE func f7c1b5fe @moorereason
- Update replace func 183e8626 @moorereason
- Update merge function f50ee6bb @moorereason
- Update dependabot.yml c0655ba6 @bep
- Create dependabot.yml a2dda22c @bep
- Remove Pygments from requirements.txt 910d81a6 @bep
- Regen CLI docs 8c490a73 @bep
- Regen docs helper e6cd9da4 @bep
- markup/asciidocext: Revert trace=true dcf25c0b @bep
- Update to Go 1.15.1 and 1.14.8 e820b366 @bep #7627
- Add support for .TableOfContents 3ba7c925 @npiganeau #1687
- Add a test case 19ef27b9 @bep #7619
- Add SourceMap flag with inline option c6b661de @richtera #7607
- Remove logic that hides ‘Building Sites’ message after build completes d39636a5 @jwarner112 #7579
- Improve stderr logging for PostCSS and simlilar ec374204 @bep #7584
- Fail on partials with return when given none or a zero argument ae63c2b5 @bep #7572#7528
- Update to Go 1.15 e627449c @bep #7554
- Revert “Update stale.yml” c2235c6a @bep
- Update stale.yml 4f69ade7 @bep
- Remove trailing whitespace and tabs from RSS templates 5f425901 @solarkennedy
- Add uninstall target 21dbfa1f @felicianotech
- Update Chroma to 0.8.0 e5591e89 @jmooring #7517
- Update go-org to v1.3.1 88929bc2 @niklasfasching
- Collect transition attributes as classes 00e00da2 @bep #7509
- Add option for setting bundle format 0256959a @bep #7503
- Simplify options handling eded9ac2 @bep #7499
- make sure documentation intro text only appears once 8d725128 @TheHippo
- Add es5 build target e81aef0a @bep
- esbuild v0.6.5 9f919147 @bep
- Add .Defines to js.Build options 35011bcb @bep #7489
Fixes
Other
- Fix AsciiDoc TOC with code 6a848cbc @helfper #7649
- markup/asciidocext: Fix broken test 4949bdc2 @bep
- Fix some change detection issues on server reloads 4055c121 @bep #7623#7624#7625
- Fixed misspelled words ad01aea3 @aurkenb
- Fix a typo in CONTRIBUTING.md f3cb0be3 @capnfabs
- Revert “Fix ellipsis display logic in pagination template” bffc4e12 @jmooring
- Fix ellipsis display logic in pagination template 2fa851e6 @jmooring #7523
- Fix Asciidoctor args 45c665d3 @helfper #7493
- Fix date format in internal schema template a06c06a5 @jmooring #7495
- Fix baseof block regression c91dbe4c @bep #7478
Улучшить эту страницу