Skip to content

Instantly share code, notes, and snippets.

View BiosBoy's full-sized avatar
⛰️
The bigger you know - the less you scared of.

Sviat Kuzhelev BiosBoy

⛰️
The bigger you know - the less you scared of.
View GitHub Profile
@BiosBoy
BiosBoy / Quick and dirty Debounce and Throttle decorators for React Components.ts
Last active November 6, 2018 15:16
Quick and dirty Debounce and Throttle decorators for React Components
class App extends PureComponent<IProps, any> {
constructor(props: IProps) {
super(props)
this.state = {
isThrottled: false,
savedArgs: null,
timer: null
}
}
// ------------------------------------
// RULES INJECTION!
// ------------------------------------
const rules = [
// PRELOAD CHECKING
{
enforce: 'pre',
test: /\.(js|jsx)?$/,
exclude: /(node_modules|bower_components)/,
loader: 'eslint-loader',
// import global vars for a whole app
require('./globals');
const path = require('path');
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin');
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
// ------------------------------------
// BUNDLES OPTIMIZATION
// ------------------------------------
const optimization = {
optimization: {
splitChunks: {
chunks: 'all',
minChunks: 2
},
minimizer: [
// ------------------------------------
// STAGE PLUGINS INJECTION! [DEVELOPMENT, PRODUCTION, TESTING]
// ------------------------------------
const stagePlugins = {
test: [new BundleAnalyzerPlugin()],
development: [
new HtmlWebpackPlugin({
template: path.resolve('./src/index.html'),
filename: 'index.html',
inject: 'body',
const createConfig = () => {
debug('Creating configuration.');
debug(`Enabling devtools for '${__NODE_ENV__} Mode!'`);
const webpackConfig = {
mode: __DEV__ ? 'development' : 'production',
name: 'client',
target: 'web',
devtool: stageConfig[__NODE_ENV__].devtool,
// import global vars for a whole app
require('../globals');
const path = require('path');
const browserSync = require('browser-sync');
const historyApiFallback = require('connect-history-api-fallback');
const webpack = require('webpack');
const webpackDevMiddleware = require('webpack-dev-middleware');
const webpackHotMiddleware = require('webpack-hot-middleware');
const webpackConfig = require('../webpack.config.js');
// ========================================================
// WEBPACK MIDDLEWARE CONFIGURATION
// ========================================================
const devMiddlewareOptions = {
publicPath: webpackConfig.output.publicPath,
hot: true,
headers: { 'Access-Control-Allow-Origin': '*' }
};
// ========================================================
// Server Configuration
// ========================================================
browserSync({
open: false,
ghostMode: {
clicks: false,
forms: false,
scroll: true
},
// import global vars for a whole app
require('../globals');
const debug = require('debug')('app:build:webpack-compiler');
const webpack = require('webpack');
const webpackConfig = require('../webpack.config.js');