lbry-desktop/web/webpack.config.js

121 lines
3.1 KiB
JavaScript
Raw Normal View History

const { WEBPACK_WEB_PORT, LBRY_WEB_API } = require('../config.js');
2019-03-05 05:46:57 +01:00
const path = require('path');
const fs = require('fs');
2019-03-05 05:46:57 +01:00
const merge = require('webpack-merge');
2019-11-07 20:39:22 +01:00
const baseConfig = require('../webpack.base.config.js');
2019-03-05 05:46:57 +01:00
const CopyWebpackPlugin = require('copy-webpack-plugin');
2019-09-26 17:06:01 +02:00
const { DefinePlugin, ProvidePlugin } = require('webpack');
2020-02-05 04:46:00 +01:00
const SentryWebpackPlugin = require('@sentry/webpack-plugin');
2020-07-08 19:02:18 +02:00
const { insertToHead, buildBasicOgMetadata } = require('./src/html');
2019-03-05 05:46:57 +01:00
const CUSTOM_ROOT = path.resolve(__dirname, '../custom/');
2019-11-07 20:39:22 +01:00
const STATIC_ROOT = path.resolve(__dirname, '../static/');
2019-11-11 16:22:57 +01:00
const UI_ROOT = path.resolve(__dirname, '../ui/');
2019-03-05 05:46:57 +01:00
const DIST_ROOT = path.resolve(__dirname, 'dist/');
2019-11-07 20:39:22 +01:00
const WEB_PLATFORM_ROOT = __dirname;
2020-02-05 04:46:00 +01:00
const isProduction = process.env.NODE_ENV === 'production';
const hasSentryToken = process.env.SENTRY_AUTH_TOKEN !== undefined;
const copyWebpackCommands = [
{
from: `${STATIC_ROOT}/index-web.html`,
to: `${DIST_ROOT}/index.html`,
2020-07-08 19:02:18 +02:00
transform(content, path) {
return insertToHead(content.toString(), buildBasicOgMetadata());
},
},
{
from: `${STATIC_ROOT}/img/favicon.png`,
to: `${DIST_ROOT}/public/favicon.png`,
},
{
from: `${STATIC_ROOT}/img/v2-og.png`,
to: `${DIST_ROOT}/public/v2-og.png`,
},
{
from: `${STATIC_ROOT}/font/`,
to: `${DIST_ROOT}/public/font/`,
},
];
const CUSTOM_OG_PATH = `${CUSTOM_ROOT}/v2-og.png`;
if (fs.existsSync(CUSTOM_OG_PATH)) {
copyWebpackCommands.push({
from: CUSTOM_OG_PATH,
to: `${DIST_ROOT}/public/v2-og.png`,
});
}
2020-02-05 04:46:00 +01:00
let plugins = [
new CopyWebpackPlugin(copyWebpackCommands),
2020-02-05 04:46:00 +01:00
new DefinePlugin({
IS_WEB: JSON.stringify(true),
'process.env.SDK_API_URL': JSON.stringify(process.env.SDK_API_URL || LBRY_WEB_API),
2020-02-05 04:46:00 +01:00
}),
new ProvidePlugin({
__: ['i18n.js', '__'],
}),
];
if (isProduction && hasSentryToken) {
plugins.push(
new SentryWebpackPlugin({
include: './dist',
ignoreFile: '.sentrycliignore',
ignore: ['node_modules', 'webpack.config.js'],
configFile: 'sentry.properties',
})
);
}
2019-03-05 05:46:57 +01:00
const webConfig = {
target: 'web',
entry: {
2019-11-07 20:39:22 +01:00
ui: '../ui/index.jsx',
2019-03-05 05:46:57 +01:00
},
output: {
2019-03-05 18:54:11 +01:00
filename: '[name].js',
2020-02-05 04:46:00 +01:00
path: path.join(__dirname, 'dist/public/'),
publicPath: '/public/',
2019-03-05 05:46:57 +01:00
},
devServer: {
port: WEBPACK_WEB_PORT,
2019-12-13 22:46:28 +01:00
contentBase: path.join(__dirname, 'dist'),
},
2019-03-05 05:46:57 +01:00
module: {
rules: [
{
2019-11-07 20:39:22 +01:00
loader: 'babel-loader',
test: /\.jsx?$/,
options: {
2019-11-21 22:48:19 +01:00
presets: ['@babel/env', '@babel/react', '@babel/flow'],
plugins: ['@babel/plugin-proposal-object-rest-spread', '@babel/plugin-proposal-class-properties'],
2019-11-07 20:39:22 +01:00
},
},
{
loader: 'preprocess-loader',
test: /\.jsx?$/,
exclude: /node_modules/,
options: {
TARGET: 'web',
ppOptions: {
type: 'js',
2019-03-05 05:46:57 +01:00
},
2019-11-07 20:39:22 +01:00
},
2019-03-05 05:46:57 +01:00
},
],
},
resolve: {
2019-11-11 16:22:57 +01:00
modules: [UI_ROOT, __dirname],
2019-03-05 05:46:57 +01:00
alias: {
2020-03-24 21:35:51 +01:00
lbryinc: 'lbryinc/dist/bundle.es.js',
2019-11-07 20:39:22 +01:00
electron: `${WEB_PLATFORM_ROOT}/stubs/electron.js`,
fs: `${WEB_PLATFORM_ROOT}/stubs/fs.js`,
2019-03-05 05:46:57 +01:00
},
},
2020-02-05 04:46:00 +01:00
plugins,
2019-03-05 05:46:57 +01:00
};
module.exports = merge(baseConfig, webConfig);