|
1 | 1 | // @ts-check |
| 2 | +// eslint-disable-next-line @typescript-eslint/no-require-imports |
| 3 | +const webpack = require("webpack"); |
2 | 4 |
|
3 | 5 | /** |
4 | 6 | * @type {import('next').NextConfig} |
@@ -115,11 +117,85 @@ const nextConfig = { |
115 | 117 | }, |
116 | 118 | // This is required to support PostHog trailing slash API requests |
117 | 119 | skipTrailingSlashRedirect: true, |
118 | | - webpack: (config, { isServer }) => { |
119 | | - if (isServer) { |
| 120 | + /** |
| 121 | + * JUPYTER SETTINGS |
| 122 | + * Mostly copied from https://github.com/datalayer-examples/jupyter-nextjs-example/blob/main/next.config.ts |
| 123 | + */ |
| 124 | + transpilePackages: ["@jupyterlab/settingregistry", "@jupyterlite/settings"], |
| 125 | + webpack: (config, options) => { |
| 126 | + if (options.isServer) { |
120 | 127 | config.plugins = [...config.plugins]; |
121 | 128 | } |
122 | | - |
| 129 | + config.resolve.fallback = { |
| 130 | + ...config.resolve.fallback, |
| 131 | + buffer: require.resolve("buffer/"), |
| 132 | + }; |
| 133 | + config.plugins.push( |
| 134 | + new webpack.ProvidePlugin({ |
| 135 | + Buffer: ["buffer", "Buffer"], |
| 136 | + }), |
| 137 | + ); |
| 138 | + // Fix json5 import issue for JupyterLab packages |
| 139 | + config.resolve.alias = { |
| 140 | + ...config.resolve.alias, |
| 141 | + json5: require.resolve("json5/lib/index.js"), |
| 142 | + }; |
| 143 | + // Add a plugin to strip `~` from import paths |
| 144 | + config.plugins.push( |
| 145 | + new webpack.NormalModuleReplacementPlugin(/^~(.*)/, (resource) => { |
| 146 | + resource.request = resource.request.replace(/^~/, ""); |
| 147 | + }), |
| 148 | + ); |
| 149 | + config.module.rules.push( |
| 150 | + { test: /\.js.map$/, type: "asset/resource" }, |
| 151 | + { |
| 152 | + // In .css files, svg is loaded as a data URI. |
| 153 | + test: /\.svg(\?v=\d+\.\d+\.\d+)?$/, |
| 154 | + issuer: /\.css$/, |
| 155 | + use: { |
| 156 | + loader: "svg-url-loader", |
| 157 | + options: { encoding: "none", limit: 10000 }, |
| 158 | + }, |
| 159 | + }, |
| 160 | + { |
| 161 | + // In .ts and .tsx files (both of which compile to .js), svg files |
| 162 | + // must be loaded as a raw string instead of data URIs. |
| 163 | + test: /\.svg(\?v=\d+\.\d+\.\d+)?$/, |
| 164 | + issuer: /\.js$/, |
| 165 | + type: "asset/source", |
| 166 | + }, |
| 167 | + // Ship the JupyterLite service worker. |
| 168 | + { |
| 169 | + resourceQuery: /text/, |
| 170 | + type: "asset/resource", |
| 171 | + generator: { |
| 172 | + filename: "[name][ext]", |
| 173 | + }, |
| 174 | + }, |
| 175 | + // Rule for pyodide kernel |
| 176 | + { |
| 177 | + test: /pypi\/.*/, |
| 178 | + type: "asset/resource", |
| 179 | + generator: { |
| 180 | + filename: "pypi/[name][ext][query]", |
| 181 | + }, |
| 182 | + }, |
| 183 | + // Rule for Python wheel files |
| 184 | + { |
| 185 | + test: /\.whl$/, |
| 186 | + type: "asset/resource", |
| 187 | + generator: { |
| 188 | + filename: "pypi/[name][ext][query]", |
| 189 | + }, |
| 190 | + }, |
| 191 | + { |
| 192 | + test: /pyodide-kernel-extension\/schema\/.*/, |
| 193 | + type: "asset/resource", |
| 194 | + generator: { |
| 195 | + filename: "schema/[name][ext][query]", |
| 196 | + }, |
| 197 | + }, |
| 198 | + ); |
123 | 199 | return config; |
124 | 200 | }, |
125 | 201 | }; |
|
0 commit comments