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-03-09 01:19:29 +01:00
|
|
|
|
2019-03-12 20:53:55 +01:00
|
|
|
const NODE_ENV = process.env.NODE_ENV || 'development';
|
|
|
|
|
|
|
|
const { ifProduction } = getIfUtils(NODE_ENV);
|
2019-03-05 05:46:57 +01:00
|
|
|
|
|
|
|
const UI_ROOT = path.resolve(__dirname, 'src/ui/');
|
|
|
|
const STATIC_ROOT = path.resolve(__dirname, 'static/');
|
|
|
|
const DIST_ROOT = path.resolve(__dirname, 'dist/');
|
|
|
|
|
2019-04-01 04:00:31 +02:00
|
|
|
console.log(ifProduction('production', 'development'));
|
2019-03-27 05:40:02 +01:00
|
|
|
|
2019-03-15 21:45:16 +01:00
|
|
|
let baseConfig = {
|
2019-03-09 01:19:29 +01:00
|
|
|
mode: ifProduction('production', 'development'),
|
2019-03-27 05:40:02 +01:00
|
|
|
devtool: ifProduction(false, 'inline-cheap-source-map'),
|
|
|
|
optimization: {
|
|
|
|
minimizer: [
|
|
|
|
new TerserPlugin({
|
|
|
|
parallel: true,
|
|
|
|
terserOptions: {
|
|
|
|
mangle: true,
|
|
|
|
toplevel: true,
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
],
|
|
|
|
},
|
2019-03-05 05:46:57 +01:00
|
|
|
node: {
|
|
|
|
__dirname: false,
|
|
|
|
},
|
|
|
|
module: {
|
|
|
|
rules: [
|
|
|
|
{
|
|
|
|
test: /\.jsx?$/,
|
2019-03-08 20:20:17 +01:00
|
|
|
exclude: /node_modules/,
|
2019-03-05 05:46:57 +01:00
|
|
|
loader: 'babel-loader',
|
|
|
|
},
|
2019-04-03 07:56:58 +02:00
|
|
|
{
|
|
|
|
test: /\.module.scss$/,
|
|
|
|
use: [
|
|
|
|
'style-loader',
|
|
|
|
{
|
|
|
|
loader: 'css-loader',
|
|
|
|
options: {
|
|
|
|
modules: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
'postcss-loader',
|
|
|
|
'sass-loader',
|
|
|
|
],
|
|
|
|
},
|
2019-03-05 05:46:57 +01:00
|
|
|
{
|
2019-03-13 06:59:07 +01:00
|
|
|
test: /\.s?css$/,
|
2019-04-03 07:56:58 +02:00
|
|
|
exclude: /\.module.scss$/,
|
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: {
|
2019-04-04 23:05:23 +02:00
|
|
|
outputPath: 'static/img',
|
2019-03-05 05:46:57 +01:00
|
|
|
name: '[name].[ext]',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2019-03-13 06:59:07 +01:00
|
|
|
test: /\.(woff|woff2)$/,
|
2019-03-05 05:46:57 +01:00
|
|
|
use: {
|
|
|
|
loader: 'file-loader',
|
|
|
|
options: {
|
2019-04-04 23:05:23 +02:00
|
|
|
outputPath: 'static/font',
|
2019-03-05 05:46:57 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
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: {
|
|
|
|
'lbry-redux$': 'lbry-redux/dist/bundle.es.js',
|
|
|
|
|
|
|
|
// 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-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 ProvidePlugin({
|
|
|
|
i18n: ['i18n', 'default'],
|
|
|
|
__: ['i18n/__', 'default'],
|
|
|
|
__n: ['i18n/__n', 'default'],
|
|
|
|
}),
|
|
|
|
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),
|
2019-03-08 21:12:20 +01:00
|
|
|
'process.env.SDK_API_URL': JSON.stringify(process.env.SDK_API_URL),
|
2019-03-12 20:53:55 +01:00
|
|
|
'process.env.LBRY_API_URL': JSON.stringify(process.env.LBRY_API_URL),
|
2019-03-05 05:46:57 +01:00
|
|
|
}),
|
|
|
|
],
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = baseConfig;
|