Browse Source

Added PostCSS to reduce size of CSS

pull/18/head
Anxhelo Lushka 3 years ago
parent
commit
0944fad4a1
  1. 1
      .gitignore
  2. 7
      layouts/partials/head.html
  3. 4
      layouts/partials/javascript.html
  4. 1487
      package-lock.json
  5. 7
      package.json
  6. 13
      postcss.config.js

1
.gitignore

@ -2,3 +2,4 @@
.hugo_build.lock .hugo_build.lock
resources/ resources/
public/ public/
node_modules/

7
layouts/partials/head.html

@ -19,10 +19,15 @@
<!-- CSS --> <!-- CSS -->
{{ $options := (dict "targetPath" "main.css" "outputStyle" "compressed" "enableSourceMap" true) }} {{ $options := (dict "targetPath" "main.css" "outputStyle" "compressed" "enableSourceMap" true) }}
{{ $style := resources.Get "scss/main.scss" | resources.ToCSS $options }} {{ $style := resources.Get "scss/main.scss" | resources.ToCSS $options }}
{{ if hugo.IsProduction }}
{{ $style = $style | resources.PostCSS | resources.Fingerprint "sha256" }}
{{ end }}
<link rel="stylesheet" href="{{ $style.RelPermalink }}" /> <link rel="stylesheet" href="{{ $style.RelPermalink }}" />
{{ range $val := $.Site.Params.customCSS }} {{ if gt (len $val) 0 }} {{ range $val := $.Site.Params.customCSS }} {{ if gt (len $val) 0 }}
<link rel="stylesheet" type="text/css" href="{{ $val }}" /> <link rel="stylesheet" type="text/css" href="{{ $val }}" integrity="{{ $style.Data.Integrity }}" />
{{ end }} {{ end }}
{{ end }} {{ end }}

4
layouts/partials/javascript.html

@ -1,6 +1,6 @@
{{ $bootstrap := resources.Get "js/bootstrap.bundle.min.js" }} {{ $bootstrap := resources.Get "js/bootstrap.bundle.min.js" }}
{{ $secureJS := slice $bootstrap | resources.Concat "bundle.js" | resources.Minify }} {{ $secureJS := slice $bootstrap | resources.Concat "bundle.js" | resources.Minify | resources.Fingerprint "sha512" }}
<script src="{{ $secureJS.RelPermalink }}"></script> <script src="{{ $secureJS.RelPermalink }}" integrity="{{ $secureJS.Data.Integrity }}"></script>
{{ range $val := $.Site.Params.customJS }} {{ range $val := $.Site.Params.customJS }}
{{ if gt (len $val) 0 }} {{ if gt (len $val) 0 }}

1487
package-lock.json

File diff suppressed because it is too large

7
package.json

@ -0,0 +1,7 @@
{
"dependencies": {
"@fullhuman/postcss-purgecss": "^4.1.3",
"postcss": "^8.4.14",
"postcss-cli": "^10.0.0"
}
}

13
postcss.config.js

@ -0,0 +1,13 @@
module.exports = {
plugins: {
"@fullhuman/postcss-purgecss": {
content: [
"./assets/js/*.js",
"./content/*.md",
"./layouts/**/*.html",
],
safelist: ["arrow", "tooltip", "tooltip-arrow", "tooltip-inner"],
blocklist: [""],
},
},
};
Loading…
Cancel
Save