Cleanup unused code and simplify webpack

This commit is contained in:
Dane Everitt 2020-07-04 18:19:46 -07:00
parent 43fbefbdb6
commit 922383e232
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
15 changed files with 135 additions and 855 deletions

View file

@ -1,64 +1,23 @@
/* eslint-disable @typescript-eslint/no-var-requires */
const path = require('path');
const tailwind = require('tailwindcss');
const glob = require('glob-all');
const AssetsManifestPlugin = require('webpack-assets-manifest');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const PurgeCssPlugin = require('purgecss-webpack-plugin');
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
const TerserPlugin = require('terser-webpack-plugin');
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
const isProduction = process.env.NODE_ENV === 'production';
let plugins = [
// new MiniCssExtractPlugin({ filename: isProduction ? 'bundle.[chunkhash:8].css' : 'bundle.[hash:8].css' }),
new AssetsManifestPlugin({
writeToDisk: true,
publicPath: true,
integrity: true,
integrityHashes: ['sha384'],
}),
];
if (isProduction) {
// 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'],
// },
// ],
// }),
// ]);
} else {
plugins.concat([new ForkTsCheckerWebpackPlugin()]);
}
module.exports = {
cache: true,
target: 'web',
mode: process.env.NODE_ENV,
devtool: isProduction ? false : process.env.DEVTOOL || 'source-map',
context: __dirname,
devtool: isProduction ? false : (process.env.DEVTOOL || 'eval-source-map'),
performance: {
hints: false,
},
entry: [
'react-hot-loader/patch',
'./resources/scripts/index.tsx',
],
entry: ['react-hot-loader/patch', './resources/scripts/index.tsx'],
output: {
path: path.resolve(__dirname, 'public/assets'),
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: (process.env.PUBLIC_PATH || '') + '/assets/',
@ -67,7 +26,7 @@ module.exports = {
module: {
rules: [
{
test: /\.tsx?$/,
test: /\.ts(x?)$/,
exclude: /node_modules/,
loader: 'babel-loader',
options: {
@ -76,45 +35,54 @@ module.exports = {
},
{
test: /\.css$/,
// include: [
// path.resolve(__dirname, 'resources'),
// ],
use: [
{ loader: 'style-loader' },
{ loader: 'css-loader' },
{ loader: 'resolve-url-loader' },
],
use: [ 'style-loader', 'css-loader' ],
},
{
test: /\.(png|jpg|gif|svg)$/,
test: /\.(png|jpe?g|gif)$/,
loader: 'file-loader',
options: {
name: '[name].[ext]?[hash:8]',
name: 'images/[name].[hash].[ext]',
},
},
{
enforce: 'pre',
test: /\.js$/,
loader: 'source-map-loader',
test: /\.svg$/,
loader: 'svg-url-loader',
}
// {
// enforce: 'pre',
// test: /\.js$/,
// loader: 'source-map-loader',
// },
],
},
resolve: {
extensions: ['.ts', '.tsx', '.js', '.json'],
alias: {
'@': path.join(__dirname, 'resources/scripts'),
'@': path.resolve(__dirname, 'resources/scripts'),
},
symlinks: false,
},
plugins: plugins,
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),
optimization: {
usedExports: true,
sideEffects: false,
runtimeChunk: false,
removeEmptyChunks: true,
minimize: isProduction,
minimizer: [
new TerserPlugin({
cache: true,
parallel: true,
extractComments: false,
terserOptions: {
safari10: true,
mangle: true,
output: {
comments: false,
@ -128,7 +96,8 @@ module.exports = {
ignored: /node_modules/,
},
devServer: {
contentBase: path.join(__dirname, 'public'),
compress: true,
contentBase: 'public',
publicPath: (process.env.PUBLIC_PATH || '') + '/assets/',
allowedHosts: [
'.pterodactyl.test',