Skip to content

Commit

Permalink
Merge pull request #120 from nuxt-modules/fix/node-polyfils
Browse files Browse the repository at this point in the history
fix: node polyfills
  • Loading branch information
Baroshem authored Jan 3, 2023
2 parents f7a7640 + 4eaec9b commit 107d22f
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 3 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
18 changes: 17 additions & 1 deletion src/module.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -161,6 +161,22 @@ export default defineNuxtModule<ModuleOptions>({
}
}

// 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'))

Expand Down
20 changes: 18 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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==
Expand Down Expand Up @@ -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"
Expand All @@ -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==
Expand Down

0 comments on commit 107d22f

Please sign in to comment.