Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,6 @@ cypress.log
src/tests/cypress/screenshots
src/tests/cypress/videos
RapiDoc

# Planning docs (versioned separately)
/plans
6 changes: 4 additions & 2 deletions next-sitemap.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
/** @type {import('next').NextConfig} */
// eslint-disable-next-line @typescript-eslint/no-var-requires
const fs = require('fs')
const siteUrl = process.env.NEXT_PUBLIC_DOMAIN_URL
const siteUrl = (
process.env.NEXT_PUBLIC_SITE_URL || 'https://developers.vtex.com'
).replace(/\/+$/, '')

module.exports = {
transform: async (config, path) => {
Expand Down Expand Up @@ -37,6 +39,6 @@ module.exports = {
},
{ userAgent: '*', allow: '/' },
],
additionalSitemaps: [`${siteUrl}server-sitemap.xml`],
additionalSitemaps: [`${siteUrl}/server-sitemap.xml`],
},
}
61 changes: 58 additions & 3 deletions next.config.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,68 @@
/* eslint-disable @typescript-eslint/no-var-requires */
/** @type {import('next').NextConfig} */
const { withPlaiceholder } = require('@plaiceholder/next')
const withLitSSR = require('@lit-labs/nextjs')()

const withPatchedLitSSR = (baseConfig = {}) => ({
...baseConfig,
webpack: (config, options) => {
const { isServer, nextRuntime, webpack } = options

config.module.rules.unshift({
test: /\/pages\/.*\.(?:jsx?|tsx?)$/,
exclude: /next\/dist\//,
loader: 'imports-loader',
options: {
imports: ['side-effects @lit-labs/ssr-react/enable-lit-ssr.js'],
},
})

if (isServer && nextRuntime === 'nodejs') {
const nextHandleExternals = config.externals[0]
config.externals = [
(opt) => {
if (
opt.request === 'react/jsx-dev-runtime' ||
opt.request === 'react/jsx-runtime'
) {
return Promise.resolve()
}

return nextHandleExternals(opt)
},
]
}

config.plugins.push(
new webpack.NormalModuleReplacementPlugin(/react/, (resource) => {
const normalizedContext = (resource.context || '').replace(/\\/g, '/')
const isLitSsrRuntime = /labs\/ssr-react/.test(normalizedContext)

if (resource.request === 'react/jsx-runtime' && !isLitSsrRuntime) {
resource.request = '@lit-labs/ssr-react/jsx-runtime'
}

if (resource.request === 'react/jsx-dev-runtime' && !isLitSsrRuntime) {
resource.request = '@lit-labs/ssr-react/jsx-dev-runtime'
}
})
)

if (typeof baseConfig.webpack === 'function') {
return baseConfig.webpack(config, options)
}

return config
},
})

const nextConfig = {
experimental: {
largePageDataBytes: 500 * 1000,
workerThreads: false,
cpus: 4,
// Next 13 writes build traces into `.next/trace`; Windows can hit EPERM
// when multiple build workers race on that file, so keep local Windows
// builds single-threaded while preserving the current Linux/CI behavior.
cpus: process.platform === 'win32' ? 1 : 4,
},
reactStrictMode: true,
swcMinify: true,
Expand Down Expand Up @@ -55,7 +110,7 @@ const nextConfig = {
}

module.exports = () => {
const plugins = [withPlaiceholder, withLitSSR]
const plugins = [withPlaiceholder, withPatchedLitSSR]
return plugins.reduce((acc, plugin) => plugin(acc), {
...nextConfig,
})
Expand Down
Loading
Loading