From 4de6013dabfaa568cd4f7c5d72b502efaf5d424d Mon Sep 17 00:00:00 2001 From: markthree <1801982702@qq.com> Date: Sat, 25 Feb 2023 21:33:51 +0800 Subject: [PATCH] perf: add beastcss --- modules/beastcss.ts | 45 +++++++++++++ nuxt.config.ts | 1 + package.json | 1 + pnpm-lock.yaml | 160 ++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 207 insertions(+) create mode 100644 modules/beastcss.ts diff --git a/modules/beastcss.ts b/modules/beastcss.ts new file mode 100644 index 0000000..56af102 --- /dev/null +++ b/modules/beastcss.ts @@ -0,0 +1,45 @@ +import { defineNuxtModule } from "@nuxt/kit"; +import Beastcss, { Options } from "beastcss"; + +function createSlient(origin: T) { + return function () { + return origin; + }; +} + +export interface ModuleOptions { + // Options passed directly to `beastcss` + config?: Options; +} + +export default defineNuxtModule({ + meta: { + name: "beastcss", + configKey: "beastcss", + }, + defaults: { + // @ts-ignore Config needs to be merged + config: { + pruneSource: true, + minifyCss: true, + preloadExternalStylesheets: true, + }, + }, + setup(options, nuxt) { + if (nuxt.options.dev) return; + + nuxt.hook("nitro:init", (nitro) => { + const beast = new Beastcss({ + path: nitro.options.output.publicDir, + publicPath: nitro.options.baseURL, + ...options.config, + }); + nitro.hooks.hook("prerender:generate", async (route) => { + if (!route.fileName?.endsWith(".html") || !route.contents) return; + route.contents = await beast.process(route.contents).catch( + createSlient(route.contents), + ); + }); + }); + }, +}); diff --git a/nuxt.config.ts b/nuxt.config.ts index 41378cb..2fde93b 100644 --- a/nuxt.config.ts +++ b/nuxt.config.ts @@ -14,6 +14,7 @@ export default defineNuxtConfig({ "@nuxt/devtools", "@nuxtjs/fontaine", "@nuxt/image-edge", + "./modules/beastcss", ], app: { head: { diff --git a/package.json b/package.json index 95a7ef1..a98a251 100644 --- a/package.json +++ b/package.json @@ -27,6 +27,7 @@ "@nuxt/image-edge": "1.0.0-27954023.4cee565", "@nuxtjs/fontaine": "^0.2.4", "@unocss/nuxt": "^0.50.1", + "beastcss": "^2.1.3", "bumpp": "^9.0.0", "execa": "^7.0.0", "file-computed": "^0.9.1", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index d74c50a..2133d6a 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -6,6 +6,7 @@ specifiers: '@nuxt/image-edge': 1.0.0-27954023.4cee565 '@nuxtjs/fontaine': ^0.2.4 '@unocss/nuxt': ^0.50.1 + beastcss: ^2.1.3 bumpp: ^9.0.0 execa: ^7.0.0 file-computed: ^0.9.1 @@ -21,6 +22,7 @@ devDependencies: '@nuxt/image-edge': 1.0.0-27954023.4cee565 '@nuxtjs/fontaine': 0.2.4 '@unocss/nuxt': 0.50.1 + beastcss: 2.1.3 bumpp: 9.0.0 execa: 7.0.0 file-computed: 0.9.1 @@ -847,6 +849,10 @@ packages: resolution: {integrity: sha512-J8TOSBq3SoZbDhM9+R/u77hP93gz/rajSA+K2kGyijPpORPWUXHUpTaleoj+92As0S9uPRP7Oi8IqMf0u+ro6A==} dev: true + /@freddy38510/dropcss/2.5.0: + resolution: {integrity: sha512-gzFIpGpXX4QpSYLl/DVYiKkE8cmLvcQBvD7lNuoXXtztz31/da+3eZCeuw91FrA4fQwq8/JchOteufymze+XZQ==} + dev: true + /@gar/promisify/1.1.3: resolution: {integrity: sha512-k2Ty1JcVojjJFwrg/ThKi2ujJ7XNLYaFGNB/bWT9wGR+oSMJHMa5w+CUq6p/pVrKeNNgA7pCqEcjSnHVoqJQFw==} dev: true @@ -2572,6 +2578,17 @@ packages: resolution: {integrity: sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==} dev: true + /beastcss/2.1.3: + resolution: {integrity: sha512-0WEiPzE/u8vQmX/nYqU92WH7lLMnBH1GMtlwli91ZEbx2e9C/Am7GjuzTB5kEjMZZjBPPgBxRwIOAOBF9qWiEQ==} + engines: {node: '>=12.17.0'} + dependencies: + '@freddy38510/dropcss': 2.5.0 + fast-glob: 3.2.12 + kolorist: 1.7.0 + lightningcss: 1.19.0 + node-html-parser: 6.1.5 + dev: true + /binary-extensions/2.2.0: resolution: {integrity: sha512-jDctJ/IVQbZoJykoeHbhXpOlNBqGNcwXJKJog42E5HDPUwQTSdjCHdihjj0DlnheQ7blbT6dHOafNAiS8ooQKA==} engines: {node: '>=8'} @@ -3222,6 +3239,16 @@ packages: nth-check: 2.1.1 dev: true + /css-select/5.1.0: + resolution: {integrity: sha512-nwoRF1rvRRnnCqqY7updORDsuqKzqYJ28+oSMaJMMgOauh3fvwHqMS7EZpIPqK8GL+g9mKxF1vP/ZjSeNjEVHg==} + dependencies: + boolbase: 1.0.0 + css-what: 6.1.0 + domhandler: 5.0.3 + domutils: 3.0.1 + nth-check: 2.1.1 + dev: true + /css-tree/1.1.3: resolution: {integrity: sha512-tRpdppF7TRazZrjJ6v3stzv93qxRcSsFmW6cX0Zm2NVKpxE1WV1HblnghVv9TreireHkqI/VDEsfolRF1p6y7Q==} engines: {node: '>=8.0.0'} @@ -3479,6 +3506,12 @@ packages: resolution: {integrity: sha512-7Bp16Bk8sk0Y6gdXiCtnpGbghn8atnTJdd/82aWvS5ESnlcNvgUc10U2NYS0PAiDSGjWiI8qs/Cv1b2uSGdQ8w==} dev: true + /detect-libc/1.0.3: + resolution: {integrity: sha512-pGjwhsmsp4kL2RTz08wcOlGN83otlqHeD/Z5T8GXZB+/YcpQ/dgo+lbU8ZsGxV0HIvqqxo9l7mqYwyYMD9bKDg==} + engines: {node: '>=0.10'} + hasBin: true + dev: true + /detect-libc/2.0.1: resolution: {integrity: sha512-463v3ZeIrcWtdgIg6vI6XUncguvr2TnGl4SzDXinkt9mSLpBJKXT3mW6xT3VQdDN11+WVs29pgvivTc4Lp8v+w==} engines: {node: '>=8'} @@ -3508,6 +3541,14 @@ packages: entities: 2.2.0 dev: true + /dom-serializer/2.0.0: + resolution: {integrity: sha512-wIkAryiqt/nV5EQKqQpo3SToSOV9J0DnbJqwK7Wv/Trc92zIAYZ4FlMu+JPFW1DfGFt81ZTCGgDEabffXeLyJg==} + dependencies: + domelementtype: 2.3.0 + domhandler: 5.0.3 + entities: 4.4.0 + dev: true + /domelementtype/2.3.0: resolution: {integrity: sha512-OLETBj6w0OsagBwdXnPdN0cnMfF9opN69co+7ZrbfPGrdpPVNBUj02spi6B1N7wChLQiPn4CSH/zJvXw56gmHw==} dev: true @@ -3519,6 +3560,13 @@ packages: domelementtype: 2.3.0 dev: true + /domhandler/5.0.3: + resolution: {integrity: sha512-cgwlv/1iFQiFnU96XXgROh8xTeetsnJiDsTc7TYCLFd9+/WNkIqPTxiM/8pSd8VIrhXGTf1Ny1q1hquVqDJB5w==} + engines: {node: '>= 4'} + dependencies: + domelementtype: 2.3.0 + dev: true + /domutils/2.8.0: resolution: {integrity: sha512-w96Cjofp72M5IIhpjgobBimYEfoPjx1Vx0BSX9P30WBdZW2WIKU0T1Bd0kz2eNZ9ikjKgHbEyKx8BB6H1L3h3A==} dependencies: @@ -3527,6 +3575,14 @@ packages: domhandler: 4.3.1 dev: true + /domutils/3.0.1: + resolution: {integrity: sha512-z08c1l761iKhDFtfXO04C7kTdPBLi41zwOZl00WS8b5eiaebNpY00HKbztwBq+e3vyqWNwWF3mP9YLUeqIrF+Q==} + dependencies: + dom-serializer: 2.0.0 + domelementtype: 2.3.0 + domhandler: 5.0.3 + dev: true + /dot-case/3.0.4: resolution: {integrity: sha512-Kv5nKlh6yRrdrGvxeJ2e5y2eRUpkUosIW4A2AS38zwSz27zu7ufDwQPi5Jhs3XAlGNetl3bmnGhQsMtkKJnj3w==} dependencies: @@ -3633,6 +3689,11 @@ packages: resolution: {integrity: sha512-p92if5Nz619I0w+akJrLZH0MX0Pb5DX39XOwQTtXSdQQOaYH03S1uIQp4mhOZtAXrxq4ViO67YTiLBo2638o9A==} dev: true + /entities/4.4.0: + resolution: {integrity: sha512-oYp7156SP8LkeGD0GF85ad1X9Ai79WtRsZ2gxJqtBuzH+98YUV6jkHEKlZkMbcrjJjIVJNIDP/3WL9wQkoPbWA==} + engines: {node: '>=0.12'} + dev: true + /env-paths/2.2.1: resolution: {integrity: sha512-+h1lkLKhZMTYjog1VEpJNG7NZJWcuc2DDk/qsqSTRRCOXiLjeQ1d1/udrUGhqMxUgAlwKNZ0cf2uqan5GLuS2A==} engines: {node: '>=6'} @@ -5267,6 +5328,98 @@ packages: readable-stream: 2.3.7 dev: true + /lightningcss-darwin-arm64/1.19.0: + resolution: {integrity: sha512-wIJmFtYX0rXHsXHSr4+sC5clwblEMji7HHQ4Ub1/CznVRxtCFha6JIt5JZaNf8vQrfdZnBxLLC6R8pC818jXqg==} + engines: {node: '>= 12.0.0'} + cpu: [arm64] + os: [darwin] + requiresBuild: true + dev: true + optional: true + + /lightningcss-darwin-x64/1.19.0: + resolution: {integrity: sha512-Lif1wD6P4poaw9c/4Uh2z+gmrWhw/HtXFoeZ3bEsv6Ia4tt8rOJBdkfVaUJ6VXmpKHALve+iTyP2+50xY1wKPw==} + engines: {node: '>= 12.0.0'} + cpu: [x64] + os: [darwin] + requiresBuild: true + dev: true + optional: true + + /lightningcss-linux-arm-gnueabihf/1.19.0: + resolution: {integrity: sha512-P15VXY5682mTXaiDtbnLYQflc8BYb774j2R84FgDLJTN6Qp0ZjWEFyN1SPqyfTj2B2TFjRHRUvQSSZ7qN4Weig==} + engines: {node: '>= 12.0.0'} + cpu: [arm] + os: [linux] + requiresBuild: true + dev: true + optional: true + + /lightningcss-linux-arm64-gnu/1.19.0: + resolution: {integrity: sha512-zwXRjWqpev8wqO0sv0M1aM1PpjHz6RVIsBcxKszIG83Befuh4yNysjgHVplF9RTU7eozGe3Ts7r6we1+Qkqsww==} + engines: {node: '>= 12.0.0'} + cpu: [arm64] + os: [linux] + libc: [glibc] + requiresBuild: true + dev: true + optional: true + + /lightningcss-linux-arm64-musl/1.19.0: + resolution: {integrity: sha512-vSCKO7SDnZaFN9zEloKSZM5/kC5gbzUjoJQ43BvUpyTFUX7ACs/mDfl2Eq6fdz2+uWhUh7vf92c4EaaP4udEtA==} + engines: {node: '>= 12.0.0'} + cpu: [arm64] + os: [linux] + libc: [musl] + requiresBuild: true + dev: true + optional: true + + /lightningcss-linux-x64-gnu/1.19.0: + resolution: {integrity: sha512-0AFQKvVzXf9byrXUq9z0anMGLdZJS+XSDqidyijI5njIwj6MdbvX2UZK/c4FfNmeRa2N/8ngTffoIuOUit5eIQ==} + engines: {node: '>= 12.0.0'} + cpu: [x64] + os: [linux] + libc: [glibc] + requiresBuild: true + dev: true + optional: true + + /lightningcss-linux-x64-musl/1.19.0: + resolution: {integrity: sha512-SJoM8CLPt6ECCgSuWe+g0qo8dqQYVcPiW2s19dxkmSI5+Uu1GIRzyKA0b7QqmEXolA+oSJhQqCmJpzjY4CuZAg==} + engines: {node: '>= 12.0.0'} + cpu: [x64] + os: [linux] + libc: [musl] + requiresBuild: true + dev: true + optional: true + + /lightningcss-win32-x64-msvc/1.19.0: + resolution: {integrity: sha512-C+VuUTeSUOAaBZZOPT7Etn/agx/MatzJzGRkeV+zEABmPuntv1zihncsi+AyGmjkkzq3wVedEy7h0/4S84mUtg==} + engines: {node: '>= 12.0.0'} + cpu: [x64] + os: [win32] + requiresBuild: true + dev: true + optional: true + + /lightningcss/1.19.0: + resolution: {integrity: sha512-yV5UR7og+Og7lQC+70DA7a8ta1uiOPnWPJfxa0wnxylev5qfo4P+4iMpzWAdYWOca4jdNQZii+bDL/l+4hUXIA==} + engines: {node: '>= 12.0.0'} + dependencies: + detect-libc: 1.0.3 + optionalDependencies: + lightningcss-darwin-arm64: 1.19.0 + lightningcss-darwin-x64: 1.19.0 + lightningcss-linux-arm-gnueabihf: 1.19.0 + lightningcss-linux-arm64-gnu: 1.19.0 + lightningcss-linux-arm64-musl: 1.19.0 + lightningcss-linux-x64-gnu: 1.19.0 + lightningcss-linux-x64-musl: 1.19.0 + lightningcss-win32-x64-msvc: 1.19.0 + dev: true + /lilconfig/2.0.6: resolution: {integrity: sha512-9JROoBW7pobfsx+Sq2JsASvCo6Pfo6WWoUW79HuB1BCoBXD4PLWJPqDF6fNj67pqBYTbAHkE57M1kS/+L1neOg==} engines: {node: '>=10'} @@ -6359,6 +6512,13 @@ packages: - supports-color dev: true + /node-html-parser/6.1.5: + resolution: {integrity: sha512-fAaM511feX++/Chnhe475a0NHD8M7AxDInsqQpz6x63GRF7xYNdS8Vo5dKsIVPgsOvG7eioRRTZQnWBrhDHBSg==} + dependencies: + css-select: 5.1.0 + he: 1.2.0 + dev: true + /node-releases/2.0.9: resolution: {integrity: sha512-2xfmOrRkGogbTK9R6Leda0DGiXeY3p2NJpy4+gNCffdUvV6mdEJnaDEic1i3Ec2djAo8jWYoJMR5PB0MSMpxUA==} dev: true