diff --git a/app/package.json b/app/package.json index 25aa2764b0..c42a923336 100644 --- a/app/package.json +++ b/app/package.json @@ -4,7 +4,7 @@ "private": true, "scripts": { "build": "webpack", - "build:prod": "webpack --mode=production", + "build:prod": "webpack --config ./webpack.prod.config.js", "clean": "rimraf build && jlpm run clean:static", "clean:static": "rimraf -g \"../notebook/static/!(favicons)\"", "watch": "webpack --config ./webpack.config.watch.js" diff --git a/app/webpack.config.js b/app/webpack.config.js index 4fdd9e5106..8707845b0b 100644 --- a/app/webpack.config.js +++ b/app/webpack.config.js @@ -214,7 +214,18 @@ module.exports = [ type: 'var', name: ['_JUPYTERLAB', 'CORE_OUTPUT'], }, - filename: 'bundle.js', + filename: '[name].[contenthash].js', + }, + optimization: { + splitChunks: { + chunks: 'all', + cacheGroups: { + jlab_core: { + test: /[\\/]node_modules[\\/]@(jupyterlab|jupyter-notebook|lumino(?!\/datagrid))[\\/]/, + name: 'notebook_core', + }, + }, + }, }, resolve: { fallback: { util: false }, diff --git a/app/webpack.prod.config.js b/app/webpack.prod.config.js new file mode 100644 index 0000000000..db7e6dfdb5 --- /dev/null +++ b/app/webpack.prod.config.js @@ -0,0 +1,29 @@ +/* + * Copyright (c) Jupyter Development Team. + * Distributed under the terms of the Modified BSD License. + */ + +const merge = require('webpack-merge').default; +const config = require('./webpack.config'); +const WPPlugin = require('@jupyterlab/builder').WPPlugin; + +config[0] = merge(config[0], { + mode: 'production', + devtool: 'source-map', + output: { + // Add version argument when in production so the Jupyter server + // allows caching of files (i.e., does not set the CacheControl header to no-cache to prevent caching static files) + filename: '[name].[contenthash].js?v=[contenthash]', + }, + optimization: { + minimize: false, + }, + plugins: [ + new WPPlugin.JSONLicenseWebpackPlugin({ + excludedPackageTest: (packageName) => + packageName === '@jupyter-notebook/app', + }), + ], +}); + +module.exports = config;