Pterodactyl-Panel/webpack.config.js

180 lines
5.8 KiB
JavaScript
Raw Normal View History

2019-06-29 07:52:57 +02:00
/* eslint-disable @typescript-eslint/no-var-requires */
const _ = require('lodash');
2018-06-04 03:03:46 +02:00
const path = require('path');
2018-06-04 04:50:58 +02:00
const tailwind = require('tailwindcss');
const glob = require('glob-all');
2018-06-04 04:35:50 +02:00
const AssetsManifestPlugin = require('webpack-assets-manifest');
2019-02-03 02:33:12 +01:00
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
2018-06-04 04:50:58 +02:00
const PurgeCssPlugin = require('purgecss-webpack-plugin');
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
const TerserPlugin = require('terser-webpack-plugin');
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
2019-02-03 02:33:12 +01:00
let plugins = [
new MiniCssExtractPlugin({ filename: isProduction ? 'bundle.[chunkhash:8].css' : 'bundle.[hash:8].css' }),
new AssetsManifestPlugin({
writeToDisk: true,
publicPath: true,
integrity: true,
integrityHashes: ['sha384'],
}),
];
2019-02-03 02:33:12 +01:00
if (isProduction) {
plugins = plugins.concat([
new PurgeCssPlugin({
paths: glob.sync([
path.join(__dirname, 'resources/scripts/**/*.tsx'),
path.join(__dirname, 'resources/views/templates/**/*.blade.php'),
2019-02-03 02:33:12 +01:00
]),
whitelistPatterns: [/^xterm/],
2019-02-03 02:33:12 +01:00
extractors: [
{
extractor: class {
static extract (content) {
return content.match(/[A-z0-9-:\/]+/g) || [];
}
},
extensions: ['html', 'ts', 'tsx', 'js', 'php'],
2019-02-03 02:33:12 +01:00
},
],
}),
]);
2019-12-16 03:50:35 +01:00
} else {
plugins.concat([new ForkTsCheckerWebpackPlugin()]);
2019-02-03 02:33:12 +01:00
}
module.exports = {
cache: true,
2019-02-03 03:49:51 +01:00
target: 'web',
mode: process.env.NODE_ENV,
devtool: isProduction ? false : 'eval-source-map',
2018-06-04 02:40:35 +02:00
performance: {
hints: false,
},
2019-12-07 21:12:33 +01:00
entry: [
'react-hot-loader/patch',
'./resources/styles/main.css',
'./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',
publicPath: _.get(process.env, 'PUBLIC_PATH', '') + '/assets/',
2018-06-04 03:46:27 +02:00
crossOriginLoading: 'anonymous',
},
module: {
rules: [
{
test: /\.tsx?$/,
2018-12-16 23:30:21 +01:00
exclude: /node_modules/,
use: [
{
loader: 'babel-loader',
options: {
cacheDirectory: !isProduction,
presets: [
'@babel/typescript',
'@babel/env',
'@babel/react',
],
plugins: [
'tailwind-components',
'react-hot-loader/babel',
'@babel/transform-runtime',
'@babel/proposal-class-properties',
'@babel/proposal-object-rest-spread',
'@babel/syntax-dynamic-import',
],
},
},
],
},
{
2018-06-04 03:46:27 +02:00
test: /\.css$/,
include: [
2018-06-04 04:35:50 +02:00
path.resolve(__dirname, 'resources'),
2018-06-04 03:46:27 +02:00
],
use: [
{
loader: MiniCssExtractPlugin.loader,
options: {
hmr: !isProduction,
},
},
{
loader: 'css-loader',
options: {
sourceMap: !isProduction,
importLoaders: 1,
},
},
{ loader: 'resolve-url-loader' },
{
loader: 'postcss-loader',
options: {
ident: 'postcss',
sourceMap: true,
plugins: [
require('postcss-import'),
tailwind('./tailwind.js'),
require('postcss-preset-env')({
stage: 2,
}),
require('precss'),
].concat(isProduction ? require('cssnano') : []),
},
},
],
2018-12-16 23:30:21 +01:00
},
{
test: /\.(png|jpg|gif|svg)$/,
loader: 'file-loader',
options: {
2019-02-03 02:33:12 +01:00
name: '[name].[ext]?[hash:8]',
2018-12-16 23:30:21 +01:00
},
},
],
},
resolve: {
extensions: ['.ts', '.tsx', '.js', '.json'],
alias: {
'@': path.join(__dirname, 'resources/scripts'),
},
symlinks: false,
},
2019-02-03 02:33:12 +01:00
plugins: plugins,
optimization: {
minimize: isProduction,
minimizer: [
new TerserPlugin({
2019-02-03 02:33:12 +01:00
cache: true,
parallel: true,
terserOptions: {
safari10: true,
mangle: true,
2019-02-03 02:33:12 +01:00
output: {
comments: false,
},
},
}),
],
},
watchOptions: {
ignored: /node_modules/,
},
2019-02-03 02:33:12 +01:00
devServer: {
contentBase: path.join(__dirname, 'public'),
2019-02-03 03:49:51 +01:00
publicPath: _.get(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
},
},
};