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