2019-06-29 07:52:57 +02:00
|
|
|
/* eslint-disable @typescript-eslint/no-var-requires */
|
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');
|
2019-02-10 04:43:11 +01:00
|
|
|
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
|
2019-06-10 02:29:10 +02:00
|
|
|
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 = [
|
2020-07-03 22:55:33 +02:00
|
|
|
// new MiniCssExtractPlugin({ filename: isProduction ? 'bundle.[chunkhash:8].css' : 'bundle.[hash:8].css' }),
|
2018-06-04 05:34:30 +02:00
|
|
|
new AssetsManifestPlugin({
|
|
|
|
writeToDisk: true,
|
|
|
|
publicPath: true,
|
|
|
|
integrity: true,
|
|
|
|
integrityHashes: ['sha384'],
|
|
|
|
}),
|
|
|
|
];
|
|
|
|
|
2019-02-03 02:33:12 +01:00
|
|
|
if (isProduction) {
|
2020-07-03 22:55:33 +02:00
|
|
|
// plugins = plugins.concat([
|
|
|
|
// new PurgeCssPlugin({
|
|
|
|
// paths: glob.sync([
|
|
|
|
// path.join(__dirname, 'resources/scripts/**/*.tsx'),
|
|
|
|
// path.join(__dirname, 'resources/views/templates/**/*.blade.php'),
|
|
|
|
// ]),
|
|
|
|
// whitelistPatterns: [/^xterm/],
|
|
|
|
// extractors: [
|
|
|
|
// {
|
|
|
|
// extractor: class {
|
|
|
|
// static extract (content) {
|
|
|
|
// return content.match(/[A-Za-z0-9-_:\\/]+/g) || [];
|
|
|
|
// }
|
|
|
|
// },
|
|
|
|
// extensions: ['html', 'ts', 'tsx', 'js', 'php'],
|
|
|
|
// },
|
|
|
|
// ],
|
|
|
|
// }),
|
|
|
|
// ]);
|
2019-12-16 03:50:35 +01:00
|
|
|
} else {
|
|
|
|
plugins.concat([new ForkTsCheckerWebpackPlugin()]);
|
2019-02-03 02:33:12 +01:00
|
|
|
}
|
|
|
|
|
2018-03-31 06:58:38 +02:00
|
|
|
module.exports = {
|
2019-06-10 02:29:10 +02:00
|
|
|
cache: true,
|
2019-02-03 03:49:51 +01:00
|
|
|
target: 'web',
|
2018-06-04 05:34:30 +02:00
|
|
|
mode: process.env.NODE_ENV,
|
2019-12-22 09:16:13 +01:00
|
|
|
devtool: isProduction ? false : process.env.DEVTOOL || '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/scripts/index.tsx',
|
|
|
|
],
|
2018-03-31 06:58:38 +02:00
|
|
|
output: {
|
2018-06-07 06:44:52 +02:00
|
|
|
path: path.resolve(__dirname, 'public/assets'),
|
2019-02-03 03:25:33 +01:00
|
|
|
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',
|
2018-03-31 06:58:38 +02:00
|
|
|
},
|
|
|
|
module: {
|
|
|
|
rules: [
|
2019-02-03 03:25:33 +01:00
|
|
|
{
|
2019-06-10 02:29:10 +02:00
|
|
|
test: /\.tsx?$/,
|
2018-12-16 23:30:21 +01:00
|
|
|
exclude: /node_modules/,
|
2020-07-03 22:55:33 +02:00
|
|
|
loader: 'babel-loader',
|
|
|
|
options: {
|
|
|
|
cacheDirectory: !isProduction,
|
|
|
|
},
|
2018-03-31 06:58:38 +02:00
|
|
|
},
|
2018-05-28 23:16:03 +02:00
|
|
|
{
|
2018-06-04 03:46:27 +02:00
|
|
|
test: /\.css$/,
|
2020-07-03 22:55:33 +02:00
|
|
|
// include: [
|
|
|
|
// path.resolve(__dirname, 'resources'),
|
|
|
|
// ],
|
2019-06-10 02:29:10 +02:00
|
|
|
use: [
|
2020-07-03 22:55:33 +02:00
|
|
|
{ loader: 'style-loader' },
|
|
|
|
{ loader: 'css-loader' },
|
2019-06-10 02:29:10 +02:00
|
|
|
{ loader: 'resolve-url-loader' },
|
|
|
|
],
|
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
|
|
|
},
|
|
|
|
},
|
2020-07-03 22:55:33 +02:00
|
|
|
{
|
|
|
|
enforce: 'pre',
|
|
|
|
test: /\.js$/,
|
|
|
|
loader: 'source-map-loader',
|
|
|
|
}
|
2018-12-16 23:30:21 +01:00
|
|
|
],
|
2018-03-31 06:58:38 +02:00
|
|
|
},
|
|
|
|
resolve: {
|
2019-06-10 02:29:10 +02:00
|
|
|
extensions: ['.ts', '.tsx', '.js', '.json'],
|
2018-03-31 06:58:38 +02:00
|
|
|
alias: {
|
2019-06-10 02:29:10 +02:00
|
|
|
'@': path.join(__dirname, 'resources/scripts'),
|
2018-03-31 06:58:38 +02:00
|
|
|
},
|
2018-06-04 05:34:30 +02:00
|
|
|
symlinks: false,
|
2018-03-31 06:58:38 +02:00
|
|
|
},
|
2019-02-03 02:33:12 +01:00
|
|
|
plugins: plugins,
|
|
|
|
optimization: {
|
2019-07-17 06:43:11 +02:00
|
|
|
minimize: isProduction,
|
2019-06-10 02:29:10 +02:00
|
|
|
minimizer: [
|
|
|
|
new TerserPlugin({
|
2019-02-03 02:33:12 +01:00
|
|
|
cache: true,
|
|
|
|
parallel: true,
|
2019-06-10 02:29:10 +02:00
|
|
|
terserOptions: {
|
|
|
|
safari10: true,
|
|
|
|
mangle: true,
|
2019-02-03 02:33:12 +01:00
|
|
|
output: {
|
|
|
|
comments: false,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
],
|
|
|
|
},
|
2019-09-18 06:05:20 +02:00
|
|
|
watchOptions: {
|
2020-03-23 02:15:38 +01:00
|
|
|
poll: 1000,
|
2019-09-18 06:05:20 +02:00
|
|
|
ignored: /node_modules/,
|
|
|
|
},
|
2019-02-03 02:33:12 +01:00
|
|
|
devServer: {
|
|
|
|
contentBase: path.join(__dirname, '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
|
|
|
},
|
|
|
|
},
|
2018-03-31 06:58:38 +02:00
|
|
|
};
|