From 4eaec9b45c7c94966461f77537d0519e9315fe02 Mon Sep 17 00:00:00 2001 From: Baroshem Date: Tue, 3 Jan 2023 09:24:08 +0100 Subject: [PATCH] fix: node polyfills --- package.json | 1 + src/module.ts | 18 +++++++++++++++++- yarn.lock | 20 ++++++++++++++++++-- 3 files changed, 36 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 59cea82..b7e933e 100644 --- a/package.json +++ b/package.json @@ -50,6 +50,7 @@ "@nuxtjs/eslint-config-typescript": "latest", "eslint": "latest", "nuxt": "^3.0.0", + "rollup-plugin-node-polyfills": "^0.2.1", "standard-version": "^9.3.2" }, "publishConfig": { diff --git a/src/module.ts b/src/module.ts index 738d8d1..bd1c33d 100644 --- a/src/module.ts +++ b/src/module.ts @@ -1,6 +1,6 @@ import { resolve } from 'path' import { fileURLToPath } from 'url' -import { defineNuxtModule, addPlugin, addComponentsDir, addServerHandler, addImportsDir, isNuxt2 } from '@nuxt/kit' +import { defineNuxtModule, addPlugin, addComponentsDir, addServerHandler, addImportsDir, isNuxt2, extendViteConfig } from '@nuxt/kit' import type { MetaData } from 'metadata-scraper/lib/types' import { defu } from 'defu' import { createPageGenerateHook, createGenerateDoneHook, CrawlerPage, CrawlerHooks } from './hooks' @@ -161,6 +161,22 @@ export default defineNuxtModule({ } } + // Polyfilling server packages for SSR support + extendViteConfig((config) => { + config.resolve = config.resolve || {} + config.resolve.alias = config.resolve.alias || {} + config.resolve.alias = { + ...config.resolve.alias, + 'http': 'rollup-plugin-node-polyfills/polyfills/http', + 'stream': 'rollup-plugin-node-polyfills/polyfills/stream', + 'util': 'rollup-plugin-node-polyfills/polyfills/util', + 'process': 'rollup-plugin-node-polyfills/polyfills/process-es6', + 'events': 'rollup-plugin-node-polyfills/polyfills/events', + 'url': 'rollup-plugin-node-polyfills/polyfills/url', + 'querystring': 'rollup-plugin-node-polyfills/polyfills/qs', + 'https': 'rollup-plugin-node-polyfills/polyfills/http', + } + }) addPlugin(resolve(runtimeDir, 'plugin')) addImportsDir(resolve(runtimeDir, 'composables')) diff --git a/yarn.lock b/yarn.lock index de72edc..26ee001 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4843,7 +4843,7 @@ lru-cache@^6.0.0: dependencies: yallist "^4.0.0" -magic-string@^0.25.7: +magic-string@^0.25.3, magic-string@^0.25.7: version "0.25.9" resolved "https://registry.yarnpkg.com/magic-string/-/magic-string-0.25.9.tgz#de7f9faf91ef8a1c91d02c2e5314c8277dbcdd1c" integrity sha512-RmF0AsMzgt25qzqqLc1+MbHmhdx0ojF2Fvs4XnOqz2ZOBXzzkEwc/dJQZCYHAn7v1jbVOjAZfK8msRn4BxO4VQ== @@ -6299,11 +6299,27 @@ rollup-plugin-esbuild@^4.8.2: joycon "^3.0.1" jsonc-parser "^3.0.0" +rollup-plugin-inject@^3.0.0: + version "3.0.2" + resolved "https://registry.yarnpkg.com/rollup-plugin-inject/-/rollup-plugin-inject-3.0.2.tgz#e4233855bfba6c0c12a312fd6649dff9a13ee9f4" + integrity sha512-ptg9PQwzs3orn4jkgXJ74bfs5vYz1NCZlSQMBUA0wKcGp5i5pA1AO3fOUEte8enhGUC+iapTCzEWw2jEFFUO/w== + dependencies: + estree-walker "^0.6.1" + magic-string "^0.25.3" + rollup-pluginutils "^2.8.1" + rollup-plugin-mjs-entry@^0.1.1: version "0.1.1" resolved "https://registry.yarnpkg.com/rollup-plugin-mjs-entry/-/rollup-plugin-mjs-entry-0.1.1.tgz#b3ab47e8d49ddb1916e36ba2480dc8a62a22d533" integrity sha512-uii0Txyrn4YCgP++fypLqsT3LgO3Fx0gAZLZlWRSwKCuZ+bdSzAzdVbJFATmCHcBNlO61i65EgemOVdVQYONHA== +rollup-plugin-node-polyfills@^0.2.1: + version "0.2.1" + resolved "https://registry.yarnpkg.com/rollup-plugin-node-polyfills/-/rollup-plugin-node-polyfills-0.2.1.tgz#53092a2744837164d5b8a28812ba5f3ff61109fd" + integrity sha512-4kCrKPTJ6sK4/gLL/U5QzVT8cxJcofO0OU74tnB19F40cmuAKSzH5/siithxlofFEjwvw1YAhPmbvGNA6jEroA== + dependencies: + rollup-plugin-inject "^3.0.0" + rollup-plugin-terser@^7.0.2: version "7.0.2" resolved "https://registry.yarnpkg.com/rollup-plugin-terser/-/rollup-plugin-terser-7.0.2.tgz#e8fbba4869981b2dc35ae7e8a502d5c6c04d324d" @@ -6323,7 +6339,7 @@ rollup-plugin-visualizer@^5.8.3: source-map "^0.7.4" yargs "^17.5.1" -rollup-pluginutils@^2.8.2: +rollup-pluginutils@^2.8.1, rollup-pluginutils@^2.8.2: version "2.8.2" resolved "https://registry.yarnpkg.com/rollup-pluginutils/-/rollup-pluginutils-2.8.2.tgz#72f2af0748b592364dbd3389e600e5a9444a351e" integrity sha512-EEp9NhnUkwY8aif6bxgovPHMoMoNr2FulJziTndpt5H9RdwC47GSGuII9XxpSdzVGM0GWrNPHV6ie1LTNJPaLQ==