configure for static export to sub-directory

This commit is contained in:
Nils Norman Haukås 2020-12-01 20:02:34 +01:00
parent 639aa27411
commit 357dc224ce
7 changed files with 15 additions and 9 deletions

1
.env Normal file
View file

@ -0,0 +1 @@
NEXT_PUBLIC_BASE_PATH=/

2
.gitignore vendored
View file

@ -32,3 +32,5 @@ yarn-error.log*
# vercel
.vercel
/web-components-in-react

View file

@ -25,7 +25,7 @@ export default function WebComponentLoader({
// Add script tags to load the dependencies.
wcToLoad.forEach((name) => {
const scriptTag = document.createElement('script')
scriptTag.src = `/${name}.js`
scriptTag.src = `${process.env.NEXT_PUBLIC_BASE_PATH}/${name}.js`
document.body.appendChild(scriptTag)
})
}, [])

4
next.config.js Normal file
View file

@ -0,0 +1,4 @@
module.exports = {
trailingSlash: true,
basePath: '/project/web-components-in-react',
}

View file

@ -7,7 +7,8 @@
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start"
"start": "next start",
"release": "NEXT_PUBLIC_BASE_PATH=/project/web-components-in-react next build && next export -o web-components-in-react"
},
"dependencies": {
"@webcomponents/webcomponentsjs": "^2.5.0",

View file

@ -5,7 +5,11 @@ function MyApp({ Component, pageProps }) {
return (
<>
<Head>
<script src="/chill-counter.js" />
<script src={`${process.env.NEXT_PUBLIC_BASE_PATH}/chill-counter.js`} />
<link
rel="icon"
href={`${process.env.NEXT_PUBLIC_BASE_PATH}/favicon.ico`}
/>
</Head>
<main>
<AppNav />

View file

@ -1,6 +0,0 @@
// Next.js API route support: https://nextjs.org/docs/api-routes/introduction
export default (req, res) => {
res.statusCode = 200
res.json({ name: 'John Doe' })
}