misc_pterodactyl-panel/webpack.config.js

125 lines
4 KiB
JavaScript
Raw Normal View History

2018-06-04 01:03:46 +00:00
const path = require('path');
const webpack = require('webpack');
2018-06-04 02:35:50 +00:00
const AssetsManifestPlugin = require('webpack-assets-manifest');
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
const TerserPlugin = require('terser-webpack-plugin');
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
2018-12-16 22:30:21 +00:00
2019-02-03 01:33:12 +00:00
const isProduction = process.env.NODE_ENV === 'production';
const modes = Object.keys(require('./resources/scripts/modes'));
2018-06-04 01:03:46 +00:00
module.exports = {
cache: true,
2019-02-03 02:49:51 +00:00
target: 'web',
mode: process.env.NODE_ENV,
devtool: isProduction ? false : (process.env.DEVTOOL || 'eval-source-map'),
2018-06-04 00:40:35 +00:00
performance: {
hints: false,
},
entry: ['react-hot-loader/patch', './resources/scripts/index.tsx'],
output: {
2020-07-05 03:54:33 +00:00
path: path.join(__dirname, '/public/assets'),
filename: isProduction ? 'bundle.[chunkhash:8].js' : 'bundle.[hash:8].js',
chunkFilename: isProduction ? '[name].[chunkhash:8].js' : '[name].[hash:8].js',
2019-12-22 22:33:08 +00:00
publicPath: (process.env.PUBLIC_PATH || '') + '/assets/',
2018-06-04 01:46:27 +00:00
crossOriginLoading: 'anonymous',
},
module: {
rules: [
{
2020-07-05 03:54:33 +00:00
test: /\.tsx?$/,
2018-12-16 22:30:21 +00:00
exclude: /node_modules/,
loader: 'babel-loader',
options: {
cacheDirectory: !isProduction,
},
},
{
2018-06-04 01:46:27 +00:00
test: /\.css$/,
use: [ 'style-loader', 'css-loader' ],
2018-12-16 22:30:21 +00:00
},
{
2020-07-05 03:54:33 +00:00
test: /\.(png|jp(e?)g|gif)$/,
2018-12-16 22:30:21 +00:00
loader: 'file-loader',
options: {
2020-07-05 03:54:33 +00:00
name: 'images/[name].[hash:8].[ext]',
2018-12-16 22:30:21 +00:00
},
},
{
test: /\.svg$/,
loader: 'svg-url-loader',
2020-07-05 03:54:33 +00:00
},
{
test: /\.js$/,
enforce: 'pre',
loader: 'source-map-loader',
}
2018-12-16 22:30:21 +00:00
],
},
2020-07-05 03:54:33 +00:00
stats: {
// Ignore warnings emitted by "source-map-loader" when trying to parse source maps from
// JS plugins we use, namely brace editor.
warningsFilter: [/Failed to parse source map/],
},
resolve: {
extensions: ['.ts', '.tsx', '.js', '.json'],
alias: {
2020-07-05 03:54:33 +00:00
'@': path.join(__dirname, '/resources/scripts'),
},
symlinks: false,
},
2020-07-05 04:57:35 +00:00
externals: {
// Mark moment as an external to exclude it from the Chart.js build since we don't need to use
// it for anything.
moment: 'moment',
},
plugins: [
new webpack.ContextReplacementPlugin(/brace[/\\](mode|worker)/, new RegExp(`^\.\/(${modes.join('|')})$`)),
new AssetsManifestPlugin({ writeToDisk: true, publicPath: true, integrity: true, integrityHashes: ['sha384'] }),
2020-07-12 17:43:37 +00:00
new ForkTsCheckerWebpackPlugin(isProduction ? {} : {
eslint: {
2020-07-05 03:54:33 +00:00
files: `${path.join(__dirname, '/resources/scripts')}/**/*.{ts,tsx}`,
},
2020-07-12 17:43:37 +00:00
}),
process.env.ANALYZE_BUNDLE ? new BundleAnalyzerPlugin({
analyzerHost: '0.0.0.0',
analyzerPort: 8081,
}) : null
].filter(p => p),
2019-02-03 01:33:12 +00:00
optimization: {
usedExports: true,
sideEffects: false,
runtimeChunk: false,
removeEmptyChunks: true,
minimize: isProduction,
minimizer: [
new TerserPlugin({
2019-02-03 01:33:12 +00:00
cache: true,
parallel: true,
extractComments: false,
terserOptions: {
mangle: true,
2019-02-03 01:33:12 +00:00
output: {
comments: false,
},
},
}),
],
},
watchOptions: {
poll: 1000,
ignored: /node_modules/,
},
2019-02-03 01:33:12 +00:00
devServer: {
compress: true,
2020-07-05 03:54:33 +00:00
contentBase: path.join(__dirname, '/public'),
2019-12-22 22:33:08 +00:00
publicPath: (process.env.PUBLIC_PATH || '') + '/assets/',
2019-02-03 01:33:12 +00:00
allowedHosts: [
'.pterodactyl.test',
],
headers: {
'Access-Control-Allow-Origin': '*',
2018-12-16 22:30:21 +00:00
},
},
};