diff --git a/package.json b/package.json index 2038194..3ae57e2 100644 --- a/package.json +++ b/package.json @@ -232,6 +232,7 @@ "extension": "./lib/jupyterlab/index.js", "outputDir": "datalayer/labextension", "schemaDir": "schema", + "webpackConfig": "./webpack.lab-config.js", "sharedPackages": { "@jupyter/docprovider": { "bundled": true, diff --git a/webpack.config.js b/webpack.config.js index 04d9f36..1b5559f 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -112,6 +112,29 @@ module.exports = { test: /\.(png|jpg|jpeg|gif|ttf|woff|woff2|eot)(\?v=[0-9]\.[0-9]\.[0-9])?$/, use: [{ loader: 'url-loader', options: { limit: 10000 } }], }, + // Ship the JupyterLite service worker. + { + resourceQuery: /text/, + type: 'asset/resource', + generator: { + filename: '[name][ext]', + }, + }, + // Rule for pyodide kernel + { + test: /pypi\/.*/, + type: 'asset/resource', + generator: { + filename: 'pypi/[name][ext][query]', + }, + }, + { + test: /pyodide-kernel-extension\/schema\/.*/, + type: 'asset/resource', + generator: { + filename: 'schema/[name][ext][query]', + }, + } ] }, plugins: [ diff --git a/webpack.lab-config.js b/webpack.lab-config.js new file mode 100644 index 0000000..4d28bd2 --- /dev/null +++ b/webpack.lab-config.js @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2021-2023 Datalayer, Inc. + * + * MIT License + */ + +module.exports = { + module: { + rules: [ + // Rule to deal with the service-worker.ts file + // It will include the transpiled file as a text file named `[name][ext]` + // That file is available from the static folder of this extension. That + // requires to overwrite the `workerUrl` in '@datalayer/jupyter-kernels:browser-service-worker' + // see https://github.com/jupyterlite/jupyterlite/blob/1a1bbcaab83f3c56fde6747a8c9b83d3c2a9eb97/packages/server/src/tokens.ts#L5 + { + resourceQuery: /text/, + type: 'asset/resource', + generator: { + // Must match the filename in jupyter_kernels/handlers/service_worker/handler.py + filename: 'lite-[name][ext]', + }, + }, + // Rules for pyodide kernel assets + { + test: /pypi\/.*/, + type: 'asset/resource', + generator: { + filename: 'pypi/[name][ext][query]', + }, + }, + { + test: /pyodide-kernel-extension\/schema\/.*/, + type: 'asset/resource', + generator: { + filename: 'schema/[name][ext][query]', + }, + }, + ], + }, +};