stremio-web/webpack.config.js

302 lines
10 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');
2019-07-18 12:26:33 +00:00
const { CleanWebpackPlugin } = require('clean-webpack-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');
2023-11-30 13:38:12 +00:00
const WebpackPwaManifest = require('webpack-pwa-manifest');
2020-02-11 20:42:59 +00:00
const pachageJson = 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'),
filename: `${COMMIT_HASH}/scripts/[name].js`
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$/,
exclude: /node_modules/,
2021-11-01 15:56:00 +00:00
type: 'asset/resource',
generator: {
filename: `${COMMIT_HASH}/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,
2020-01-30 14:58:25 +00:00
DEBUG: argv.mode !== 'production',
2020-02-12 07:01:16 +00:00
VERSION: pachageJson.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']
}),
2021-01-06 16:29:27 +00:00
new CleanWebpackPlugin({
cleanOnceBeforeBuildPatterns: ['*']
}),
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: [
{ from: 'favicons', to: 'favicons' },
{ from: 'images', to: 'images' },
{ from: 'screenshots/*.webp', to: './' },
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
}),
new WebpackPwaManifest({
name: 'Stremio Web',
short_name: 'Stremio',
description: 'Freedom To Stream',
background_color: '#161523',
theme_color: '#2a2843',
orientation: 'any',
display: 'standalone',
2023-12-07 20:19:19 +00:00
display_override: ['standalone'],
2023-11-30 13:38:12 +00:00
scope: './',
2023-12-07 20:19:19 +00:00
start_url: './',
2023-11-30 13:38:12 +00:00
publicPath: './',
icons: [
{
src: 'images/icon.png',
destination: 'icons',
2023-11-30 13:38:12 +00:00
sizes: [196, 512],
purpose: 'any'
2023-11-30 13:38:12 +00:00
},
{
src: 'images/maskable_icon.png',
destination: 'maskable_icons',
2023-11-30 13:38:12 +00:00
sizes: [196, 512],
purpose: 'maskable',
ios: true
2023-11-30 13:38:12 +00:00
},
{
src: 'favicons/favicon.ico',
destination: 'favicons',
2023-12-07 20:19:19 +00:00
sizes: [256],
2023-11-30 13:38:12 +00:00
}
2023-12-07 20:19:19 +00:00
],
2023-12-07 20:27:48 +00:00
screenshots : [
{
src: 'screenshots/board_wide.webp',
2023-12-07 20:27:48 +00:00
sizes: '1440x900',
type: 'image/webp',
form_factor: 'wide',
label: 'Homescreen of Stremio'
},
{
src: 'screenshots/board_narrow.webp',
2023-12-07 20:27:48 +00:00
sizes: '414x896',
type: 'image/webp',
form_factor: 'narrow',
label: 'Homescreen of Stremio'
}
],
2023-11-30 13:38:12 +00:00
fingerprints: false,
ios: true
}),
2022-07-27 08:15:06 +00:00
].filter(Boolean)
2020-01-30 14:58:25 +00:00
});