lbry-desktop/webpack.base.config.js

94 lines
2.7 KiB
JavaScript
Raw 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');
2019-03-05 05:46:57 +01:00
const merge = require('webpack-merge');
const { DefinePlugin, ProvidePlugin } = require('webpack');
2019-03-09 01:19:29 +01:00
const { getIfUtils, removeEmpty } = 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-04 20:37:17 +01:00
devtool: ifProduction('source-map', 'eval-cheap-source-map'),
2019-03-27 05:40:02 +01:00
optimization: {
minimizer: [
new TerserPlugin({
parallel: true,
2020-02-04 20:37:17 +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$/,
2019-04-24 16:02:08 +02:00
use: ['style-loader', 'css-loader', 'postcss-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
],
},
// Allows imports for all directories inside '/ui'
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'),
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-04 20:37:17 +01:00
'process.env.SENTRY_AUTH_TOKEN': JSON.stringify(process.env.SENTRY_AUTH_TOKEN),
2019-03-05 05:46:57 +01:00
}),
],
};
module.exports = baseConfig;