From 75d12d49dee786e5d426fdf0d375cf3e05552292 Mon Sep 17 00:00:00 2001 From: Tania Allard Date: Mon, 2 Sep 2024 12:38:47 +0100 Subject: [PATCH] ENH - Update bundling and vendoring (JS) (#1955) Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- .gitignore | 1 + package-lock.json | 481 +++++++++--------- package.json | 12 +- .../assets/scripts/bootstrap.js | 4 +- .../assets/scripts/fontawesome.js | 5 + .../assets/styles/bootstrap.scss | 5 - .../assets/styles/pydata-sphinx-theme.scss | 14 +- .../assets/styles/variables/_fonts.scss | 1 + .../theme/pydata_sphinx_theme/layout.html | 1 - .../pydata_sphinx_theme/static/.gitignore | 5 + tests/test_build.py | 2 +- webpack.config.js | 127 ++--- 12 files changed, 345 insertions(+), 313 deletions(-) create mode 100644 src/pydata_sphinx_theme/assets/scripts/fontawesome.js delete mode 100644 src/pydata_sphinx_theme/assets/styles/bootstrap.scss diff --git a/.gitignore b/.gitignore index 08eaa6b21..a6c8d35a0 100644 --- a/.gitignore +++ b/.gitignore @@ -105,6 +105,7 @@ envs/ .nodeenv/ .yarn-packages node_modules/ +bun.lockb # Editors .vscode diff --git a/package-lock.json b/package-lock.json index b7a6e37a6..88ac40d9d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,19 +9,22 @@ "@fortawesome/fontawesome-free": "^6.5.1", "@popperjs/core": "^2.11.6", "bootstrap": "^5.2.2", - "compare-versions": "^5.0.3" + "compare-versions": "^5.0.3", + "webpack-bundle-analyzer": "^4.10.2" }, "devDependencies": { "axe-core": "^4.6.3", - "copy-webpack-plugin": "^11.0.0", "css-loader": "^6.8.1", "css-minimizer-webpack-plugin": "^4.2.2", "dedent": "^0.7.0", "html-webpack-plugin": "^5.0.0", "imports-loader": "^0.8.0", "mini-css-extract-plugin": "^2.7.5", + "resolve-url-loader": "^5.0.0", "sass": "^1.59.3", "sass-loader": "^10.3.1", + "style-loader": "^4.0.0", + "terser-webpack-plugin": "^5.3.10", "webpack": "^5.0.0", "webpack-cli": "^5.0.0" } @@ -30,7 +33,6 @@ "version": "0.5.7", "resolved": "https://registry.npmjs.org/@discoveryjs/json-ext/-/json-ext-0.5.7.tgz", "integrity": "sha512-dBVuXR082gk3jsFp7Rd/JI4kytwGHecnCoTtXFb7DB6CNHp4rg5k1bhg0nWdLGLnOV71lmDzGQaLMy8iPLY0pw==", - "dev": true, "engines": { "node": ">=10.0.0" } @@ -131,40 +133,10 @@ "@jridgewell/sourcemap-codec": "^1.4.14" } }, - "node_modules/@nodelib/fs.scandir": { - "version": "2.1.5", - "resolved": "https://registry.npmjs.org/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz", - "integrity": "sha512-vq24Bq3ym5HEQm2NKCr3yXDwjc7vTsEThRDnkp2DK9p1uqLR+DHurm/NOTo0KG7HYHU7eppKZj3MyqYuMBf62g==", - "dev": true, - "dependencies": { - "@nodelib/fs.stat": "2.0.5", - "run-parallel": "^1.1.9" - }, - "engines": { - "node": ">= 8" - } - }, - "node_modules/@nodelib/fs.stat": { - "version": "2.0.5", - "resolved": "https://registry.npmjs.org/@nodelib/fs.stat/-/fs.stat-2.0.5.tgz", - "integrity": "sha512-RkhPPp2zrqDAQA/2jNhnztcPAlv64XdhIp7a7454A5ovI7Bukxgt7MX7udwAu3zg1DcpPU0rz3VV1SeaqvY4+A==", - "dev": true, - "engines": { - "node": ">= 8" - } - }, - "node_modules/@nodelib/fs.walk": { - "version": "1.2.8", - "resolved": "https://registry.npmjs.org/@nodelib/fs.walk/-/fs.walk-1.2.8.tgz", - "integrity": "sha512-oGB+UxlgWcgQkgwo8GcEGwemoTFt3FIO9ababBmaGwXIoBKZ+GTy0pP185beGg7Llih/NSHSV2XAs1lnznocSg==", - "dev": true, - "dependencies": { - "@nodelib/fs.scandir": "2.1.5", - "fastq": "^1.6.0" - }, - "engines": { - "node": ">= 8" - } + "node_modules/@polka/url": { + "version": "1.0.0-next.25", + "resolved": "https://registry.npmjs.org/@polka/url/-/url-1.0.0-next.25.tgz", + "integrity": "sha512-j7P6Rgr3mmtdkeDGTe0E/aYyWEWVtc5yFXtHCRHs28/jptDEWfaVOc5T7cblqy1XKPPfCxJc/8DwQ5YgLOZOVQ==" }, "node_modules/@popperjs/core": { "version": "2.11.8", @@ -482,7 +454,6 @@ "version": "8.11.3", "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.11.3.tgz", "integrity": "sha512-Y9rRfJG5jcKOE0CLisYbojUjIrIEE7AGMzA/Sm4BslANhbS+cDMpgBdcPT91oJ7OuJ9hYJBx59RjbhxVnrF8Xg==", - "dev": true, "bin": { "acorn": "bin/acorn" }, @@ -499,6 +470,56 @@ "acorn": "^8" } }, + "node_modules/acorn-walk": { + "version": "8.3.3", + "resolved": "https://registry.npmjs.org/acorn-walk/-/acorn-walk-8.3.3.tgz", + "integrity": "sha512-MxXdReSRhGO7VlFe1bRG/oI7/mdLV9B9JJT0N8vZOhF7gFRR5l3M8W9G8JxmKV+JC5mGqJ0QvqfSOLsCPa4nUw==", + "dependencies": { + "acorn": "^8.11.0" + }, + "engines": { + "node": ">=0.4.0" + } + }, + "node_modules/adjust-sourcemap-loader": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/adjust-sourcemap-loader/-/adjust-sourcemap-loader-4.0.0.tgz", + "integrity": "sha512-OXwN5b9pCUXNQHJpwwD2qP40byEmSgzj8B4ydSN0uMNYWiFmJ6x6KwUllMmfk8Rwu/HJDFR7U8ubsWBoN0Xp0A==", + "dev": true, + "dependencies": { + "loader-utils": "^2.0.0", + "regex-parser": "^2.2.11" + }, + "engines": { + "node": ">=8.9" + } + }, + "node_modules/adjust-sourcemap-loader/node_modules/json5": { + "version": "2.2.3", + "resolved": "https://registry.npmjs.org/json5/-/json5-2.2.3.tgz", + "integrity": "sha512-XmOWe7eyHYH14cLdVPoyg+GOH3rYX++KpzrylJwSW98t3Nk+U8XOl8FWKOgwtzdb8lXGf6zYwDUzeHMWfxasyg==", + "dev": true, + "bin": { + "json5": "lib/cli.js" + }, + "engines": { + "node": ">=6" + } + }, + "node_modules/adjust-sourcemap-loader/node_modules/loader-utils": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/loader-utils/-/loader-utils-2.0.4.tgz", + "integrity": "sha512-xXqpXoINfFhgua9xiqD8fPFHgkoq1mmmpE92WlDbm9rNRd/EbRb+Gqf908T2DMfuHjjJlksiK2RbHVOdD/MqSw==", + "dev": true, + "dependencies": { + "big.js": "^5.2.2", + "emojis-list": "^3.0.0", + "json5": "^2.1.2" + }, + "engines": { + "node": ">=8.9.0" + } + }, "node_modules/ajv": { "version": "8.12.0", "resolved": "https://registry.npmjs.org/ajv/-/ajv-8.12.0.tgz", @@ -885,29 +906,11 @@ "resolved": "https://registry.npmjs.org/compare-versions/-/compare-versions-5.0.3.tgz", "integrity": "sha512-4UZlZP8Z99MGEY+Ovg/uJxJuvoXuN4M6B3hKaiackiHrgzQFEe3diJi1mf1PNHbFujM7FvLrK2bpgIaImbtZ1A==" }, - "node_modules/copy-webpack-plugin": { - "version": "11.0.0", - "resolved": "https://registry.npmjs.org/copy-webpack-plugin/-/copy-webpack-plugin-11.0.0.tgz", - "integrity": "sha512-fX2MWpamkW0hZxMEg0+mYnA40LTosOSa5TqZ9GYIBzyJa9C3QUaMPSE2xAi/buNr8u89SfD9wHSQVBzrRa/SOQ==", - "dev": true, - "dependencies": { - "fast-glob": "^3.2.11", - "glob-parent": "^6.0.1", - "globby": "^13.1.1", - "normalize-path": "^3.0.0", - "schema-utils": "^4.0.0", - "serialize-javascript": "^6.0.0" - }, - "engines": { - "node": ">= 14.15.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/webpack" - }, - "peerDependencies": { - "webpack": "^5.1.0" - } + "node_modules/convert-source-map": { + "version": "1.9.0", + "resolved": "https://registry.npmjs.org/convert-source-map/-/convert-source-map-1.9.0.tgz", + "integrity": "sha512-ASFBup0Mz1uyiIjANan1jzLQami9z1PoYSZCiiYW2FczPbenXc45FZdBZLzOT+r6+iciuEModtmCti+hjaAk0A==", + "dev": true }, "node_modules/cross-spawn": { "version": "7.0.3", @@ -1155,24 +1158,17 @@ "node": ">=8.0.0" } }, + "node_modules/debounce": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/debounce/-/debounce-1.2.1.tgz", + "integrity": "sha512-XRRe6Glud4rd/ZGQfiV1ruXSfbvfJedlV9Y6zOlP+2K04vBYiJEte6stfFkCP03aMnY5tsipamumUjL14fofug==" + }, "node_modules/dedent": { "version": "0.7.0", "resolved": "https://registry.npmjs.org/dedent/-/dedent-0.7.0.tgz", "integrity": "sha512-Q6fKUPqnAHAyhiUgFU7BUzLiv0kd8saH9al7tnu5Q/okj6dnupxyTgFIBjVzJATdfIAm9NAsvXNzjaKa+bxVyA==", "dev": true }, - "node_modules/dir-glob": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/dir-glob/-/dir-glob-3.0.1.tgz", - "integrity": "sha512-WkrWp9GR4KXfKGYzOLmTuGVi1UWFfws377n9cc55/tb6DuqyF6pcQ5AbiHEshaDpY9v6oaSr2XCDidGmMwdzIA==", - "dev": true, - "dependencies": { - "path-type": "^4.0.0" - }, - "engines": { - "node": ">=8" - } - }, "node_modules/dom-converter": { "version": "0.2.0", "resolved": "https://registry.npmjs.org/dom-converter/-/dom-converter-0.2.0.tgz", @@ -1247,6 +1243,11 @@ "tslib": "^2.0.3" } }, + "node_modules/duplexer": { + "version": "0.1.2", + "resolved": "https://registry.npmjs.org/duplexer/-/duplexer-0.1.2.tgz", + "integrity": "sha512-jtD6YG370ZCIi/9GTaJKQxWTZD045+4R4hTk/x1UyoqadyJ9x9CgSi1RlVDQF8U2sxLLSnFkCaMihqljHIWgMg==" + }, "node_modules/electron-to-chromium": { "version": "1.4.735", "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.735.tgz", @@ -1311,6 +1312,17 @@ "node": ">=6" } }, + "node_modules/escape-string-regexp": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-4.0.0.tgz", + "integrity": "sha512-TtpcNJ3XAzx3Gq8sWRzJaVajRs0uVxA2YAkdb1jm2YkPz4G6egUFAyA3n5vtEIZefPk5Wa4UXbKuS5fKkJWdgA==", + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/eslint-scope": { "version": "5.1.1", "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-5.1.1.tgz", @@ -1369,34 +1381,6 @@ "integrity": "sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==", "dev": true }, - "node_modules/fast-glob": { - "version": "3.3.2", - "resolved": "https://registry.npmjs.org/fast-glob/-/fast-glob-3.3.2.tgz", - "integrity": "sha512-oX2ruAFQwf/Orj8m737Y5adxDQO0LAB7/S5MnxCdTNDd4p6BsyIVsv9JQsATbTSq8KHRpLwIHbVlUNatxd+1Ow==", - "dev": true, - "dependencies": { - "@nodelib/fs.stat": "^2.0.2", - "@nodelib/fs.walk": "^1.2.3", - "glob-parent": "^5.1.2", - "merge2": "^1.3.0", - "micromatch": "^4.0.4" - }, - "engines": { - "node": ">=8.6.0" - } - }, - "node_modules/fast-glob/node_modules/glob-parent": { - "version": "5.1.2", - "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-5.1.2.tgz", - "integrity": "sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow==", - "dev": true, - "dependencies": { - "is-glob": "^4.0.1" - }, - "engines": { - "node": ">= 6" - } - }, "node_modules/fast-json-stable-stringify": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/fast-json-stable-stringify/-/fast-json-stable-stringify-2.1.0.tgz", @@ -1412,15 +1396,6 @@ "node": ">= 4.9.1" } }, - "node_modules/fastq": { - "version": "1.17.1", - "resolved": "https://registry.npmjs.org/fastq/-/fastq-1.17.1.tgz", - "integrity": "sha512-sRVD3lWVIXWg6By68ZN7vho9a1pQcN/WBFaAAsDDFzlJjvoGx0P8z7V1t72grFJfJhu3YPZBuu25f7Kaw2jN1w==", - "dev": true, - "dependencies": { - "reusify": "^1.0.4" - } - }, "node_modules/fill-range": { "version": "7.1.1", "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.1.1.tgz", @@ -1478,49 +1453,32 @@ "url": "https://github.com/sponsors/ljharb" } }, - "node_modules/glob-parent": { - "version": "6.0.2", - "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-6.0.2.tgz", - "integrity": "sha512-XxwI8EOhVQgWp6iDL+3b0r86f4d6AX6zSU55HfB4ydCEuXLXc5FcYeOu+nnGftS4TEju/11rt4KJPTMgbfmv4A==", - "dev": true, - "dependencies": { - "is-glob": "^4.0.3" - }, - "engines": { - "node": ">=10.13.0" - } - }, "node_modules/glob-to-regexp": { "version": "0.4.1", "resolved": "https://registry.npmjs.org/glob-to-regexp/-/glob-to-regexp-0.4.1.tgz", "integrity": "sha512-lkX1HJXwyMcprw/5YUZc2s7DrpAiHB21/V+E1rHUrVNokkvB6bqMzT0VfV6/86ZNabt1k14YOIaT7nDvOX3Iiw==", "dev": true }, - "node_modules/globby": { - "version": "13.2.2", - "resolved": "https://registry.npmjs.org/globby/-/globby-13.2.2.tgz", - "integrity": "sha512-Y1zNGV+pzQdh7H39l9zgB4PJqjRNqydvdYCDG4HFXM4XuvSaQQlEc91IU1yALL8gUTDomgBAfz3XJdmUS+oo0w==", - "dev": true, + "node_modules/graceful-fs": { + "version": "4.2.11", + "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.11.tgz", + "integrity": "sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ==", + "dev": true + }, + "node_modules/gzip-size": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/gzip-size/-/gzip-size-6.0.0.tgz", + "integrity": "sha512-ax7ZYomf6jqPTQ4+XCpUGyXKHk5WweS+e05MBO4/y3WJ5RkmPXNKvX+bx1behVILVwr6JSQvZAku021CHPXG3Q==", "dependencies": { - "dir-glob": "^3.0.1", - "fast-glob": "^3.3.0", - "ignore": "^5.2.4", - "merge2": "^1.4.1", - "slash": "^4.0.0" + "duplexer": "^0.1.2" }, "engines": { - "node": "^12.20.0 || ^14.13.1 || >=16.0.0" + "node": ">=10" }, "funding": { "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/graceful-fs": { - "version": "4.2.11", - "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.11.tgz", - "integrity": "sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ==", - "dev": true - }, "node_modules/has-flag": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", @@ -1551,6 +1509,11 @@ "he": "bin/he" } }, + "node_modules/html-escaper": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/html-escaper/-/html-escaper-2.0.2.tgz", + "integrity": "sha512-H2iMtd0I4Mt5eYiapRdIDjp+XzelXQ0tFE4JS7YFwFevXXMmOp9myNrUvCg0D6ws8iqkRPBfKHgbwig1SmlLfg==" + }, "node_modules/html-minifier-terser": { "version": "6.1.0", "resolved": "https://registry.npmjs.org/html-minifier-terser/-/html-minifier-terser-6.1.0.tgz", @@ -1635,15 +1598,6 @@ "postcss": "^8.1.0" } }, - "node_modules/ignore": { - "version": "5.3.1", - "resolved": "https://registry.npmjs.org/ignore/-/ignore-5.3.1.tgz", - "integrity": "sha512-5Fytz/IraMjqpwfd34ke28PTVMjZjJG2MPn5t7OE4eUCUNf8BAa7b5WUS9/Qvr6mwOQS7Mk6vdsMno5he+T8Xw==", - "dev": true, - "engines": { - "node": ">= 4" - } - }, "node_modules/immutable": { "version": "4.3.5", "resolved": "https://registry.npmjs.org/immutable/-/immutable-4.3.5.tgz", @@ -1941,28 +1895,6 @@ "integrity": "sha512-abv/qOcuPfk3URPfDzmZU1LKmuw8kT+0nIHvKrKgFrwifol/doWcdA4ZqsWQ8ENrFKkd67Mfpo/LovbIUsbt3w==", "dev": true }, - "node_modules/merge2": { - "version": "1.4.1", - "resolved": "https://registry.npmjs.org/merge2/-/merge2-1.4.1.tgz", - "integrity": "sha512-8q7VEgMJW4J8tcfVPy8g09NcQwZdbwFEqhe/WZkoIzjn/3TGDwtOCYtXGxA3O8tPzpczCCDgv+P2P5y00ZJOOg==", - "dev": true, - "engines": { - "node": ">= 8" - } - }, - "node_modules/micromatch": { - "version": "4.0.5", - "resolved": "https://registry.npmjs.org/micromatch/-/micromatch-4.0.5.tgz", - "integrity": "sha512-DMy+ERcEW2q8Z2Po+WNXuw3c5YaUSFjAO5GsJqfEl7UjvtIuFKO6ZrKvcItdy98dwFI2N1tg3zNIdKaQT+aNdA==", - "dev": true, - "dependencies": { - "braces": "^3.0.2", - "picomatch": "^2.3.1" - }, - "engines": { - "node": ">=8.6" - } - }, "node_modules/mime-db": { "version": "1.52.0", "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz", @@ -2013,6 +1945,14 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/mrmime": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/mrmime/-/mrmime-2.0.0.tgz", + "integrity": "sha512-eu38+hdgojoyq63s+yTpN4XMBdt5l8HhMhc4VKLO9KM5caLIBvUm4thi7fFaxyTmCKeNnXZ5pAlBwCUnhA09uw==", + "engines": { + "node": ">=10" + } + }, "node_modules/nanoid": { "version": "3.3.7", "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.7.tgz", @@ -2086,6 +2026,14 @@ "url": "https://github.com/fb55/nth-check?sponsor=1" } }, + "node_modules/opener": { + "version": "1.5.2", + "resolved": "https://registry.npmjs.org/opener/-/opener-1.5.2.tgz", + "integrity": "sha512-ur5UIdyw5Y7yEj9wLzhqXiy6GZ3Mwx0yGI+5sMn2r0N0v3cKJvUmFH5yPP+WXh9e0xfyzyJX95D8l088DNFj7A==", + "bin": { + "opener": "bin/opener-bin.js" + } + }, "node_modules/p-limit": { "version": "2.3.0", "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-2.3.0.tgz", @@ -2166,20 +2114,10 @@ "integrity": "sha512-LDJzPVEEEPR+y48z93A0Ed0yXb8pAByGWo/k5YYdYgpY2/2EsOsksJrq7lOHxryrVOn1ejG6oAp8ahvOIQD8sw==", "dev": true }, - "node_modules/path-type": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/path-type/-/path-type-4.0.0.tgz", - "integrity": "sha512-gDKb8aZMDeD/tZWs9P6+q0J9Mwkdl6xMV8TjnGP3qJVJ06bdMgkbBlLU8IdfOsIsFz2BW1rNVT3XuNEl8zPAvw==", - "dev": true, - "engines": { - "node": ">=8" - } - }, "node_modules/picocolors": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.0.0.tgz", - "integrity": "sha512-1fygroTLlHu66zi26VoTDv8yRgm0Fccecssto+MhsZ0D/DGW2sm8E8AjW7NU5VVTRt5GxbeZ5qBuJr+HyLYkjQ==", - "dev": true + "integrity": "sha512-1fygroTLlHu66zi26VoTDv8yRgm0Fccecssto+MhsZ0D/DGW2sm8E8AjW7NU5VVTRt5GxbeZ5qBuJr+HyLYkjQ==" }, "node_modules/picomatch": { "version": "2.3.1", @@ -2735,26 +2673,6 @@ "node": ">=6" } }, - "node_modules/queue-microtask": { - "version": "1.2.3", - "resolved": "https://registry.npmjs.org/queue-microtask/-/queue-microtask-1.2.3.tgz", - "integrity": "sha512-NuaNSa6flKT5JaSYQzJok04JzTL1CA6aGhv5rfLW3PgqA+M2ChpZQnAC8h8i4ZFkBS8X5RqkDBHA7r4hej3K9A==", - "dev": true, - "funding": [ - { - "type": "github", - "url": "https://github.com/sponsors/feross" - }, - { - "type": "patreon", - "url": "https://www.patreon.com/feross" - }, - { - "type": "consulting", - "url": "https://feross.org/support" - } - ] - }, "node_modules/randombytes": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/randombytes/-/randombytes-2.1.0.tgz", @@ -2788,6 +2706,12 @@ "node": ">= 10.13.0" } }, + "node_modules/regex-parser": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/regex-parser/-/regex-parser-2.3.0.tgz", + "integrity": "sha512-TVILVSz2jY5D47F4mA4MppkBrafEaiUWJO/TcZHEIuI13AqoZMkK1WMA4Om1YkYbTx+9Ki1/tSUXbceyr9saRg==", + "dev": true + }, "node_modules/relateurl": { "version": "0.2.7", "resolved": "https://registry.npmjs.org/relateurl/-/relateurl-0.2.7.tgz", @@ -2857,37 +2781,46 @@ "node": ">=8" } }, - "node_modules/reusify": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/reusify/-/reusify-1.0.4.tgz", - "integrity": "sha512-U9nH88a3fc/ekCF1l0/UP1IosiuIjyTh7hBvXVMHYgVcfGvt897Xguj2UOLDeI5BG2m7/uwyaLVT6fbtCwTyzw==", + "node_modules/resolve-url-loader": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/resolve-url-loader/-/resolve-url-loader-5.0.0.tgz", + "integrity": "sha512-uZtduh8/8srhBoMx//5bwqjQ+rfYOUq8zC9NrMUGtjBiGTtFJM42s58/36+hTqeqINcnYe08Nj3LkK9lW4N8Xg==", "dev": true, + "dependencies": { + "adjust-sourcemap-loader": "^4.0.0", + "convert-source-map": "^1.7.0", + "loader-utils": "^2.0.0", + "postcss": "^8.2.14", + "source-map": "0.6.1" + }, "engines": { - "iojs": ">=1.0.0", - "node": ">=0.10.0" + "node": ">=12" } }, - "node_modules/run-parallel": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/run-parallel/-/run-parallel-1.2.0.tgz", - "integrity": "sha512-5l4VyZR86LZ/lDxZTR6jqL8AFE2S0IFLMP26AbjsLVADxHdhB/c0GUsH+y39UfCi3dzz8OlQuPmnaJOMoDHQBA==", + "node_modules/resolve-url-loader/node_modules/json5": { + "version": "2.2.3", + "resolved": "https://registry.npmjs.org/json5/-/json5-2.2.3.tgz", + "integrity": "sha512-XmOWe7eyHYH14cLdVPoyg+GOH3rYX++KpzrylJwSW98t3Nk+U8XOl8FWKOgwtzdb8lXGf6zYwDUzeHMWfxasyg==", + "dev": true, + "bin": { + "json5": "lib/cli.js" + }, + "engines": { + "node": ">=6" + } + }, + "node_modules/resolve-url-loader/node_modules/loader-utils": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/loader-utils/-/loader-utils-2.0.4.tgz", + "integrity": "sha512-xXqpXoINfFhgua9xiqD8fPFHgkoq1mmmpE92WlDbm9rNRd/EbRb+Gqf908T2DMfuHjjJlksiK2RbHVOdD/MqSw==", "dev": true, - "funding": [ - { - "type": "github", - "url": "https://github.com/sponsors/feross" - }, - { - "type": "patreon", - "url": "https://www.patreon.com/feross" - }, - { - "type": "consulting", - "url": "https://feross.org/support" - } - ], "dependencies": { - "queue-microtask": "^1.2.2" + "big.js": "^5.2.2", + "emojis-list": "^3.0.0", + "json5": "^2.1.2" + }, + "engines": { + "node": ">=8.9.0" } }, "node_modules/safe-buffer": { @@ -3115,16 +3048,17 @@ "node": ">=8" } }, - "node_modules/slash": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/slash/-/slash-4.0.0.tgz", - "integrity": "sha512-3dOsAHXXUkQTpOYcoAxLIorMTp4gIQr5IW3iVb7A7lFIp0VHhnynm9izx6TssdrIcVIESAlVjtnO2K8bg+Coew==", - "dev": true, - "engines": { - "node": ">=12" + "node_modules/sirv": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/sirv/-/sirv-2.0.4.tgz", + "integrity": "sha512-94Bdh3cC2PKrbgSOUqTiGPWVZeSiXfKOVZNJniWoqrWrRkB1CJzBU3NEbiTsPcYy1lDsANA/THzS+9WBiy5nfQ==", + "dependencies": { + "@polka/url": "^1.0.0-next.24", + "mrmime": "^2.0.0", + "totalist": "^3.0.0" }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" + "engines": { + "node": ">= 10" } }, "node_modules/source-map": { @@ -3174,6 +3108,22 @@ "node": ">=8" } }, + "node_modules/style-loader": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/style-loader/-/style-loader-4.0.0.tgz", + "integrity": "sha512-1V4WqhhZZgjVAVJyt7TdDPZoPBPNHbekX4fWnCJL1yQukhCeZhJySUL+gL9y6sNdN95uEOS83Y55SqHcP7MzLA==", + "dev": true, + "engines": { + "node": ">= 18.12.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/webpack" + }, + "peerDependencies": { + "webpack": "^5.27.0" + } + }, "node_modules/stylehacks": { "version": "5.1.1", "resolved": "https://registry.npmjs.org/stylehacks/-/stylehacks-5.1.1.tgz", @@ -3389,6 +3339,14 @@ "node": ">=8.0" } }, + "node_modules/totalist": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/totalist/-/totalist-3.0.1.tgz", + "integrity": "sha512-sf4i37nQ2LBx4m3wB74y+ubopq6W/dIzXg0FDGjsYnZHVa1Da8FH853wlL2gtUhg+xJXjfk3kUZS3BRoQeoQBQ==", + "engines": { + "node": ">=6" + } + }, "node_modules/tslib": { "version": "2.6.2", "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.6.2.tgz", @@ -3512,6 +3470,39 @@ } } }, + "node_modules/webpack-bundle-analyzer": { + "version": "4.10.2", + "resolved": "https://registry.npmjs.org/webpack-bundle-analyzer/-/webpack-bundle-analyzer-4.10.2.tgz", + "integrity": "sha512-vJptkMm9pk5si4Bv922ZbKLV8UTT4zib4FPgXMhgzUny0bfDDkLXAVQs3ly3fS4/TN9ROFtb0NFrm04UXFE/Vw==", + "dependencies": { + "@discoveryjs/json-ext": "0.5.7", + "acorn": "^8.0.4", + "acorn-walk": "^8.0.0", + "commander": "^7.2.0", + "debounce": "^1.2.1", + "escape-string-regexp": "^4.0.0", + "gzip-size": "^6.0.0", + "html-escaper": "^2.0.2", + "opener": "^1.5.2", + "picocolors": "^1.0.0", + "sirv": "^2.0.3", + "ws": "^7.3.1" + }, + "bin": { + "webpack-bundle-analyzer": "lib/bin/analyzer.js" + }, + "engines": { + "node": ">= 10.13.0" + } + }, + "node_modules/webpack-bundle-analyzer/node_modules/commander": { + "version": "7.2.0", + "resolved": "https://registry.npmjs.org/commander/-/commander-7.2.0.tgz", + "integrity": "sha512-QrWXB+ZQSVPmIWIhtEO9H+gwHaMGYiF5ChvoJ+K9ZGHG/sVsa6yiesAD1GC/x46sET00Xlwo1u49RVVVzvcSkw==", + "engines": { + "node": ">= 10" + } + }, "node_modules/webpack-cli": { "version": "5.1.4", "resolved": "https://registry.npmjs.org/webpack-cli/-/webpack-cli-5.1.4.tgz", @@ -3659,6 +3650,26 @@ "integrity": "sha512-CC1bOL87PIWSBhDcTrdeLo6eGT7mCFtrg0uIJtqJUFyK+eJnzl8A1niH56uu7KMa5XFrtiV+AQuHO3n7DsHnLQ==", "dev": true }, + "node_modules/ws": { + "version": "7.5.10", + "resolved": "https://registry.npmjs.org/ws/-/ws-7.5.10.tgz", + "integrity": "sha512-+dbF1tHwZpXcbOJdVOkzLDxZP1ailvSxM6ZweXTegylPny803bFhA+vqBYw4s31NSAk4S2Qz+AKXK9a4wkdjcQ==", + "engines": { + "node": ">=8.3.0" + }, + "peerDependencies": { + "bufferutil": "^4.0.1", + "utf-8-validate": "^5.0.2" + }, + "peerDependenciesMeta": { + "bufferutil": { + "optional": true + }, + "utf-8-validate": { + "optional": true + } + } + }, "node_modules/yallist": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", diff --git a/package.json b/package.json index e9f315613..78f7f126e 100644 --- a/package.json +++ b/package.json @@ -2,19 +2,24 @@ "name": "pydata_sphinx_theme", "repository": "https://github.com/pydata/pydata-sphinx-theme", "scripts": { - "build": "webpack" + "build": "webpack --mode=production", + "build-dev": "webpack", + "profile": "webpack --profile --json > bundle-stats.json", + "view-profile": "webpack-bundle-analyzer bundle-stats.json" }, "devDependencies": { "axe-core": "^4.6.3", - "copy-webpack-plugin": "^11.0.0", "css-loader": "^6.8.1", "css-minimizer-webpack-plugin": "^4.2.2", "dedent": "^0.7.0", "html-webpack-plugin": "^5.0.0", "imports-loader": "^0.8.0", "mini-css-extract-plugin": "^2.7.5", + "resolve-url-loader": "^5.0.0", "sass": "^1.59.3", "sass-loader": "^10.3.1", + "style-loader": "^4.0.0", + "terser-webpack-plugin": "^5.3.10", "webpack": "^5.0.0", "webpack-cli": "^5.0.0" }, @@ -22,6 +27,7 @@ "@fortawesome/fontawesome-free": "^6.5.1", "@popperjs/core": "^2.11.6", "bootstrap": "^5.2.2", - "compare-versions": "^5.0.3" + "compare-versions": "^5.0.3", + "webpack-bundle-analyzer": "^4.10.2" } } diff --git a/src/pydata_sphinx_theme/assets/scripts/bootstrap.js b/src/pydata_sphinx_theme/assets/scripts/bootstrap.js index d0e5f6dfa..505a65eff 100644 --- a/src/pydata_sphinx_theme/assets/scripts/bootstrap.js +++ b/src/pydata_sphinx_theme/assets/scripts/bootstrap.js @@ -1,10 +1,10 @@ +// TODO: @trallard might end up moving this to the main JS file // Import and setup functions to control Bootstrap's behavior. import "@popperjs/core"; +// Import all of Bootstrap's JS import * as bootstrap from "bootstrap"; import { documentReady } from "./mixin"; -import "../styles/bootstrap.scss"; - /******************************************************************************* * Trigger tooltips */ diff --git a/src/pydata_sphinx_theme/assets/scripts/fontawesome.js b/src/pydata_sphinx_theme/assets/scripts/fontawesome.js new file mode 100644 index 000000000..6d3ee4317 --- /dev/null +++ b/src/pydata_sphinx_theme/assets/scripts/fontawesome.js @@ -0,0 +1,5 @@ +// TODO: @trallard might end up moving this to the main JS file +// Define the custom behavior of the page +import { documentReady } from "./mixin"; + +import "@fortawesome/fontawesome-free/js/all.min.js"; diff --git a/src/pydata_sphinx_theme/assets/styles/bootstrap.scss b/src/pydata_sphinx_theme/assets/styles/bootstrap.scss deleted file mode 100644 index 260161ecb..000000000 --- a/src/pydata_sphinx_theme/assets/styles/bootstrap.scss +++ /dev/null @@ -1,5 +0,0 @@ -// create a specific css file to build bootstrap css -// the objective is to split css coming from bootstrap from the one coming from -// the theme itself -@import "variables/bootstrap"; -@import "~bootstrap/scss/bootstrap"; diff --git a/src/pydata_sphinx_theme/assets/styles/pydata-sphinx-theme.scss b/src/pydata_sphinx_theme/assets/styles/pydata-sphinx-theme.scss index 1b8ac9cdc..5ed816b55 100644 --- a/src/pydata_sphinx_theme/assets/styles/pydata-sphinx-theme.scss +++ b/src/pydata_sphinx_theme/assets/styles/pydata-sphinx-theme.scss @@ -1,10 +1,14 @@ -// Import Bootstrap core -@import "~bootstrap/scss/functions"; -@import "variables/bootstrap"; -@import "~bootstrap/scss/variables"; -@import "~bootstrap/scss/mixins"; +// Import all of Bootstrap scss +@import "~bootstrap/scss/bootstrap"; + +// Import FontAwesome from _node_modules +@import "~@fortawesome/fontawesome-free/scss/fontawesome"; +@import "~@fortawesome/fontawesome-free/scss/solid"; +@import "~@fortawesome/fontawesome-free/scss/regular"; +@import "~@fortawesome/fontawesome-free/scss/brands"; // Variables +@import "variables/bootstrap"; @import "variables/layout"; @import "variables/fonts"; @import "variables/icons"; diff --git a/src/pydata_sphinx_theme/assets/styles/variables/_fonts.scss b/src/pydata_sphinx_theme/assets/styles/variables/_fonts.scss index 19219c3d4..b60ed94c4 100644 --- a/src/pydata_sphinx_theme/assets/styles/variables/_fonts.scss +++ b/src/pydata_sphinx_theme/assets/styles/variables/_fonts.scss @@ -43,3 +43,4 @@ html { } $line-height-body: 1.65; +$fa-font-path: "vendor/fontawesome/webfonts/"; diff --git a/src/pydata_sphinx_theme/theme/pydata_sphinx_theme/layout.html b/src/pydata_sphinx_theme/theme/pydata_sphinx_theme/layout.html index 30a25cab0..7062dd628 100644 --- a/src/pydata_sphinx_theme/theme/pydata_sphinx_theme/layout.html +++ b/src/pydata_sphinx_theme/theme/pydata_sphinx_theme/layout.html @@ -27,7 +27,6 @@ {{ _webpack.head_pre_assets() }} - {{ _webpack.head_pre_icons() }} {{- css() }} {{ _webpack.head_js_preload() }} {%- endblock css %} diff --git a/src/pydata_sphinx_theme/theme/pydata_sphinx_theme/static/.gitignore b/src/pydata_sphinx_theme/theme/pydata_sphinx_theme/static/.gitignore index 16a48c80b..5b2bb8d6e 100644 --- a/src/pydata_sphinx_theme/theme/pydata_sphinx_theme/static/.gitignore +++ b/src/pydata_sphinx_theme/theme/pydata_sphinx_theme/static/.gitignore @@ -11,6 +11,11 @@ scripts/bootstrap.js.map styles/bootstrap.css styles/bootstrap.css.map +# fontawesome generated webpack outputs +scripts/fontawesome.js +scripts/fontawesome.js.LICENSE.txt +scripts/fontawesome.js.map + # webpack files webpack-macros.html vendor/* diff --git a/tests/test_build.py b/tests/test_build.py index a2a1239d0..8ff73d820 100644 --- a/tests/test_build.py +++ b/tests/test_build.py @@ -1,4 +1,4 @@ -"""All the tests performed in the pydata-sphinx-theme test suit.""" +"""All the tests performed in the pydata-sphinx-theme test suite.""" import re from pathlib import Path diff --git a/webpack.config.js b/webpack.config.js index ff56828ec..f5427e4c2 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -12,9 +12,9 @@ const { resolve } = require("path"); const HtmlWebpackPlugin = require("html-webpack-plugin"); -const CopyPlugin = require("copy-webpack-plugin"); const MiniCssExtractPlugin = require("mini-css-extract-plugin"); const CssMinimizerPlugin = require("css-minimizer-webpack-plugin"); +const TerserPlugin = require("terser-webpack-plugin"); const dedent = require("dedent"); const { Compilation } = require("webpack"); @@ -29,12 +29,9 @@ exec(`pybabel compile -d ${localePath} -D sphinx`); * Paths for various assets (sources and destinations) */ -const vendorVersions = {fontAwesome: require("@fortawesome/fontawesome-free/package.json").version}; - const scriptPath = resolve(__dirname, "src/pydata_sphinx_theme/assets/scripts"); -const staticPath = resolve(__dirname,"src/pydata_sphinx_theme/theme/pydata_sphinx_theme/static"); +const staticPath = resolve(__dirname, "src/pydata_sphinx_theme/theme/pydata_sphinx_theme/static"); const vendorPath = resolve(staticPath, "vendor"); -const faPath = {fontAwesome: resolve(vendorPath, "fontawesome", vendorVersions.fontAwesome)}; /******************************************************************************* * functions to load the assets in the html head @@ -42,33 +39,23 @@ const faPath = {fontAwesome: resolve(vendorPath, "fontawesome", vendorVersions.f * the fonts are loaded from vendors */ -function stylesheet(css){ return ``;} -function preload(js){ return ``;} -function script(js){ return ``;} -function font(woff2){ return ``;} +function stylesheet(css) { return ``; } +function preload(js) { return ``; } +function script(js) { return ``; } /******************************************************************************* * the assets to load in the macro */ - const theme_stylesheets = [ +const theme_stylesheets = [ "styles/theme.css", // basic sphinx css - "styles/bootstrap.css", // all bootstrap 5 css with variable adjustments "styles/pydata-sphinx-theme.css", // all the css created for this specific theme ]; const theme_scripts = [ "scripts/bootstrap.js", "scripts/pydata-sphinx-theme.js", ]; -const fa_stylesheets = [ - `vendor/fontawesome/${vendorVersions.fontAwesome}/css/all.min.css`, -]; const fa_scripts = [ - `vendor/fontawesome/${vendorVersions.fontAwesome}/js/all.min.js`, -]; -const fa_fonts = [ - `vendor/fontawesome/${vendorVersions.fontAwesome}/webfonts/fa-solid-900.woff2`, - `vendor/fontawesome/${vendorVersions.fontAwesome}/webfonts/fa-brands-400.woff2`, - `vendor/fontawesome/${vendorVersions.fontAwesome}/webfonts/fa-regular-400.woff2`, + "scripts/fontawesome.js", ]; /******************************************************************************* @@ -84,11 +71,6 @@ function macroTemplate({ compilation }) { AUTO-GENERATED from webpack.config.js, do **NOT** edit by hand. These are re-used in layout.html --> - {# Load FontAwesome icons #} - {% macro head_pre_icons() %} - ${fa_stylesheets.map(stylesheet.bind(compilation)).join("\n")} - ${fa_fonts.map(font).join("\n")} - {% endmacro %} {% macro head_pre_assets() %} @@ -98,11 +80,11 @@ function macroTemplate({ compilation }) { {% macro head_js_preload() %} ${theme_scripts.map(preload.bind(compilation)).join("\n")} - ${fa_scripts.map(script.bind(compilation)).join("\n")} {% endmacro %} {% macro body_post() %} + ${fa_scripts.map(script.bind(compilation)).join("\n")} ${theme_scripts.map(script.bind(compilation)).join("\n")} {% endmacro %} `); @@ -120,53 +102,76 @@ const htmlWebpackPlugin = new HtmlWebpackPlugin({ templateContent: macroTemplate, }); -const copyPlugin = new CopyPlugin({ // fontawesome - patterns: [ - { - context: "./node_modules/@fortawesome/fontawesome-free", - from: "LICENSE.txt", - to: resolve(faPath.fontAwesome, "LICENSE.txt"), - }, - { - context: "./node_modules/@fortawesome/fontawesome-free/css", - from: "all.min.css", - to: resolve(faPath.fontAwesome, "css"), - }, - { - context: "./node_modules/@fortawesome/fontawesome-free/js", - from: "all.min.js", - to: resolve(faPath.fontAwesome, "js"), - }, - { - context: "./node_modules/@fortawesome/fontawesome-free", - from: "webfonts", - to: resolve(faPath.fontAwesome, "webfonts"), - }, - ] -}); - module.exports = { mode: "production", devtool: "source-map", entry: { "pydata-sphinx-theme": resolve(scriptPath, "pydata-sphinx-theme.js"), + "fontawesome": resolve(scriptPath, "fontawesome.js"), "bootstrap": resolve(scriptPath, "bootstrap.js"), }, - output: {filename: "scripts/[name].js", path: staticPath}, - optimization: {minimizer: ['...', new CssMinimizerPlugin()]}, + output: { + filename: "scripts/[name].js", + path: staticPath, + // clean webpack assets at the beginning of the build - except for + // files we need to explicitly keep + clean: { + keep(asset) { + const filesToKeep = ["styles/theme.css", ".gitignore"]; + return filesToKeep.some(file => asset.includes(file)); + } + }, + }, + optimization: { + minimizer: [ + '...', + new CssMinimizerPlugin(), + new TerserPlugin({ + terserOptions: { + parallel: true, + } + })] + }, module: { rules: [{ - test: /\.scss$/, + test: /\.(sa|sc|c)ss$/, use: [ - {loader: MiniCssExtractPlugin.loader}, - {loader: "css-loader", options: { url: false }}, - {loader: "sass-loader",}, + // Extracts CSS for each JS file that includes CSS + { loader: MiniCssExtractPlugin.loader }, + { + // Interprets `@import` and `url()` like `import/require()` and will resolve them + loader: 'css-loader', + options: { + sourceMap: true, + url: true, + } + }, + { loader: 'resolve-url-loader' }, + { + // Loads a SASS/SCSS file and compiles it to CSS + loader: "sass-loader", + options: { + sourceMap: true, + sassOptions: { outputStyle: "expanded" } + } + }, ], - }], + }, + { + // Font vendoring and management - will separate FA and export the font files + test: /\.(woff|woff2|eot|ttf|otf)$/i, + type: 'asset/resource', + generator: { + filename: 'vendor/fontawesome/webfonts/[name][ext]' + } + },], }, - plugins: [htmlWebpackPlugin, copyPlugin, new MiniCssExtractPlugin({ - filename: "styles/[name].css" - })], + plugins: [ + htmlWebpackPlugin, + new MiniCssExtractPlugin({ + filename: "styles/[name].css", + chunkFilename: "styles/[id].css", + })], experiments: { topLevelAwait: true, },