Skip to content

Commit 8236b38

Browse files
fix: prepend basePath to static file URLs (#1213)
* fix: prepend basePath to static file URLs * chore: add basePath demo * chore: log event * fix: pass basePath * chore: remove cypress from basepath demo for now * chore: copy default locale Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
1 parent da7ffd5 commit 8236b38

File tree

20 files changed

+410
-15
lines changed

20 files changed

+410
-15
lines changed

demos/base-path/.eslintrc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"extends": "next",
3+
"root": true
4+
}

demos/base-path/.gitignore

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2+
3+
# dependencies
4+
/node_modules
5+
/.pnp
6+
.pnp.js
7+
8+
# testing
9+
/coverage
10+
11+
# next.js
12+
/.next/
13+
/out/
14+
15+
# production
16+
/build
17+
18+
# misc
19+
.DS_Store
20+
*.pem
21+
22+
# debug
23+
npm-debug.log*
24+
yarn-debug.log*
25+
yarn-error.log*
26+
27+
# local env files
28+
.env.local
29+
.env.development.local
30+
.env.test.local
31+
.env.production.local
32+
33+
# vercel
34+
.vercel

demos/base-path/README.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
This is a [Next.js](https://nextjs.org/) project bootstrapped with [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app).
2+
3+
## Getting Started
4+
5+
First, run the development server:
6+
7+
```bash
8+
npm run dev
9+
# or
10+
yarn dev
11+
```
12+
13+
Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.
14+
15+
You can start editing the page by modifying `pages/index.js`. The page auto-updates as you edit the file.
16+
17+
[API routes](https://nextjs.org/docs/api-routes/introduction) can be accessed on [http://localhost:3000/api/hello](http://localhost:3000/api/hello). This endpoint can be edited in `pages/api/hello.js`.
18+
19+
The `pages/api` directory is mapped to `/api/*`. Files in this directory are treated as [API routes](https://nextjs.org/docs/api-routes/introduction) instead of React pages.
20+
21+
## Learn More
22+
23+
To learn more about Next.js, take a look at the following resources:
24+
25+
- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
26+
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.
27+
28+
You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js/) - your feedback and contributions are welcome!
29+
30+
## Deploy on Vercel
31+
32+
The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.
33+
34+
Check out our [Next.js deployment documentation](https://nextjs.org/docs/deployment) for more details.

demos/base-path/local-plugin/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = require('../../../lib')
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
name: '@netlify/plugin-nextjs-local'

demos/base-path/local-plugin/package-lock.json

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"name": "local-plugin",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "index.js",
6+
"scripts": {
7+
"preinstall": "cd ../../.. && npm i"
8+
},
9+
"author": "",
10+
"license": "ISC"
11+
}

demos/base-path/netlify.toml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
[build]
2+
command = "next build"
3+
publish = ".next"
4+
ignore = "git diff --quiet $CACHED_COMMIT_REF $COMMIT_REF ../../"
5+
6+
[build.environment]
7+
# cache Cypress binary in local "node_modules" folder
8+
# so Netlify caches it
9+
CYPRESS_CACHE_FOLDER = "../node_modules/.CypressBinary"
10+
11+
[dev]
12+
framework = "#static"
13+
14+
[[plugins]]
15+
package = "./local-plugin"
16+
17+
[[plugins]]
18+
package = "@netlify/plugin-local-install-core"
19+
20+
# [[context.deploy-preview.plugins]]
21+
# package = "netlify-plugin-cypress"

demos/base-path/next.config.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
module.exports = {
2+
// Configurable site features we support:
3+
// distDir: 'build',
4+
generateBuildId: () => 'build-id',
5+
i18n: {
6+
defaultLocale: 'en',
7+
locales: ['en', 'es', 'fr'],
8+
},
9+
async headers() {
10+
return [
11+
{
12+
source: '/',
13+
headers: [
14+
{
15+
key: 'x-custom-header',
16+
value: 'my custom header value',
17+
},
18+
],
19+
},
20+
]
21+
},
22+
trailingSlash: true,
23+
// Configurable site features _to_ support:
24+
basePath: '/docs',
25+
// Rewrites allow you to map an incoming request path to a different destination path.
26+
async rewrites() {
27+
return {
28+
beforeFiles: [
29+
{
30+
source: '/old/:path*',
31+
destination: '/:path*',
32+
},
33+
],
34+
}
35+
},
36+
// Redirects allow you to redirect an incoming request path to a different destination path.
37+
async redirects() {
38+
return [
39+
{
40+
source: '/redirectme',
41+
destination: '/',
42+
permanent: true,
43+
},
44+
]
45+
},
46+
}

demos/base-path/pages/_app.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import '../styles/globals.css'
2+
3+
function MyApp({ Component, pageProps }) {
4+
return <Component {...pageProps} />
5+
}
6+
7+
export default MyApp

0 commit comments

Comments
 (0)