lbry-desktop/webpack.base.config.js

122 lines
4 KiB
JavaScript
Raw Permalink Normal View History

2019-03-05 05:46:57 +01:00
const path = require('path');
2019-03-15 19:58:42 +01:00
const webpack = require('webpack');
const Dotenv = require('dotenv-webpack');
const { DefinePlugin } = require('webpack');
const { getIfUtils } = require('webpack-config-utils');
2019-03-27 05:40:02 +01:00
const TerserPlugin = require('terser-webpack-plugin');
2019-11-07 20:39:22 +01:00
2019-03-12 20:53:55 +01:00
const NODE_ENV = process.env.NODE_ENV || 'development';
const { ifProduction } = getIfUtils(NODE_ENV);
2019-11-07 20:39:22 +01:00
const UI_ROOT = path.resolve(__dirname, 'ui/');
2019-03-05 05:46:57 +01:00
const STATIC_ROOT = path.resolve(__dirname, 'static/');
let baseConfig = {
2019-03-09 01:19:29 +01:00
mode: ifProduction('production', 'development'),
2020-02-14 17:42:38 +01:00
devtool: ifProduction('source-map', 'eval-cheap-module-source-map'),
2019-03-27 05:40:02 +01:00
optimization: {
minimizer: [
new TerserPlugin({
parallel: true,
2020-02-05 04:46:00 +01:00
sourceMap: true,
2019-03-27 05:40:02 +01:00
}),
],
},
2019-03-05 05:46:57 +01:00
node: {
__dirname: false,
},
devServer: {
historyApiFallback: true,
},
2019-03-05 05:46:57 +01:00
module: {
rules: [
{
test: /\.jsx?$/,
loader: 'babel-loader',
options: {
plugins: ['@babel/plugin-syntax-dynamic-import'],
},
2019-03-05 05:46:57 +01:00
},
{
2019-03-13 06:59:07 +01:00
test: /\.s?css$/,
use: [
{ loader: 'style-loader' },
{ loader: 'css-loader' },
{ loader: 'postcss-loader',
options: {
2022-03-09 16:56:18 +01:00
postcssOptions: {
plugins: [
'postcss-import',
function () {
return [ require('postcss-rtlcss')() ];
},
require('postcss-omit-import-tilde'), // postcss doesn't understand ~@reach in third-party.scss
],
},
},
},
{ loader: 'sass-loader'},
],
2019-03-05 05:46:57 +01:00
},
{
test: /\.(png|svg|gif)$/,
use: {
loader: 'file-loader',
options: {
outputPath: 'img/',
2019-03-05 05:46:57 +01:00
name: '[name].[ext]',
},
},
},
2019-03-07 04:37:25 +01:00
{
2019-03-20 05:52:37 +01:00
test: /\.(vert|frag|glsl)$/,
2019-03-07 04:37:25 +01:00
use: {
2019-03-20 05:52:37 +01:00
loader: 'raw-loader',
2019-03-07 04:37:25 +01:00
},
},
2019-03-05 05:46:57 +01:00
],
},
2021-10-16 00:07:58 +02:00
// Allows imports for all directories inside '/ui' :)
2019-03-05 05:46:57 +01:00
resolve: {
modules: [UI_ROOT, 'node_modules', __dirname],
extensions: ['.js', '.jsx', '.json', '.scss'],
2019-04-03 07:56:58 +02:00
alias: {
config: path.resolve(__dirname, 'config.js'),
homepage: 'util/homepage.js',
homepages: process.env.CUSTOM_HOMEPAGE === 'true' ? path.resolve(__dirname, 'custom/homepages/v2/index.js') : ('homepages/index.js'),
2021-07-23 06:26:01 +02:00
memes: process.env.CUSTOM_HOMEPAGE === 'true' ? path.resolve(__dirname, 'custom/homepages/meme/index.js') : path.resolve(__dirname, 'homepages/meme/index.js'),
lbryinc: 'extras/lbryinc',
2021-10-14 22:46:36 +02:00
recsys: 'extras/recsys',
2019-04-03 07:56:58 +02:00
// Build optimizations for 'redux-persist-transform-filter'
'redux-persist-transform-filter': 'redux-persist-transform-filter/index.js',
'lodash.get': 'lodash-es/get',
'lodash.set': 'lodash-es/set',
'lodash.unset': 'lodash-es/unset',
'lodash.pickby': 'lodash-es/pickBy',
'lodash.isempty': 'lodash-es/isEmpty',
'lodash.forin': 'lodash-es/forIn',
'lodash.clonedeep': 'lodash-es/cloneDeep',
2019-08-21 20:22:51 +02:00
...ifProduction({}, { 'react-dom': '@hot-loader/react-dom' }),
2019-04-03 07:56:58 +02:00
},
2019-11-21 17:38:41 +01:00
symlinks: false,
2019-03-05 05:46:57 +01:00
},
plugins: [
2019-03-27 05:40:02 +01:00
new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/),
new webpack.EnvironmentPlugin(['NODE_ENV']),
2019-03-05 05:46:57 +01:00
new DefinePlugin({
__static: `"${path.join(__dirname, 'static').replace(/\\/g, '\\\\')}"`,
2019-03-12 20:53:55 +01:00
'process.env.NODE_ENV': JSON.stringify(NODE_ENV),
'process.env.LBRY_API_URL': JSON.stringify(process.env.LBRY_API_URL),
2020-02-05 04:46:00 +01:00
'process.env.SENTRY_AUTH_TOKEN': JSON.stringify(process.env.SENTRY_AUTH_TOKEN),
2020-06-01 19:03:19 +02:00
'process.env.MOONPAY_SECRET_KEY': JSON.stringify(process.env.MOONPAY_SECRET_KEY),
2019-03-05 05:46:57 +01:00
}),
new Dotenv({
allowEmptyValues: true, // allow empty variables (e.g. `FOO=`) (treat it as empty string, rather than missing)
systemvars: true, // load all the predefined 'process.env' variables which will trump anything local per dotenv specs.
silent: false, // hide any errors
defaults: true, // load '.env.defaults' as the default values if empty.
}),
2019-03-05 05:46:57 +01:00
],
};
module.exports = baseConfig;