Setup javascript minification
MODIFY
website/.eleventy.js
website/.eleventy.js
@@ -2,6 +2,7 @@ const syntaxHighlight = require("@11ty/eleventy-plugin-syntaxhighlight");
const CleanCSS = require("clean-css");
const markdownIt = require("markdown-it");
const markdownItAnchor = require('markdown-it-anchor');
+const Terser = require("terser");
module.exports = function(eleventyConfig) {
@@ -9,6 +10,17 @@ module.exports = function(eleventyConfig) {
return new CleanCSS({}).minify(code).styles;
});
+
+ eleventyConfig.addFilter("jsmin", function(code) {
+ let minified = Terser.minify(code);
+ if( minified.error ) {
+ console.log("Terser error: ", minified.error);
+ return code;
+ }
+
+ return minified.code;
+ });
+
eleventyConfig.addPlugin(syntaxHighlight);
let options = {

MODIFY
website/package.json
website/package.json
"@11ty/eleventy": "^0.11.0",
"@11ty/eleventy-plugin-syntaxhighlight": "^3.0.1",
"clean-css": "^4.2.3",
- "markdown-it-anchor": "^5.3.0"
+ "markdown-it-anchor": "^5.3.0",
+ "terser": "^4.7.0"
}
}

MODIFY
website/src/includes/layout.njk
website/src/includes/layout.njk
@@ -35,17 +35,10 @@ title: A JavaScript toolchain | Rome
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/tocbot/4.11.1/tocbot.min.js"></script>
- <script>
- tocbot.init({
- tocSelector: '.table-of-contents',
- contentSelector: '.content',
- headingSelector: 'h1, h2, h3',
- hasInnerContainers: true,
- collapseDepth: 3,
- });
+ {% set js %}{% include "main.js" %}{% endset %}
- </script>
+ <script>{{ js | jsmin | safe }}</script>
</body>
</html>
\ No newline at end of file

ADD
website/src/includes/main.js
+tocbot.init({
+ tocSelector: '.table-of-contents',
+ contentSelector: '.content',
+ headingSelector: 'h1, h2, h3',
+ hasInnerContainers: true,
+ collapseDepth: 3,
+});
\ No newline at end of file

MODIFY
website/yarn.lock
website/yarn.lock
@@ -484,6 +484,11 @@ bs-snippet-injector@^2.0.1:
resolved "https://registry.yarnpkg.com/bs-snippet-injector/-/bs-snippet-injector-2.0.1.tgz#61b5393f11f52559ed120693100343b6edb04dd5"
integrity sha1-YbU5PxH1JVntEgaTEANDtu2wTdU=
+buffer-from@^1.0.0:
+ version "1.1.1"
+ resolved "https://registry.yarnpkg.com/buffer-from/-/buffer-from-1.1.1.tgz#32713bc028f75c02fdb710d7c7bcec1f2c6070ef"
+ integrity sha512-MQcXEUbCKtEo7bhqEs6560Hyd4XaovZlO/k9V3hjVUF/zwW7KBVdSK4gIt/bzwS9MbR5qob+F5jusZsb0YQK2A==
+
bytes@3.1.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/bytes/-/bytes-3.1.0.tgz#f6cf7933a360e0588fa9fde85651cdc7f805d1f6"
@@ -665,7 +670,7 @@ color-name@~1.1.4:
resolved "https://registry.yarnpkg.com/color-name/-/color-name-1.1.4.tgz#c2a09a87acbde69543de6f63fa3995c826c536a2"
integrity sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==
-commander@^2.19.0, commander@^2.2.0, commander@~2.20.3:
+commander@^2.19.0, commander@^2.2.0, commander@^2.20.0, commander@~2.20.3:
version "2.20.3"
resolved "https://registry.yarnpkg.com/commander/-/commander-2.20.3.tgz#fd485e84c03eb4881c20722ba48035e8531aeb33"
integrity sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==
@@ -2878,6 +2883,14 @@ source-map-resolve@^0.5.0:
source-map-url "^0.4.0"
urix "^0.1.0"
+source-map-support@~0.5.12:
+ version "0.5.19"
+ resolved "https://registry.yarnpkg.com/source-map-support/-/source-map-support-0.5.19.tgz#a98b62f86dcaf4f67399648c085291ab9e8fed61"
+ integrity sha512-Wonm7zOCIJzBGQdB+thsPar0kYuCIzYvxZwlBa87yi/Mdjv7Tip2cyVbLj5o0cFPN4EVkuTwb3GDDyUx2DGnGw==
+ dependencies:
+ buffer-from "^1.0.0"
+ source-map "^0.6.0"
+
source-map-url@^0.4.0:
version "0.4.0"
resolved "https://registry.yarnpkg.com/source-map-url/-/source-map-url-0.4.0.tgz#3e935d7ddd73631b97659956d55128e87b5084a3"
@@ -2888,7 +2901,7 @@ source-map@^0.5.6, source-map@~0.5.1:
resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.5.7.tgz#8a039d2d1021d22d1ea14c80d8ea468ba2ef3fcc"
integrity sha1-igOdLRAh0i0eoUyA2OpGi6LvP8w=
-source-map@^0.6.1, source-map@~0.6.0:
+source-map@^0.6.0, source-map@^0.6.1, source-map@~0.6.0, source-map@~0.6.1:
version "0.6.1"
resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.6.1.tgz#74722af32e9614e9c287a8d0bbde48b5e2f1a263"
integrity sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==
@@ -3019,6 +3032,15 @@ symbol-observable@1.0.1:
resolved "https://registry.yarnpkg.com/symbol-observable/-/symbol-observable-1.0.1.tgz#8340fc4702c3122df5d22288f88283f513d3fdd4"
integrity sha1-g0D8RwLDEi310iKI+IKD9RPT/dQ=
+terser@^4.7.0:
+ version "4.7.0"
+ resolved "https://registry.yarnpkg.com/terser/-/terser-4.7.0.tgz#15852cf1a08e3256a80428e865a2fa893ffba006"
+ integrity sha512-Lfb0RiZcjRDXCC3OSHJpEkxJ9Qeqs6mp2v4jf2MHfy8vGERmVDuvjXdd/EnP5Deme5F2yBRBymKmKHCBg2echw==
+ dependencies:
+ commander "^2.20.0"
+ source-map "~0.6.1"
+ source-map-support "~0.5.12"
+
text-table@^0.2.0:
version "0.2.0"
resolved "https://registry.yarnpkg.com/text-table/-/text-table-0.2.0.tgz#7f5ee823ae805207c00af2df4a84ec3fcfa570b4"

Setup javascript minification