From e4a2d7513bf11d24a59386aa3d83db88f2c727d3 Mon Sep 17 00:00:00 2001 From: Bill Thornton Date: Tue, 6 Sep 2022 01:45:59 -0400 Subject: [PATCH] Split node_modules to separate bundles --- webpack.common.js | 20 +++++++++++++++++++- webpack.dev.js | 2 +- webpack.prod.js | 2 +- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/webpack.common.js b/webpack.common.js index 8d6d702bf6..6d28d90b13 100644 --- a/webpack.common.js +++ b/webpack.common.js @@ -81,11 +81,29 @@ module.exports = { }) ], output: { - filename: '[name].jellyfin.bundle.js', + filename: '[name].bundle.js', chunkFilename: '[name].[contenthash].chunk.js', path: path.resolve(__dirname, 'dist'), publicPath: '' }, + optimization: { + runtimeChunk: 'single', + splitChunks: { + chunks: 'all', + maxInitialRequests: Infinity, + cacheGroups: { + vendor: { + test: /[\\/]node_modules[\\/]/, + name(module) { + // get the name. E.g. node_modules/packageName/not/this/part.js + // or node_modules/packageName + const packageName = module.context.match(/[\\/]node_modules[\\/](.*?)([\\/]|$)/)[1]; + return `node_modules.${packageName}`; + } + } + } + } + }, module: { rules: [ { diff --git a/webpack.dev.js b/webpack.dev.js index 345468f89f..61d7d3b2ea 100644 --- a/webpack.dev.js +++ b/webpack.dev.js @@ -5,7 +5,7 @@ module.exports = merge(common, { // In order for live reload to work we must use "web" as the target not "browserslist" target: process.env.WEBPACK_SERVE ? 'web' : 'browserslist', mode: 'development', - entry: './scripts/site.js', + entry: { 'main.jellyfin': './scripts/site.js' }, devtool: 'source-map', module: { rules: [ diff --git a/webpack.prod.js b/webpack.prod.js index ad02582f91..f87e9b429e 100644 --- a/webpack.prod.js +++ b/webpack.prod.js @@ -5,7 +5,7 @@ const WorkboxPlugin = require('workbox-webpack-plugin'); module.exports = merge(common, { mode: 'production', - entry: './scripts/site.js', + entry: { 'main.jellyfin': './scripts/site.js' }, plugins: [ new WorkboxPlugin.InjectManifest({ swSrc: path.resolve(__dirname, 'src/serviceworker.js'),