stremio-web/webpack.config.js

250 lines
8.6 KiB
JavaScript
Raw Normal View History

2023-06-09 17:16:32 +00:00
// Copyright (C) 2017-2023 Smart code 203358507
2020-04-08 08:45:16 +00:00
2018-06-04 12:56:17 +00:00
const path = require('path');
2024-12-22 13:19:07 +00:00
const os = require('os');
2021-09-02 15:59:27 +00:00
const { execSync } = require('child_process');
const webpack = require('webpack');
2024-12-22 13:19:07 +00:00
const threadLoader = require('thread-loader');
2018-06-04 12:56:17 +00:00
const HtmlWebPackPlugin = require('html-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
2022-07-27 08:15:06 +00:00
const WorkboxPlugin = require('workbox-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
2018-11-06 15:53:30 +00:00
const TerserPlugin = require('terser-webpack-plugin');
2025-09-27 13:23:06 +00:00
const packageJson = require('./package.json');
2018-06-04 12:56:17 +00:00
2021-09-02 15:59:27 +00:00
const COMMIT_HASH = execSync('git rev-parse HEAD').toString().trim();
2021-01-06 15:45:30 +00:00
2024-12-22 13:19:07 +00:00
const THREAD_LOADER = {
loader: 'thread-loader',
options: {
name: 'shared-pool',
workers: os.cpus().length,
},
};
threadLoader.warmup(
THREAD_LOADER.options,
[
'babel-loader',
'ts-loader',
'css-loader',
'postcss-loader',
'less-loader',
],
);
2020-01-30 14:58:25 +00:00
module.exports = (env, argv) => ({
2021-01-06 15:45:30 +00:00
mode: argv.mode,
devtool: argv.mode === 'production' ? 'source-map' : 'eval-source-map',
2022-07-09 20:16:43 +00:00
entry: {
main: './src/index.js',
2022-08-04 14:07:00 +00:00
worker: './node_modules/@stremio/stremio-core-web/worker.js'
2022-07-09 20:16:43 +00:00
},
2020-01-23 14:09:43 +00:00
output: {
2021-01-06 15:45:30 +00:00
path: path.join(__dirname, 'build'),
2026-01-14 02:21:08 +00:00
filename: `${COMMIT_HASH}/scripts/[name].js`,
clean: true,
2020-01-23 14:09:43 +00:00
},
2018-06-04 12:56:17 +00:00
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
2024-12-22 13:19:07 +00:00
use: [
THREAD_LOADER,
{
loader: 'babel-loader',
options: {
presets: [
'@babel/preset-env',
'@babel/preset-react'
],
}
2018-11-06 15:53:30 +00:00
}
2024-12-22 13:19:07 +00:00
]
2018-06-04 14:38:28 +00:00
},
{
test: /\.(ts|tsx)$/,
exclude: /node_modules/,
2024-12-22 13:19:07 +00:00
use: [
THREAD_LOADER,
{
loader: 'ts-loader',
options: {
happyPackMode: true,
}
}
]
},
2018-06-04 14:38:28 +00:00
{
2018-06-05 08:49:35 +00:00
test: /\.less$/,
2018-06-04 14:38:28 +00:00
exclude: /node_modules/,
use: [
{
loader: MiniCssExtractPlugin.loader,
options: {
2021-11-01 15:56:00 +00:00
esModule: false
}
2018-06-04 14:38:28 +00:00
},
2024-12-22 13:19:07 +00:00
THREAD_LOADER,
2018-06-04 14:38:28 +00:00
{
loader: 'css-loader',
options: {
esModule: false,
2019-07-18 12:55:04 +00:00
importLoaders: 2,
modules: {
namedExport: false,
2019-09-11 13:35:29 +00:00
localIdentName: '[local]-[hash:base64:5]'
2019-07-18 12:55:04 +00:00
}
2018-06-12 14:44:22 +00:00
}
},
{
loader: 'postcss-loader',
options: {
postcssOptions: {
plugins: [
require('cssnano')({
preset: [
'advanced',
{
autoprefixer: {
add: true,
remove: true,
flexbox: false,
grid: false
},
cssDeclarationSorter: true,
calc: false,
colormin: false,
convertValues: false,
discardComments: {
removeAll: true,
},
discardOverridden: false,
2021-09-02 15:59:27 +00:00
discardUnused: false,
mergeIdents: false,
normalizeDisplayValues: false,
normalizePositions: false,
normalizeRepeatStyle: false,
normalizeUnicode: false,
normalizeUrl: false,
reduceIdents: false,
reduceInitial: false,
zindex: false
}
]
})
]
}
2018-06-04 14:38:28 +00:00
}
2018-06-05 08:49:35 +00:00
},
{
loader: 'less-loader',
options: {
lessOptions: {
strictMath: true,
ieCompat: false
}
2018-06-05 08:49:35 +00:00
}
2018-06-04 14:38:28 +00:00
}
]
},
{
test: /\.(ttf|woff2)$/,
exclude: /node_modules/,
2021-11-01 15:56:00 +00:00
type: 'asset/resource',
generator: {
filename: 'fonts/[name][ext][query]'
}
},
{
2023-07-05 17:10:14 +00:00
test: /\.(png|jpe?g|svg)$/,
exclude: /node_modules/,
2021-11-01 15:56:00 +00:00
type: 'asset/resource',
generator: {
filename: 'images/[name][ext][query]'
2021-01-06 15:45:30 +00:00
}
},
{
test: /\.wasm$/,
2021-11-01 15:56:00 +00:00
type: 'asset/resource',
generator: {
filename: `${COMMIT_HASH}/binaries/[name][ext][query]`
}
2018-06-04 12:56:17 +00:00
}
]
},
2018-06-04 13:34:15 +00:00
resolve: {
extensions: ['.tsx', '.ts', '.js', '.json', '.less', '.wasm'],
2018-06-04 13:34:15 +00:00
alias: {
'stremio': path.resolve(__dirname, 'src'),
'stremio-router': path.resolve(__dirname, 'src', 'router')
2018-06-04 13:34:15 +00:00
}
},
devServer: {
2018-11-07 14:14:04 +00:00
host: '0.0.0.0',
2021-11-01 15:56:00 +00:00
static: false,
2018-11-07 14:14:04 +00:00
hot: false,
server: 'https',
2021-01-15 17:00:41 +00:00
liveReload: false
},
2018-11-06 15:53:30 +00:00
optimization: {
minimize: true,
2018-11-06 15:53:30 +00:00
minimizer: [
new TerserPlugin({
test: /\.js$/,
2019-09-30 07:51:15 +00:00
extractComments: false,
2018-11-06 15:53:30 +00:00
terserOptions: {
ecma: 5,
mangle: true,
2019-09-24 20:05:40 +00:00
warnings: false,
2018-11-06 15:53:30 +00:00
output: {
comments: false,
beautify: false,
wrap_iife: true
}
}
})
]
},
2018-06-04 12:56:17 +00:00
plugins: [
2021-01-06 16:29:27 +00:00
new webpack.ProgressPlugin(),
2020-01-30 14:58:25 +00:00
new webpack.EnvironmentPlugin({
2021-01-06 15:45:30 +00:00
SENTRY_DSN: null,
...env,
SERVICE_WORKER_DISABLED: false,
2020-01-30 14:58:25 +00:00
DEBUG: argv.mode !== 'production',
2025-09-27 13:23:06 +00:00
VERSION: packageJson.version,
2021-01-06 15:45:30 +00:00
COMMIT_HASH
2020-01-30 14:58:25 +00:00
}),
2021-08-31 14:48:13 +00:00
new webpack.ProvidePlugin({
Buffer: ['buffer', 'Buffer']
}),
2024-10-07 10:17:33 +00:00
argv.mode === 'production' &&
2022-07-27 08:15:06 +00:00
new WorkboxPlugin.GenerateSW({
maximumFileSizeToCacheInBytes: 20000000,
clientsClaim: true,
skipWaiting: true
}),
new CopyWebpackPlugin({
2022-07-27 08:15:06 +00:00
patterns: [
2026-01-14 03:34:49 +00:00
{ from: 'assets/favicons', to: 'favicons' },
{ from: 'assets/images', to: 'images' },
{ from: 'assets/screenshots/*.webp', to: 'screenshots/[name][ext]' },
2025-03-17 12:53:25 +00:00
{ from: '.well-known', to: '.well-known' },
{ from: 'manifest.json', to: 'manifest.json' },
2022-07-27 08:15:06 +00:00
]
2021-01-06 16:29:27 +00:00
}),
new MiniCssExtractPlugin({
filename: `${COMMIT_HASH}/styles/[name].css`
}),
2019-07-18 11:45:15 +00:00
new HtmlWebPackPlugin({
template: './src/index.html',
2021-01-06 15:45:30 +00:00
inject: false,
2021-09-08 16:19:23 +00:00
scriptLoading: 'blocking',
faviconsPath: 'favicons',
imagesPath: 'images',
2023-11-30 13:38:12 +00:00
}),
2022-07-27 08:15:06 +00:00
].filter(Boolean)
2020-01-30 14:58:25 +00:00
});