2022-05-18 00:11:32 +03:00
|
|
|
const path = require('path');
|
|
|
|
|
2022-06-08 16:27:41 +03:00
|
|
|
const webpack = require('webpack');
|
2022-05-18 13:15:33 +03:00
|
|
|
const { merge } = require('webpack-merge');
|
2022-05-17 22:40:23 +03:00
|
|
|
const HtmlWebpackPlugin = require('html-webpack-plugin');
|
|
|
|
const HotModuleReplacementPlugin = require('html-webpack-plugin');
|
|
|
|
const CopyWebpackPlugin = require('copy-webpack-plugin');
|
|
|
|
const { ProvidePlugin } = require('webpack');
|
2022-05-18 13:15:33 +03:00
|
|
|
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
|
|
|
|
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
|
2022-05-17 22:40:23 +03:00
|
|
|
|
2022-05-18 13:15:33 +03:00
|
|
|
const commonConfig = {
|
2022-05-17 15:49:58 +03:00
|
|
|
target: 'web',
|
2022-05-18 00:11:32 +03:00
|
|
|
context: path.resolve(__dirname),
|
2022-05-17 15:49:58 +03:00
|
|
|
stats: {
|
|
|
|
children: false,
|
|
|
|
entrypoints: false,
|
|
|
|
modules: false,
|
|
|
|
},
|
|
|
|
output: {
|
2022-05-18 00:11:32 +03:00
|
|
|
path: path.resolve(__dirname, '.build'),
|
2022-05-17 15:49:58 +03:00
|
|
|
publicPath: '/',
|
|
|
|
},
|
|
|
|
resolve: {
|
|
|
|
alias: {
|
|
|
|
'react-native': 'react-native-web',
|
|
|
|
},
|
|
|
|
extensions: [
|
|
|
|
'.web.jsx',
|
|
|
|
'.web.js',
|
|
|
|
'.wasm',
|
|
|
|
'.mjs',
|
|
|
|
'.jsx',
|
|
|
|
'.js',
|
|
|
|
'.json',
|
|
|
|
],
|
2022-06-08 16:27:41 +03:00
|
|
|
fallback: {
|
2022-08-08 22:24:51 +03:00
|
|
|
url: require.resolve('url'),
|
|
|
|
crypto: require.resolve('crypto-browserify'),
|
|
|
|
stream: require.resolve('stream-browserify'),
|
|
|
|
buffer: require.resolve('buffer'),
|
2022-06-08 16:27:41 +03:00
|
|
|
assert: require.resolve('assert'),
|
|
|
|
fs: false,
|
|
|
|
tls: false,
|
|
|
|
},
|
2022-05-17 15:49:58 +03:00
|
|
|
},
|
2022-05-18 13:15:33 +03:00
|
|
|
module: {
|
|
|
|
rules: [
|
2023-01-05 01:58:12 +03:00
|
|
|
{
|
|
|
|
test: /\.(mjs|jsx|js)$/,
|
|
|
|
resolve: {
|
|
|
|
fullySpecified: false, // disable the behaviour
|
|
|
|
},
|
|
|
|
},
|
2022-05-18 13:15:33 +03:00
|
|
|
{
|
|
|
|
test: /\.html$/,
|
2022-11-08 03:02:06 +03:00
|
|
|
use: {
|
|
|
|
loader: 'html-loader',
|
|
|
|
options: {
|
|
|
|
sources: {
|
|
|
|
list: [
|
|
|
|
{
|
|
|
|
tag: 'img',
|
|
|
|
attribute: 'img-src',
|
|
|
|
type: 'src',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
tag: 'a',
|
|
|
|
attribute: 'href',
|
|
|
|
type: 'src',
|
|
|
|
},
|
|
|
|
],
|
2022-05-18 13:15:33 +03:00
|
|
|
},
|
|
|
|
},
|
2022-11-08 03:02:06 +03:00
|
|
|
},
|
2022-05-18 13:15:33 +03:00
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.(mjs|jsx|js)$/,
|
2022-06-08 16:27:41 +03:00
|
|
|
type: 'javascript/auto',
|
2022-05-18 13:15:33 +03:00
|
|
|
include: [
|
|
|
|
path.resolve(__dirname, 'ui'),
|
|
|
|
path.resolve(__dirname, 'tests/ui'),
|
|
|
|
],
|
|
|
|
use: [
|
|
|
|
{
|
|
|
|
loader: 'babel-loader',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
plugins: [
|
2022-08-08 22:24:51 +03:00
|
|
|
new webpack.ProvidePlugin({
|
|
|
|
Buffer: ['buffer', 'Buffer'],
|
|
|
|
}),
|
2022-06-08 16:27:41 +03:00
|
|
|
new webpack.ProvidePlugin({
|
|
|
|
process: 'process/browser',
|
|
|
|
}),
|
2022-06-01 13:10:23 +03:00
|
|
|
new CopyWebpackPlugin({
|
|
|
|
patterns: ['ui/contribute.json', 'ui/revision.txt', 'ui/robots.txt'],
|
|
|
|
}),
|
2022-05-18 13:15:33 +03:00
|
|
|
new ProvidePlugin({
|
|
|
|
jQuery: 'jquery',
|
|
|
|
'window.jQuery': 'jquery',
|
|
|
|
}),
|
|
|
|
],
|
|
|
|
entry: {
|
|
|
|
index: ['./ui/index'],
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
const developmentConfig = {
|
|
|
|
mode: 'development',
|
|
|
|
|
2022-06-08 16:27:41 +03:00
|
|
|
devtool: 'eval-cheap-module-source-map',
|
2022-05-18 13:15:33 +03:00
|
|
|
|
2022-05-17 15:49:58 +03:00
|
|
|
devServer: {
|
2022-06-07 15:49:40 +03:00
|
|
|
host: '0.0.0.0',
|
2022-05-17 15:49:58 +03:00
|
|
|
port: 5000,
|
|
|
|
hot: true,
|
|
|
|
historyApiFallback: true,
|
2022-06-07 15:49:40 +03:00
|
|
|
open: true,
|
2022-05-17 15:49:58 +03:00
|
|
|
proxy: {
|
|
|
|
'/api': {
|
|
|
|
changeOrigin: true,
|
|
|
|
headers: {
|
|
|
|
referer: 'https://treeherder.mozilla.org/webpack-dev-server',
|
|
|
|
},
|
2022-06-07 11:47:05 +03:00
|
|
|
// Support BACKEND environment variable provided by npm run scripts
|
|
|
|
target: process.env.BACKEND || 'https://treeherder.mozilla.org',
|
2022-05-17 15:49:58 +03:00
|
|
|
onProxyRes: (proxyRes) => {
|
|
|
|
// Strip the cookie `secure` attribute, otherwise production's cookies
|
|
|
|
// will be rejected by the browser when using non-HTTPS localhost:
|
|
|
|
// https://github.com/nodejitsu/node-http-proxy/pull/1166
|
|
|
|
const removeSecure = (str) => str.replace(/; secure/i, '');
|
|
|
|
const cookieHeader = proxyRes.headers['set-cookie'];
|
|
|
|
if (cookieHeader) {
|
|
|
|
proxyRes.headers['set-cookie'] = Array.isArray(cookieHeader)
|
|
|
|
? cookieHeader.map(removeSecure)
|
|
|
|
: removeSecure(cookieHeader);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2022-06-01 13:10:23 +03:00
|
|
|
devMiddleware: {
|
|
|
|
stats: {
|
|
|
|
all: false,
|
|
|
|
errors: true,
|
|
|
|
timings: true,
|
|
|
|
warnings: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
static: {
|
|
|
|
watch: {
|
|
|
|
usePolling: true,
|
|
|
|
interval: 1000,
|
|
|
|
ignored: /node_modules/,
|
|
|
|
},
|
2022-05-17 15:49:58 +03:00
|
|
|
},
|
|
|
|
},
|
2022-05-18 13:15:33 +03:00
|
|
|
|
|
|
|
output: {
|
|
|
|
filename: 'assets/[name].js',
|
|
|
|
},
|
|
|
|
|
|
|
|
optimization: {
|
|
|
|
minimize: false,
|
|
|
|
splitChunks: {
|
|
|
|
chunks: 'all',
|
|
|
|
maxInitialRequests: Infinity,
|
2022-06-08 16:27:41 +03:00
|
|
|
name: false,
|
2022-05-18 13:15:33 +03:00
|
|
|
},
|
|
|
|
runtimeChunk: 'single',
|
|
|
|
},
|
|
|
|
|
2022-05-30 22:56:06 +03:00
|
|
|
plugins: [
|
|
|
|
new HotModuleReplacementPlugin({
|
|
|
|
template: 'ui/index.html',
|
|
|
|
lang: 'en',
|
|
|
|
filename: 'index.html',
|
|
|
|
}),
|
|
|
|
],
|
2022-05-18 13:15:33 +03:00
|
|
|
|
2022-06-01 13:10:23 +03:00
|
|
|
infrastructureLogging: {
|
|
|
|
level: 'warn',
|
|
|
|
},
|
|
|
|
|
2022-05-17 15:49:58 +03:00
|
|
|
module: {
|
|
|
|
rules: [
|
|
|
|
{
|
2022-05-18 13:15:33 +03:00
|
|
|
test: /\.css$/,
|
2022-05-17 15:49:58 +03:00
|
|
|
use: [
|
|
|
|
{
|
2022-05-18 13:15:33 +03:00
|
|
|
loader: 'style-loader',
|
2022-05-17 15:49:58 +03:00
|
|
|
},
|
|
|
|
{
|
2022-05-18 13:15:33 +03:00
|
|
|
loader: 'css-loader',
|
|
|
|
options: {
|
|
|
|
importLoaders: 0,
|
|
|
|
},
|
2022-05-17 15:49:58 +03:00
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.(eot|ttf|woff|woff2)(\?v=\d+\.\d+\.\d+)?$/,
|
2022-06-08 16:27:41 +03:00
|
|
|
type: 'asset/resource',
|
|
|
|
generator: {
|
|
|
|
filename: 'assets/[name].[ext]',
|
|
|
|
},
|
2022-05-17 15:49:58 +03:00
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.(ico|png|jpg|jpeg|gif|svg|webp)(\?v=\d+\.\d+\.\d+)?$/,
|
2022-06-08 16:27:41 +03:00
|
|
|
type: 'asset',
|
|
|
|
generator: {
|
|
|
|
filename: 'assets/[name].[ext]',
|
|
|
|
},
|
2022-05-17 15:49:58 +03:00
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
2022-05-18 13:15:33 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
const productionConfig = {
|
|
|
|
mode: 'production',
|
|
|
|
devtool: 'source-map',
|
|
|
|
|
|
|
|
output: {
|
|
|
|
filename: 'assets/[name].[contenthash:8].js',
|
|
|
|
},
|
|
|
|
|
2022-05-17 15:49:58 +03:00
|
|
|
optimization: {
|
2022-05-18 13:15:33 +03:00
|
|
|
minimize: true,
|
2022-05-17 15:49:58 +03:00
|
|
|
splitChunks: {
|
|
|
|
chunks: 'all',
|
2022-05-18 13:15:33 +03:00
|
|
|
maxInitialRequests: 5,
|
|
|
|
name: false,
|
2023-09-05 14:00:01 +03:00
|
|
|
cacheGroups: {
|
|
|
|
redoc: {
|
|
|
|
test: /[\\/]node_modules[\\/](mobx|redoc|styled-components)[\\/]/,
|
|
|
|
name: 'redoc',
|
|
|
|
chunks: 'all',
|
|
|
|
},
|
|
|
|
},
|
2022-05-17 15:49:58 +03:00
|
|
|
},
|
|
|
|
runtimeChunk: 'single',
|
|
|
|
},
|
2022-05-18 13:15:33 +03:00
|
|
|
|
|
|
|
performance: {
|
|
|
|
hints: 'error',
|
2024-07-04 15:56:23 +03:00
|
|
|
maxAssetSize: 2300000,
|
2023-09-05 14:00:01 +03:00
|
|
|
maxEntrypointSize: 3000000,
|
2022-05-18 13:15:33 +03:00
|
|
|
},
|
|
|
|
|
2022-05-17 15:49:58 +03:00
|
|
|
plugins: [
|
2022-05-30 22:56:06 +03:00
|
|
|
new HtmlWebpackPlugin({
|
|
|
|
template: 'ui/index.html',
|
|
|
|
appMountId: 'root',
|
|
|
|
lang: 'en',
|
|
|
|
meta: false,
|
|
|
|
filename: 'index.html',
|
2023-09-05 14:00:01 +03:00
|
|
|
chunks: ['index', 'redoc'],
|
2022-05-30 22:56:06 +03:00
|
|
|
}),
|
2022-05-18 13:15:33 +03:00
|
|
|
new MiniCssExtractPlugin({
|
|
|
|
filename: 'assets/[name].[contenthash:8].css',
|
2022-05-17 15:49:58 +03:00
|
|
|
}),
|
2022-05-18 13:15:33 +03:00
|
|
|
new CleanWebpackPlugin({
|
|
|
|
verbose: false,
|
2022-05-17 15:49:58 +03:00
|
|
|
}),
|
|
|
|
],
|
2022-05-18 13:15:33 +03:00
|
|
|
|
|
|
|
module: {
|
|
|
|
rules: [
|
|
|
|
{
|
|
|
|
test: /\.css$/,
|
|
|
|
use: [
|
2022-06-01 13:10:23 +03:00
|
|
|
MiniCssExtractPlugin.loader,
|
2022-05-18 13:15:33 +03:00
|
|
|
{
|
|
|
|
loader: 'css-loader',
|
|
|
|
options: {
|
|
|
|
importLoaders: 0,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.(eot|ttf|woff|woff2)(\?v=\d+\.\d+\.\d+)?$/,
|
2022-06-08 16:27:41 +03:00
|
|
|
type: 'asset/resource',
|
|
|
|
generator: {
|
|
|
|
filename: 'assets/[name].[hash:8].[ext]',
|
|
|
|
},
|
2022-05-18 13:15:33 +03:00
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.(ico|png|jpg|jpeg|gif|svg|webp)(\?v=\d+\.\d+\.\d+)?$/,
|
2022-06-08 16:27:41 +03:00
|
|
|
type: 'asset',
|
|
|
|
generator: {
|
|
|
|
filename: 'assets/[name].[hash:8].[ext]',
|
|
|
|
},
|
2022-05-18 13:15:33 +03:00
|
|
|
},
|
|
|
|
],
|
2022-05-17 15:49:58 +03:00
|
|
|
},
|
|
|
|
};
|
2022-05-18 13:15:33 +03:00
|
|
|
|
|
|
|
module.exports = (env, args) => {
|
|
|
|
switch (args.mode) {
|
|
|
|
case 'development':
|
|
|
|
return merge(commonConfig, developmentConfig);
|
|
|
|
case 'production':
|
|
|
|
return merge(commonConfig, productionConfig);
|
|
|
|
default:
|
|
|
|
throw new Error('No matching configuration was found!');
|
|
|
|
}
|
|
|
|
};
|