2020-05-04 03:44:12 -07:00
|
|
|
const path = require('path');
|
2020-08-15 03:44:52 -07:00
|
|
|
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
|
2020-08-16 11:24:45 -07:00
|
|
|
const CopyPlugin = require('copy-webpack-plugin');
|
2020-11-19 21:36:35 -07:00
|
|
|
const HtmlWebpackPlugin = require('html-webpack-plugin');
|
2022-09-29 06:13:12 -07:00
|
|
|
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
|
2021-10-04 21:26:00 -07:00
|
|
|
const { DefinePlugin } = require('webpack');
|
2020-05-29 14:32:45 -07:00
|
|
|
|
2020-11-20 20:07:37 -07:00
|
|
|
const Assets = [
|
|
|
|
'native-promise-only/npo.js',
|
|
|
|
'libarchive.js/dist/worker-bundle.js',
|
2022-05-15 19:10:42 -07:00
|
|
|
'@jellyfin/libass-wasm/dist/js/subtitles-octopus-worker.js',
|
|
|
|
'@jellyfin/libass-wasm/dist/js/subtitles-octopus-worker.data',
|
|
|
|
'@jellyfin/libass-wasm/dist/js/subtitles-octopus-worker.wasm',
|
|
|
|
'@jellyfin/libass-wasm/dist/js/subtitles-octopus-worker-legacy.js',
|
|
|
|
'@jellyfin/libass-wasm/dist/js/subtitles-octopus-worker-legacy.data',
|
|
|
|
'@jellyfin/libass-wasm/dist/js/subtitles-octopus-worker-legacy.js.mem',
|
2020-11-20 20:07:37 -07:00
|
|
|
'pdfjs-dist/build/pdf.worker.js'
|
|
|
|
];
|
|
|
|
|
|
|
|
const LibarchiveWasm = [
|
|
|
|
'libarchive.js/dist/wasm-gen/libarchive.js',
|
|
|
|
'libarchive.js/dist/wasm-gen/libarchive.wasm'
|
|
|
|
];
|
|
|
|
|
2022-09-29 06:13:12 -07:00
|
|
|
const DEV_MODE = process.env.NODE_ENV !== 'production';
|
|
|
|
|
|
|
|
const NODE_MODULES_REGEX = /[\\/]node_modules[\\/]/;
|
|
|
|
|
|
|
|
const config = {
|
2020-05-04 03:44:12 -07:00
|
|
|
context: path.resolve(__dirname, 'src'),
|
2020-11-27 09:17:04 -07:00
|
|
|
target: 'browserslist',
|
2019-04-28 03:38:30 -07:00
|
|
|
resolve: {
|
2021-06-11 05:49:57 -07:00
|
|
|
extensions: ['.tsx', '.ts', '.js'],
|
2019-04-28 03:38:30 -07:00
|
|
|
modules: [
|
2020-05-04 03:44:12 -07:00
|
|
|
path.resolve(__dirname, 'node_modules')
|
2019-04-28 03:38:30 -07:00
|
|
|
]
|
2019-05-24 21:28:06 -07:00
|
|
|
},
|
2019-09-30 16:58:05 -07:00
|
|
|
plugins: [
|
2021-10-04 21:26:00 -07:00
|
|
|
new DefinePlugin({
|
|
|
|
__WEBPACK_SERVE__: JSON.stringify(!!process.env.WEBPACK_SERVE)
|
|
|
|
}),
|
2020-08-16 11:24:45 -07:00
|
|
|
new CleanWebpackPlugin(),
|
2020-11-19 21:36:35 -07:00
|
|
|
new HtmlWebpackPlugin({
|
|
|
|
filename: 'index.html',
|
2021-07-14 12:33:30 -07:00
|
|
|
template: 'index.html',
|
|
|
|
// Append file hashes to bundle urls for cache busting
|
|
|
|
hash: true
|
2020-11-19 21:36:35 -07:00
|
|
|
}),
|
2020-08-16 11:24:45 -07:00
|
|
|
new CopyPlugin({
|
|
|
|
patterns: [
|
|
|
|
{
|
|
|
|
from: 'themes/',
|
|
|
|
to: 'themes/'
|
2020-10-21 17:10:40 -07:00
|
|
|
},
|
|
|
|
{
|
|
|
|
from: 'assets/**',
|
|
|
|
globOptions: {
|
2021-03-06 02:52:49 -07:00
|
|
|
dot: true,
|
2020-10-21 17:10:40 -07:00
|
|
|
ignore: ['**/css/*']
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
2021-03-06 02:51:55 -07:00
|
|
|
from: '*.*',
|
2020-10-21 17:10:40 -07:00
|
|
|
globOptions: {
|
2021-03-06 02:52:49 -07:00
|
|
|
dot: true,
|
2020-10-21 17:10:40 -07:00
|
|
|
ignore: ['**.js', '**.html']
|
|
|
|
}
|
2020-08-16 11:24:45 -07:00
|
|
|
}
|
|
|
|
]
|
2020-11-09 12:20:55 -07:00
|
|
|
}),
|
2020-11-20 20:07:37 -07:00
|
|
|
new CopyPlugin({
|
|
|
|
patterns: Assets.map(asset => {
|
|
|
|
return {
|
|
|
|
from: path.resolve(__dirname, `./node_modules/${asset}`),
|
|
|
|
to: path.resolve(__dirname, './dist/libraries')
|
|
|
|
};
|
|
|
|
})
|
|
|
|
}),
|
|
|
|
new CopyPlugin({
|
|
|
|
patterns: LibarchiveWasm.map(asset => {
|
|
|
|
return {
|
|
|
|
from: path.resolve(__dirname, `./node_modules/${asset}`),
|
|
|
|
to: path.resolve(__dirname, './dist/libraries/wasm-gen')
|
|
|
|
};
|
|
|
|
})
|
2020-08-16 11:24:45 -07:00
|
|
|
})
|
2020-08-15 03:44:52 -07:00
|
|
|
],
|
|
|
|
output: {
|
2022-09-05 22:45:59 -07:00
|
|
|
filename: '[name].bundle.js',
|
2021-07-14 12:33:30 -07:00
|
|
|
chunkFilename: '[name].[contenthash].chunk.js',
|
2021-02-27 02:59:29 -07:00
|
|
|
path: path.resolve(__dirname, 'dist'),
|
|
|
|
publicPath: ''
|
2020-10-18 07:29:40 -07:00
|
|
|
},
|
2022-09-05 22:45:59 -07:00
|
|
|
optimization: {
|
|
|
|
runtimeChunk: 'single',
|
|
|
|
splitChunks: {
|
|
|
|
chunks: 'all',
|
|
|
|
maxInitialRequests: Infinity,
|
|
|
|
cacheGroups: {
|
2022-09-29 06:13:12 -07:00
|
|
|
node_modules: {
|
|
|
|
test(module) {
|
|
|
|
return NODE_MODULES_REGEX.test(module.context);
|
|
|
|
},
|
2022-09-05 22:45:59 -07:00
|
|
|
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];
|
2022-10-12 07:24:05 -07:00
|
|
|
// if "packageName" is a namespace (i.e. @jellyfin) get the namespace + packageName
|
|
|
|
if (packageName.startsWith('@')) {
|
|
|
|
const parts = module.context
|
|
|
|
.substring(module.context.lastIndexOf(packageName))
|
|
|
|
.split('/');
|
|
|
|
return `node_modules.${parts[0]}.${parts[1]}`;
|
|
|
|
}
|
|
|
|
|
2022-09-05 22:45:59 -07:00
|
|
|
return `node_modules.${packageName}`;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2020-10-18 07:29:40 -07:00
|
|
|
module: {
|
|
|
|
rules: [
|
2020-10-18 12:37:54 -07:00
|
|
|
{
|
|
|
|
test: /\.(html)$/,
|
|
|
|
use: {
|
|
|
|
loader: 'html-loader'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
2021-06-11 05:49:57 -07:00
|
|
|
test: /\.(js|jsx)$/,
|
2022-10-07 04:39:16 -07:00
|
|
|
exclude: /node_modules[\\/](?!@uupaa[\\/]dynamic-import-polyfill|@remix-run[\\/]router|blurhash|date-fns|epubjs|flv.js|libarchive.js|marked|react-router|screenfull)/,
|
2020-10-18 12:37:54 -07:00
|
|
|
use: [{
|
2022-09-05 23:18:19 -07:00
|
|
|
loader: 'babel-loader',
|
|
|
|
options: {
|
|
|
|
cacheCompression: false,
|
|
|
|
cacheDirectory: true
|
|
|
|
}
|
2020-10-18 12:37:54 -07:00
|
|
|
}]
|
|
|
|
},
|
2021-12-30 14:04:12 -07:00
|
|
|
{
|
|
|
|
test: /\.worker\.ts$/,
|
|
|
|
exclude: /node_modules/,
|
|
|
|
use: [
|
|
|
|
'worker-loader',
|
|
|
|
'ts-loader'
|
|
|
|
]
|
|
|
|
},
|
2021-06-11 05:49:57 -07:00
|
|
|
{
|
|
|
|
test: /\.(ts|tsx)$/,
|
|
|
|
exclude: /node_modules/,
|
|
|
|
use: [{
|
|
|
|
loader: 'ts-loader'
|
|
|
|
}]
|
|
|
|
},
|
2020-11-27 15:46:16 -07:00
|
|
|
/* modules that Babel breaks when transforming to ESM */
|
|
|
|
{
|
|
|
|
test: /node_modules[\\/](pdfjs-dist|xmldom)[\\/].*\.js$/,
|
|
|
|
use: [{
|
|
|
|
loader: 'babel-loader',
|
|
|
|
options: {
|
2022-09-05 23:18:19 -07:00
|
|
|
cacheCompression: false,
|
|
|
|
cacheDirectory: true,
|
2020-11-27 15:46:16 -07:00
|
|
|
plugins: [
|
|
|
|
'@babel/transform-modules-umd'
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}]
|
|
|
|
},
|
2020-11-05 17:00:34 -07:00
|
|
|
{
|
|
|
|
test: /\.s[ac]ss$/i,
|
|
|
|
use: [
|
2022-09-29 06:13:12 -07:00
|
|
|
DEV_MODE ? 'style-loader' : MiniCssExtractPlugin.loader,
|
2020-11-05 17:00:34 -07:00
|
|
|
'css-loader',
|
|
|
|
{
|
|
|
|
loader: 'postcss-loader',
|
|
|
|
options: {
|
2021-06-14 22:05:47 -07:00
|
|
|
postcssOptions: {
|
|
|
|
config: path.resolve(__dirname, 'postcss.config.js')
|
2020-11-05 17:00:34 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
'sass-loader'
|
|
|
|
]
|
|
|
|
},
|
2020-10-18 12:37:54 -07:00
|
|
|
{
|
|
|
|
test: /\.css$/i,
|
|
|
|
use: [
|
2022-09-29 06:13:12 -07:00
|
|
|
DEV_MODE ? 'style-loader' : MiniCssExtractPlugin.loader,
|
2020-10-18 12:37:54 -07:00
|
|
|
'css-loader',
|
|
|
|
{
|
|
|
|
loader: 'postcss-loader',
|
|
|
|
options: {
|
2021-06-14 22:05:47 -07:00
|
|
|
postcssOptions: {
|
|
|
|
config: path.resolve(__dirname, 'postcss.config.js')
|
2020-10-18 12:37:54 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.(png|jpg|gif|svg)$/i,
|
2021-10-22 22:24:14 -07:00
|
|
|
type: 'asset/resource'
|
2020-10-18 12:37:54 -07:00
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.(woff|woff2|eot|ttf|otf)$/,
|
2021-10-22 22:24:14 -07:00
|
|
|
type: 'asset/resource'
|
2020-10-18 12:37:54 -07:00
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.(mp3)$/i,
|
2021-10-22 22:24:14 -07:00
|
|
|
type: 'asset/resource'
|
2020-10-18 12:37:54 -07:00
|
|
|
},
|
2020-10-18 07:29:40 -07:00
|
|
|
{
|
|
|
|
test: require.resolve('jquery'),
|
|
|
|
loader: 'expose-loader',
|
|
|
|
options: {
|
|
|
|
exposes: ['$', 'jQuery']
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
2020-08-15 03:44:52 -07:00
|
|
|
}
|
2019-05-22 12:18:17 -07:00
|
|
|
};
|
2022-09-29 06:13:12 -07:00
|
|
|
|
|
|
|
if (!DEV_MODE) {
|
|
|
|
config.plugins.push(new MiniCssExtractPlugin());
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = config;
|