Pterodactyl-Panel/webpack.config.js

110 lines
3.3 KiB
JavaScript
Raw Normal View History

2018-06-04 03:03:46 +02:00
const path = require('path');
2018-06-04 04:35:50 +02: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 23:30:21 +01:00
2019-02-03 02:33:12 +01:00
const isProduction = process.env.NODE_ENV === 'production';
2018-06-04 03:03:46 +02:00
module.exports = {
cache: true,
2019-02-03 03:49:51 +01:00
target: 'web',
mode: process.env.NODE_ENV,
context: __dirname,
devtool: isProduction ? false : (process.env.DEVTOOL || 'eval-source-map'),
2018-06-04 02:40:35 +02:00
performance: {
hints: false,
},
entry: ['react-hot-loader/patch', './resources/scripts/index.tsx'],
output: {
path: path.resolve(__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 23:33:08 +01:00
publicPath: (process.env.PUBLIC_PATH || '') + '/assets/',
2018-06-04 03:46:27 +02:00
crossOriginLoading: 'anonymous',
},
module: {
rules: [
{
test: /\.ts(x?)$/,
2018-12-16 23:30:21 +01:00
exclude: /node_modules/,
loader: 'babel-loader',
options: {
cacheDirectory: !isProduction,
},
},
{
2018-06-04 03:46:27 +02:00
test: /\.css$/,
use: [ 'style-loader', 'css-loader' ],
2018-12-16 23:30:21 +01:00
},
{
test: /\.(png|jpe?g|gif)$/,
2018-12-16 23:30:21 +01:00
loader: 'file-loader',
options: {
name: 'images/[name].[hash].[ext]',
2018-12-16 23:30:21 +01:00
},
},
{
test: /\.svg$/,
loader: 'svg-url-loader',
}
// {
// enforce: 'pre',
// test: /\.js$/,
// loader: 'source-map-loader',
// },
2018-12-16 23:30:21 +01:00
],
},
resolve: {
extensions: ['.ts', '.tsx', '.js', '.json'],
alias: {
'@': path.resolve(__dirname, 'resources/scripts'),
},
symlinks: false,
},
plugins: [
new AssetsManifestPlugin({ writeToDisk: true, publicPath: true, integrity: true, integrityHashes: ['sha384'] }),
!isProduction ? new ForkTsCheckerWebpackPlugin({
eslint: {
files: './resources/scripts/**/*.{ts,tsx}',
},
}) : null,
process.env.ANALYZE_BUNDLE ? new BundleAnalyzerPlugin() : null
].filter(p => p),
2019-02-03 02:33:12 +01:00
optimization: {
usedExports: true,
sideEffects: false,
runtimeChunk: false,
removeEmptyChunks: true,
minimize: isProduction,
minimizer: [
new TerserPlugin({
2019-02-03 02:33:12 +01:00
cache: true,
parallel: true,
extractComments: false,
terserOptions: {
mangle: true,
2019-02-03 02:33:12 +01:00
output: {
comments: false,
},
},
}),
],
},
watchOptions: {
poll: 1000,
ignored: /node_modules/,
},
2019-02-03 02:33:12 +01:00
devServer: {
compress: true,
contentBase: 'public',
2019-12-22 23:33:08 +01:00
publicPath: (process.env.PUBLIC_PATH || '') + '/assets/',
2019-02-03 02:33:12 +01:00
allowedHosts: [
'.pterodactyl.test',
],
headers: {
'Access-Control-Allow-Origin': '*',
2018-12-16 23:30:21 +01:00
},
},
};