stremio-web/webpack.config.js

213 lines
7.7 KiB
JavaScript
Raw Normal View History

2020-04-08 08:45:16 +00:00
// Copyright (C) 2017-2020 Smart code 203358507
2018-06-04 12:56:17 +00:00
const path = require('path');
2021-09-02 15:59:27 +00:00
const { execSync } = require('child_process');
const webpack = require('webpack');
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');
const CopyWebpackPlugin = require('copy-webpack-plugin');
2018-11-06 15:53:30 +00:00
const TerserPlugin = require('terser-webpack-plugin');
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
2020-01-30 14:58:25 +00:00
module.exports = (env, argv) => ({
2021-01-06 15:45:30 +00:00
mode: argv.mode,
2018-06-04 12:56:17 +00:00
entry: './src/index.js',
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/,
2018-06-04 12:56:17 +00:00
use: {
2018-11-06 15:53:30 +00:00
loader: 'babel-loader',
options: {
2019-07-18 11:45:15 +00:00
presets: [
'@babel/preset-env',
'@babel/preset-react'
],
2019-04-10 08:04:33 +00:00
plugins: [
'@babel/plugin-proposal-class-properties',
2019-04-16 07:27:37 +00:00
'@babel/plugin-proposal-object-rest-spread'
2019-04-10 08:04:33 +00:00
]
2018-11-06 15:53:30 +00:00
}
2018-06-04 12:56:17 +00:00
}
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: {
esModule: false,
modules: {
namedExport: false
}
}
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/,
loader: 'file-loader',
options: {
2021-01-06 15:45:30 +00:00
esModule: false,
name: '[name].[ext]',
outputPath: `${COMMIT_HASH}/fonts`,
publicPath: `/${COMMIT_HASH}/fonts`
}
},
{
test: /\.(png|jpe?g)$/,
exclude: /node_modules/,
loader: 'file-loader',
options: {
esModule: false,
2021-01-06 15:45:30 +00:00
name: '[name].[ext]',
outputPath: `${COMMIT_HASH}/images`,
publicPath: `/${COMMIT_HASH}/images`
}
},
{
test: /\.wasm$/,
loader: 'file-loader',
options: {
esModule: false,
name: '[name].[ext]',
outputPath: `${COMMIT_HASH}/binaries`,
publicPath: `/${COMMIT_HASH}/binaries`
}
2018-06-04 12:56:17 +00:00
}
]
},
2018-06-04 13:34:15 +00:00
resolve: {
2019-04-10 08:04:33 +00:00
extensions: ['.js', '.json', '.less', '.wasm'],
2018-06-04 13:34:15 +00:00
alias: {
2021-01-06 15:45:30 +00:00
'stremio': path.join(__dirname, 'src'),
'stremio-router': path.join(__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-01-06 15:45:30 +00:00
contentBase: false,
2018-11-07 14:14:04 +00:00
hot: false,
2020-12-14 09:55:10 +00:00
inline: false,
2021-01-15 17:00:41 +00:00
https: true,
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: ['*']
}),
new CopyWebpackPlugin({
2021-01-06 16:29:27 +00:00
patterns: [{ from: 'favicons', to: `${COMMIT_HASH}/favicons` }]
}),
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',
2021-01-06 15:45:30 +00:00
faviconsPath: `${COMMIT_HASH}/favicons`
2019-07-18 11:45:15 +00:00
})
2018-06-04 12:56:17 +00:00
]
2020-01-30 14:58:25 +00:00
});