Skip to content

Commit 2003882

Browse files
authored
Fix vite and next.js examples (#381)
* fix: nextjs example * lint * readme * readme
1 parent 9992c83 commit 2003882

File tree

21 files changed

+320
-251
lines changed

21 files changed

+320
-251
lines changed

examples/next-js/README.md

Lines changed: 38 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,47 +4,67 @@
44

55
# Jupyter UI for Next.js
66

7+
> Live example on https://jupyter-nextjs-example.vercel.app
8+
79
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).
810

911
<div align="center" style="text-align: center">
1012
<img alt="Jupyter UI Next.js" src="https://datalayer-jupyter-examples.s3.amazonaws.com/jupyter-react-nextjs.png" />
1113
</div>
1214

13-
Read more on the [Datalayer documentation website](https://jupyter-ui.datalayer.tech/docs/examples/next-js) (ensure you have tne needed [Setup](https://jupyter-ui.datalayer.tech/docs/develop/setup)).
15+
Read more on the [documentation website](https://jupyter-ui.datalayer.tech/docs/examples/next-js) (ensure you have tne needed [development environment](https://jupyter-ui.datalayer.tech/docs/develop/setup)).
1416

1517
## Getting Started
1618

17-
> You have to use Yarn V3 to make this work.
18-
19-
First, run the development server:
19+
First, run the development server.
2020

2121
```bash
22+
npm i
2223
npm run dev
2324
```
2425

2526
Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.
2627

2728
You can start editing the page by modifying `app/page.tsx`. The page auto-updates as you edit the file.
2829

30+
## Production Build
31+
32+
To create a production build, you first need to patch `@jupyter-widgets/controls` to avoid issues with early loadings via `require.js`.
33+
34+
```patch
35+
diff --git a/node_modules/@jupyter-widgets/controls/lib/index.js b/node_modules/@jupyter-widgets/controls/lib/index.js
36+
index 0063f69..ade0862 100644
37+
--- a/node_modules/@jupyter-widgets/controls/lib/index.js
38+
+++ b/node_modules/@jupyter-widgets/controls/lib/index.js
39+
@@ -22,5 +22,5 @@ export * from './widget_tagsinput';
40+
export * from './widget_string';
41+
export * from './widget_description';
42+
export * from './widget_upload';
43+
-export const version = require('../package.json').version;
44+
+export const version = "0.1.0";
45+
//# sourceMappingURL=index.js.map
46+
\ No newline at end of file
47+
diff --git a/node_modules/@jupyter-widgets/controls/src/index.ts b/node_modules/@jupyter-widgets/controls/src/index.ts
48+
index 912458d..5edaa11 100644
49+
--- a/node_modules/@jupyter-widgets/controls/src/index.ts
50+
+++ b/node_modules/@jupyter-widgets/controls/src/index.ts
51+
@@ -24,4 +24,4 @@ export * from './widget_string';
52+
export * from './widget_description';
53+
export * from './widget_upload';
54+
55+
-export const version = (require('../package.json') as any).version;
56+
+export const version = "5.0.12";
57+
```
58+
2959
You can create a static version of the application that you will find under the `out` folder.
3060

3161
```bash
3262
npm run build
63+
npm start
3364
```
3465

35-
This project uses [`next/font`](https://nextjs.org/docs/basic-features/font-optimization) to automatically optimize and load Inter, a custom Google Font.
36-
37-
## Learn More
38-
39-
To learn more about Next.js, take a look at the following resources:
40-
41-
- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
42-
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.
43-
44-
You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js/) - your feedback and contributions are welcome!
45-
46-
## Deploy on Vercel
66+
## ⚖️ License
4767

48-
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.
68+
Copyright (c) 2025 Datalayer, Inc.
4969

50-
Check out our [Next.js deployment documentation](https://nextjs.org/docs/deployment) for more details.
70+
Released under the terms of the MIT license (see [LICENSE](https://github.com/datalayer/jupyter-ui/blob/main/LICENSE).

examples/next-js/next.config.js renamed to examples/next-js/next.config.ts

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,38 @@
44
* MIT License
55
*/
66

7+
const webpack = require('webpack');
8+
const path = require('path');
9+
710
/** @type {import('next').NextConfig} */
811
const nextConfig = {
912
reactStrictMode: false,
10-
webpack: (config, options) => {
13+
transpilePackages: ['@jupyterlab/settingregistry', '@jupyterlite/settings'],
14+
webpack: (config: any, options: any) => {
15+
config.resolve.fallback = {
16+
...config.resolve.fallback,
17+
buffer: require.resolve('buffer/'),
18+
};
19+
config.plugins.push(
20+
new webpack.ProvidePlugin({
21+
Buffer: ['buffer', 'Buffer'],
22+
})
23+
);
24+
// Fix json5 import issue for JupyterLab packages
25+
config.resolve.alias = {
26+
...config.resolve.alias,
27+
'json5': require.resolve('json5/lib/index.js'),
28+
'~': path.resolve(__dirname, 'node_modules'),
29+
};
30+
// Add a plugin to strip `~` from import paths
31+
config.plugins.push(
32+
new webpack.NormalModuleReplacementPlugin(
33+
/^~(.*)/,
34+
(resource: any) => {
35+
resource.request = resource.request.replace(/^~/, '');
36+
},
37+
),
38+
);
1139
config.module.rules.push(
1240
{ test: /\.js.map$/, type: 'asset/resource' },
1341
{
@@ -42,6 +70,14 @@ const nextConfig = {
4270
filename: 'pypi/[name][ext][query]',
4371
},
4472
},
73+
// Rule for Python wheel files
74+
{
75+
test: /\.whl$/,
76+
type: 'asset/resource',
77+
generator: {
78+
filename: 'pypi/[name][ext][query]',
79+
},
80+
},
4581
{
4682
test: /pyodide-kernel-extension\/schema\/.*/,
4783
type: 'asset/resource',
@@ -54,4 +90,4 @@ const nextConfig = {
5490
},
5591
}
5692

57-
module.exports = nextConfig
93+
module.exports = nextConfig;

examples/next-js/package.json

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,27 @@
44
"private": true,
55
"scripts": {
66
"dev": "next dev",
7-
"clean": "rimraf node_modules lib dist build tsconfig.tsbuildinfo",
8-
"build:prod": "next build",
7+
"build": "next build",
98
"start": "next start",
109
"lint": "next lint"
1110
},
1211
"dependencies": {
1312
"@datalayer/icons-react": "^1.0.0",
1413
"@datalayer/jupyter-react": "^1.0.1",
1514
"@datalayer/primer-addons": "^1.0.0",
16-
"autoprefixer": "^10.4.14",
17-
"eslint": "^9.0.0",
18-
"eslint-config-next": "^15.3.0",
19-
"next": "^14.2.3",
20-
"next-themes": "^0.2.1",
21-
"postcss": "^8.4.23",
22-
"react": "18.3.1",
23-
"react-dom": "18.3.1",
24-
"svg-url-loader": "^7.1.1",
25-
"tailwindcss": "^3.3.2"
15+
"next": "^15.4.1",
16+
"next-themes": "^0.4.6",
17+
"react": "^18.2.0",
18+
"react-dom": "^18",
19+
"svg-url-loader": "^8.0.0"
2620
},
2721
"devDependencies": {
28-
"@types/node": "^22.14.1",
29-
"@types/react": "18.3.20",
30-
"@types/react-dom": "18.3.6",
31-
"raw-loader": "^4.0.2",
32-
"typescript": "^5.8.3"
22+
"@tailwindcss/postcss": "^4",
23+
"@types/node": "^20",
24+
"@types/react": "^18",
25+
"@types/react-dom": "^18",
26+
"buffer": "^6.0.3",
27+
"tailwindcss": "^4",
28+
"typescript": "^5"
3329
}
3430
}

examples/next-js/postcss.config.js

Lines changed: 0 additions & 12 deletions
This file was deleted.

examples/next-js/postcss.config.mjs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
const config = {
2+
plugins: [
3+
"@tailwindcss/postcss"
4+
],
5+
};
6+
7+
export default config;

examples/next-js/public/file.svg

Lines changed: 1 addition & 0 deletions
Loading

examples/next-js/public/globe.svg

Lines changed: 1 addition & 0 deletions
Loading

examples/next-js/public/vercel.svg

Lines changed: 1 addition & 1 deletion
Loading

examples/next-js/public/window.svg

Lines changed: 1 addition & 0 deletions
Loading

examples/next-js/src/app/globals.css

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,26 @@
1-
/*
2-
* Copyright (c) 2021-2023 Datalayer, Inc.
3-
*
4-
* MIT License
5-
*/
1+
@import "tailwindcss";
2+
3+
:root {
4+
--background: #ffffff;
5+
--foreground: #171717;
6+
}
7+
8+
@theme inline {
9+
--color-background: var(--background);
10+
--color-foreground: var(--foreground);
11+
--font-sans: var(--font-geist-sans);
12+
--font-mono: var(--font-geist-mono);
13+
}
14+
15+
@media (prefers-color-scheme: dark) {
16+
:root {
17+
--background: #0a0a0a;
18+
--foreground: #ededed;
19+
}
20+
}
21+
22+
body {
23+
background: var(--background);
24+
color: var(--foreground);
25+
font-family: Arial, Helvetica, sans-serif;
26+
}

0 commit comments

Comments
 (0)