Skip to content

Commit

Permalink
fix(platform): remove global define, update platform-server replaceme…
Browse files Browse the repository at this point in the history
…nts (#661)
  • Loading branch information
brandonroberts authored Sep 19, 2023
1 parent 36495e0 commit e9a14df
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 14 deletions.
19 changes: 8 additions & 11 deletions packages/platform/src/lib/ssr/ssr-build-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,17 @@ import { normalizePath, Plugin } from 'vite';
export function ssrBuildPlugin(): Plugin {
return {
name: 'analogjs-ssr-build-plugin',
config() {
return {
define: {
global: 'globalThis',
},
};
},
transform(code, id) {
if (id.includes('platform-server')) {
return {
code: code.replace(
'new xhr2.XMLHttpRequest',
'new (xhr2.default.XMLHttpRequest || xhr2.default)'
),
code: code
.replace(
'new xhr2.XMLHttpRequest',
'new (xhr2.default.XMLHttpRequest || xhr2.default)'
)
.replaceAll('global.', 'globalThis.')
.replaceAll('global,', 'globalThis,')
.replaceAll(' global[', ' globalThis['),
};
}

Expand Down
5 changes: 5 additions & 0 deletions packages/platform/src/lib/ssr/ssr-xhr-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ export function ssrXhrBuildPlugin(): Plugin {
apply: 'build',
config() {
return {
resolve: {
alias: {
'zone.js/node': 'zone.js/plugins/zone-node',
},
},
ssr: {
noExternal: ['xhr2'],
},
Expand Down
4 changes: 2 additions & 2 deletions packages/vite-plugin-nitro/src/lib/vite-plugin-nitro.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export function nitro(options?: Options, nitroOptions?: NitroConfig): Plugin[] {

nitroConfig.alias = {
'#analog/ssr': normalizePath(
path.resolve(workspaceRoot, 'dist', rootDir, 'ssr/main.server.mjs')
path.resolve(workspaceRoot, 'dist', rootDir, 'ssr/main.server')
),
'#analog/index': normalizePath(
path.resolve(clientOutputPath, 'index.html')
Expand Down Expand Up @@ -141,7 +141,7 @@ export function nitro(options?: Options, nitroOptions?: NitroConfig): Plugin[] {
inline: ['zone.js/node'],
external: ['rxjs', 'node-fetch-native/dist/polyfill', 'destr'],
},
moduleSideEffects: ['zone.js/node'],
moduleSideEffects: ['zone.js/node', 'zone.js/plugins/zone-node'],
renderer: normalizePath(`${__dirname}/runtime/renderer`),
handlers: [
{
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"importHelpers": true,
"target": "es2015",
"module": "esnext",
"lib": ["es2017", "dom"],
"lib": ["es2021", "dom"],
"skipLibCheck": true,
"skipDefaultLibCheck": true,
"baseUrl": ".",
Expand Down

0 comments on commit e9a14df

Please sign in to comment.