summaryrefslogtreecommitdiffstats
path: root/resources/resource_transformers
AgeCommit message (Collapse)Author
2021-10-10Allow multiple plugins in the PostCSS options mapJoe Mooring
Usage: {{ $options := dict "use" "autoprefixer postcss-color-alpha" }} {{ $style := resources.Get "main.css" | resources.PostCSS $options }} Fixes #9015
2021-09-22Pass minification errors to the userPaul Gottschling
Previously, *minifyTransformation.Transform suppressed the error returned by t.m.Minify. This meant that when minification returned an error, the error would not reach the user. Instead, minification would silently fail. For example, if a JavaScript file included a call to the Date constructor with: new Date(2020, 04, 02) The package that the minification library uses to parse JS files, github.com/tdewolff/parse would return an error, since "04" would be parsed as a legacy octal. However, the JS file would remain un-minified with no error. Fixing this is not as simple as replacing "_" with an "err" in *minifyTransformation.Transform, however (though this is necessary). If we only returned this error from Transform, then hugolib.TestResourceMinifyDisabled would fail. Instead of being a no-op, as TestResourceMinifyDisabled expects, using the "minify" template function with a "disableXML=true" config setting instead returns the error, "minifier does not exist for mimetype." The "minifier does not exist" error is returned because of the way minifiers.New works. If the user's config disables minification for a particular MIME type, minifiers.New does not add it to the resulting Client's *minify.M. However, this also means that when the "minify" template function is executed, a *resourceAdapter's transformations still add a minification. When it comes time to call the minify.Minifier for a specific MIME type via *M.MinifyMimetype, the github.com/tdewolff/minify library throws the "does not exist" error for the missing MIME type. The solution was to change minifiers.New so, instead of skipping a minifier for each disabled MIME type, it adds a NoOpMinifier, which simply copies the source to the destination without minification. This means that when the "minify" template function is used for a particular resource, and that resource's MIME type has minification disabled, minification is genuinely skipped, and does not result in an error. In order to add this, I've fixed a possibly unwanted interaction between minifiers.TestConfigureMinify and hugolib.TestResourceMinifyDisabled. The latter disables minification and expects minification to be a no-op. The former disables minification and expects it to result in an error. The only reason hugolib.TestResourceMinifyDisabled passes in the original code is that the "does not exist" error is suppressed. However, we shouldn't suppress minification errors, since they can leave users perplexed. I've changed the test assertion in minifiers.TestConfigureMinify to expect no errors and a no-op if minification is disabled for a particular MIME type. Fixes #8954
2021-09-01js: Fix import order for ./foo when both ./foo.js and ./foo/index.js existsBjørn Erik Pedersen
This is in line with how both Node and ESBuild's native import resolver does it. The ambiguous situations above were discovered trying to build AlpineJS v3. Note that the above was never an issue if you used `./foo.js` and similar to import the component. Fixes #8945
2021-07-19minifiers: Make keepWhitespace = true default for HTMLBjørn Erik Pedersen
Fixes #8771
2021-07-15hugofs: Make FileMeta a structBjørn Erik Pedersen
This commit started out investigating a `concurrent map read write` issue, ending by replacing the map with a struct. This is easier to reason about, and it's more effective: ``` name old time/op new time/op delta SiteNew/Regular_Deep_content_tree-16 71.5ms ± 3% 69.4ms ± 5% ~ (p=0.200 n=4+4) name old alloc/op new alloc/op delta SiteNew/Regular_Deep_content_tree-16 29.7MB ± 0% 27.9MB ± 0% -5.82% (p=0.029 n=4+4) name old allocs/op new allocs/op delta SiteNew/Regular_Deep_content_tree-16 313k ± 0% 303k ± 0% -3.35% (p=0.029 n=4+4) ``` See #8749
2021-06-14Misc config loading fixesBjørn Erik Pedersen
The main motivation behind this is simplicity and correctnes, but the new small config library is also faster: ``` BenchmarkDefaultConfigProvider/Viper-16 252418 4546 ns/op 2720 B/op 30 allocs/op BenchmarkDefaultConfigProvider/Custom-16 450756 2651 ns/op 1008 B/op 6 allocs/op ``` Fixes #8633 Fixes #8618 Fixes #8630 Updates #8591 Closes #6680 Closes #5192
2021-03-14deps: Update to esbuild v0.9.0Bjørn Erik Pedersen
2021-02-16js: Fix potential path issue on WindowsBjørn Erik Pedersen
2021-02-01deps: Update to esbuild v0.8.39Bjørn Erik Pedersen
Fixes #8189
2021-01-22js: Add Inject config optionBjørn Erik Pedersen
Fixes #8164
2021-01-22js: Add Shims optionBjørn Erik Pedersen
This commit adds a new `shims` option to `js.Build` that allows swapping out a component with another. Fixes #8165
2021-01-21Fix nilpointer in js.Build error handlingBjørn Erik Pedersen
Fixes #8162
2021-01-18pipes: Add external source map support to js.Build and BabelAndreas Richter
Fixes #8132
2020-12-31dartsass: Add missing OutputStyle optionBjørn Erik Pedersen
2020-12-30Add Dart Sass supportBjørn Erik Pedersen
But note that the Dart Sass Embedded Protocol is still in beta (beta 5), a main release scheduled for Q1 2021. Fixes #7380 Fixes #8102
2020-12-19Improve LookPathBjørn Erik Pedersen
2020-12-16all: Fix minor typosPhil Davis
2020-12-03all: Format code with gofumptBjørn Erik Pedersen
See https://github.com/mvdan/gofumpt
2020-11-25deps: Update to github.com/evanw/esbuild 0.8.11 to 0.8.14Bjørn Erik Pedersen
Closes #7986
2020-11-13js: Let ESBuild handle all imports from node_modulesBjørn Erik Pedersen
This commit fixes some issues where modules in /assets share the same name as in node_modules. This was not intended, and with this commit the node_modules-components should be isolated. If you want to redefine something inside node_modules, use the `defines` option. Fixes #7948
2020-11-04js: Remove external source map optionBjørn Erik Pedersen
It was merged by accident and the implementation does not look correct. Fixes #7932
2020-11-04js: Misc fixesBjørn Erik Pedersen
* Fix resolve of package.json deps in submodules * Fix directory logic for writing assets/jsconfig.json Fixes #7924 Fixes #7923
2020-11-03js: Add avoidTDZ optionBjørn Erik Pedersen
Fixes #7865
2020-11-03Make js.Build fully support modulesBjørn Erik Pedersen
Fixes #7816 Fixes #7777 Fixes #7916
2020-11-03js.Build: Generate tsconfig filesAndreas Richter
Updates #7777 Added support to allow SourceMap files to be external to the build. In addition added more information when the js compilation has an error. Correctly append sourceMappingURL to output file. Fix merge conflict.
2020-10-22Allow getJSON errors to be ignoredBjørn Erik Pedersen
This change is mostly motivated to get a more stable CI build (we're building the Hugo site there, with Instagram and Twitter shortcodes sometimes failing). Fixes #7866
2020-09-13Add "hugo mod npm pack"Bjørn Erik Pedersen
This commit also introduces a convention where these common JS config files, including `package.hugo.json`, gets mounted into: ``` assets/_jsconfig ´`` These files mapped to their real filename will be added to the environment when running PostCSS, Babel etc., so you can do `process.env.HUGO_FILE_TAILWIND_CONFIG_JS` to resolve the real filename. But do note that `assets` is a composite/union filesystem, so if your config file is not meant to be overridden, name them something specific. This commit also adds adds `workDir/node_modules` to `NODE_PATH` and `HUGO_WORKDIR` to the env when running the JS tools above. Fixes #7644 Fixes #7656 Fixes #7675
2020-09-01js.Build: Add SourceMap flag with inline optionAndreas Richter
Added a flag to allow turning on sourcemap in ESBuild. The current support can only support inline or true as value for sourcemap. This is because the way ESBuild is invoked it doesn't have a separate output path to write the mapfile external to the asset pipeline. Add disable for "" and "0". Add test script and make sure mage check passes. Fixes #7607
2020-08-20Improve stderr logging for PostCSS and simlilarBjørn Erik Pedersen
Fixes #7584
2020-07-22resources/js: Add option for setting bundle formatBjørn Erik Pedersen
Fixes #7503
2020-07-22resources/js: Simplify options handlingBjørn Erik Pedersen
Mostly to minify cache hash breakage. Updates #7499
2020-07-20resources/js: Add es5 build targetBjørn Erik Pedersen
2020-07-17Add .Defines to js.Build optionsBjørn Erik Pedersen
This is needed to import `react` as a library, e.g.: ``` {{ $jsx := resources.Get "index.jsx" }} {{ $options := dict "defines" (dict "process.env.NODE_ENV" "\"development\"") }} {{ $js := $jsx | js.Build $options }} ``` Fixes #7489
2020-07-13Add proper Media Type handling in js.BuildBjørn Erik Pedersen
See #732
2020-07-13Add js.Build asset bundlingRemko Tronçon
Fixes #7321
2020-05-18Fix Babel on WindowsBjørn Erik Pedersen
Fixes #7251
2020-04-29Rename transpileJS to babelBjørn Erik Pedersen
And add a test. Updates #5764
2020-04-29resources: Add JavaScript transpiling solutionNiek de Wit
Add a new pipe called TranspileJS which uses the Babel cli. This makes it possible for users to write ES6 JavaScript code and transpile it to ES5 during website generation so that the code still works with older browser versions. Fixes #5764
2020-04-07Add basic "post resource publish support"Bjørn Erik Pedersen
Fixes #7146
2020-03-21Revert "resources: Add data context to the key in ExecuteAsTemplate"Bjørn Erik Pedersen
This reverts commit 18cb21ff2e4a60e7094908e4d6113a9d5a086316. Fixes #7064
2020-03-20Some minify configuration adjustmentsBjørn Erik Pedersen
2020-03-20Add minify configSatowTakeshi
Fixes #6750 Updates #6892
2020-03-17resources: Fix scss vs css import regexpBjørn Erik Pedersen
Fixes #7063
2020-03-16Add workaround for regular CSS imports in SCSSBjørn Erik Pedersen
Fixes #7059
2020-03-11resources: Add data context to the key in ExecuteAsTemplateBjørn Erik Pedersen
Fixes #7046
2020-03-11Improve Tailwind/PostCSS error messagesBjørn Erik Pedersen
Fixes #7041 Fixes #7042
2020-02-27resources: Add basic @import support to resources.PostCSSBjørn Erik Pedersen
This commit also makes the HUGO_ENVIRONMENT environment variable available to Node. Fixes #6957 Fixes #6961
2020-02-10Update to LibSass v3.6.3Bjørn Erik Pedersen
Fixes #6862
2020-01-22tpl/tplimpl: Rework template management to get rid of concurrency issuesBjørn Erik Pedersen
This more or less completes the simplification of the template handling code in Hugo started in v0.62. The main motivation was to fix a long lasting issue about a crash in HTML content files without front matter. But this commit also comes with a big functional improvement. As we now have moved the base template evaluation to the build stage we now use the same lookup rules for `baseof` as for `list` etc. type of templates. This means that in this simple example you can have a `baseof` template for the `blog` section without having to duplicate the others: ``` layouts ├── _default │   ├── baseof.html │   ├── list.html │   └── single.html └── blog └── baseof.html ``` Also, when simplifying code, you often get rid of some double work, as shown in the "site building" benchmarks below. These benchmarks looks suspiciously good, but I have repeated the below with ca. the same result. Compared to master: ``` name old time/op new time/op delta SiteNew/Bundle_with_image-16 13.1ms ± 1% 10.5ms ± 1% -19.34% (p=0.029 n=4+4) SiteNew/Bundle_with_JSON_file-16 13.0ms ± 0% 10.7ms ± 1% -18.05% (p=0.029 n=4+4) SiteNew/Tags_and_categories-16 46.4ms ± 2% 43.1ms ± 1% -7.15% (p=0.029 n=4+4) SiteNew/Canonify_URLs-16 52.2ms ± 2% 47.8ms ± 1% -8.30% (p=0.029 n=4+4) SiteNew/Deep_content_tree-16 77.9ms ± 1% 70.9ms ± 1% -9.01% (p=0.029 n=4+4) SiteNew/Many_HTML_templates-16 43.0ms ± 0% 37.2ms ± 1% -13.54% (p=0.029 n=4+4) SiteNew/Page_collections-16 58.2ms ± 1% 52.4ms ± 1% -9.95% (p=0.029 n=4+4) name old alloc/op new alloc/op delta SiteNew/Bundle_with_image-16 3.81MB ± 0% 2.22MB ± 0% -41.70% (p=0.029 n=4+4) SiteNew/Bundle_with_JSON_file-16 3.60MB ± 0% 2.01MB ± 0% -44.20% (p=0.029 n=4+4) SiteNew/Tags_and_categories-16 19.3MB ± 1% 14.1MB ± 0% -26.91% (p=0.029 n=4+4) SiteNew/Canonify_URLs-16 70.7MB ± 0% 69.0MB ± 0% -2.40% (p=0.029 n=4+4) SiteNew/Deep_content_tree-16 37.1MB ± 0% 31.2MB ± 0% -15.94% (p=0.029 n=4+4) SiteNew/Many_HTML_templates-16 17.6MB ± 0% 10.6MB ± 0% -39.92% (p=0.029 n=4+4) SiteNew/Page_collections-16 25.9MB ± 0% 21.2MB ± 0% -17.99% (p=0.029 n=4+4) name old allocs/op new allocs/op delta SiteNew/Bundle_with_image-16 52.3k ± 0% 26.1k ± 0% -50.18% (p=0.029 n=4+4) SiteNew/Bundle_with_JSON_file-16 52.3k ± 0% 26.1k ± 0% -50.16% (p=0.029 n=4+4) SiteNew/Tags_and_categories-16 336k ± 1% 269k ± 0% -19.90% (p=0.029 n=4+4) SiteNew/Canonify_URLs-16 422k ± 0% 395k ± 0% -6.43% (p=0.029 n=4+4) SiteNew/Deep_content_tree-16 401k ± 0% 313k ± 0% -21.79% (p=0.029 n=4+4) SiteNew/Many_HTML_templates-16 247k ± 0% 143k ± 0% -42.17% (p=0.029 n=4+4) SiteNew/Page_collections-16 282k ± 0% 207k ± 0% -26.55% (p=0.029 n=4+4) ``` Fixes #6716 Fixes #6760 Fixes #6768 Fixes #6778
2019-12-12Rework template handling for function and map lookupsBjørn Erik Pedersen
This is a big commit, but it deletes lots of code and simplifies a lot. * Resolving the template funcs at execution time means we don't have to create template clones per site * Having a custom map resolver means that we can remove the AST lower case transformation for the special lower case Params map Not only is the above easier to reason about, it's also faster, especially if you have more than one language, as in the benchmark below: ``` name old time/op new time/op delta SiteNew/Deep_content_tree-16 53.7ms ± 0% 48.1ms ± 2% -10.38% (p=0.029 n=4+4) name old alloc/op new alloc/op delta SiteNew/Deep_content_tree-16 41.0MB ± 0% 36.8MB ± 0% -10.26% (p=0.029 n=4+4) name old allocs/op new allocs/op delta SiteNew/Deep_content_tree-16 481k ± 0% 410k ± 0% -14.66% (p=0.029 n=4+4) ``` This should be even better if you also have lots of templates. Closes #6594