Advertisement
ahmadandika

Untitled

Sep 17th, 2019
259
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const path = require('path');
  2. const HtmlWebpackPlugin = require('html-webpack-plugin');
  3. const MiniCssExtractPlugin = require('mini-css-extract-plugin');
  4. const LoadablePlugin = require('react-loadable/webpack').ReactLoadablePlugin;
  5. const webpack = require('webpack');
  6. const Dotenv = require('dotenv-webpack');
  7. const BrotliGzipPlugin = require('brotli-gzip-webpack-plugin');
  8.  
  9. module.exports = {
  10.   entry: './src/index.js',
  11.   output: {
  12.     path: path.resolve('dist'),
  13.     filename: '[name].[contenthash].js',
  14.     chunkFilename: '[name].[contenthash].bundle.js',
  15.     publicPath: '/'
  16.   },
  17.   devtool: 'source-map',
  18.   resolveLoader: {
  19.     moduleExtensions: ['-loader']
  20.   },
  21.   resolve: {
  22.     extensions: ['.js', '.jsx']
  23.   },
  24.   module: {
  25.     rules: [
  26.       {
  27.         test: [/\.jsx$/, /\.js$/],
  28.         exclude: /node_modules/,
  29.         loader: 'babel-loader',
  30.         query: {
  31.           presets: ['es2015', 'react', 'stage-0', 'stage-2']
  32.         }
  33.       },
  34.       {
  35.         test: /\.html$/,
  36.         exclude: /node_modules/,
  37.         loader: 'html-loader'
  38.       },
  39.       {
  40.         test: /\.(eot|woff|woff2|ttf|svg|png|jpg|gif)$/,
  41.         use: [
  42.           {
  43.             loader: 'file-loader'
  44.           }
  45.         ]
  46.       },
  47.       {
  48.         test: /\.css$/,
  49.         exclude: /node_modules/,
  50.         use: ['style-loader', 'css-loader']
  51.       },
  52.       {
  53.         test: /\.scss$/,
  54.         use: [
  55.           {
  56.             loader: 'style-loader'
  57.           },
  58.           {
  59.             loader: 'css-loader',
  60.             options: {
  61.               sourceMap: true
  62.             }
  63.           },
  64.           {
  65.             loader: 'sass-loader',
  66.             options: {
  67.               sourceMap: true
  68.             }
  69.           }
  70.         ]
  71.       },
  72.       {
  73.         test: /\.s?[ac]ss$/,
  74.         use: [
  75.           MiniCssExtractPlugin.loader,
  76.           { loader: 'css-loader', options: { url: false, sourceMap: true } },
  77.           { loader: 'sass-loader', options: { sourceMap: true } }
  78.         ]
  79.       }
  80.     ]
  81.   },
  82.   devServer: {
  83.     historyApiFallback: true,
  84.     port: 8088
  85.   },
  86.   optimization: {
  87.     splitChunks: {
  88.       cacheGroups: {
  89.         commons: {
  90.           test: /[\\/]node_modules[\\/]/,
  91.           name: 'vendor',
  92.           chunks: 'all'
  93.         }
  94.       }
  95.     }
  96.   },
  97.   plugins: [
  98.     new HtmlWebpackPlugin({
  99.       template: './public/index.html',
  100.       filename: 'index.html'
  101.     }),
  102.     new MiniCssExtractPlugin({
  103.       filename: 'style.css'
  104.     }),
  105.     new Dotenv({
  106.       path: './.env' // Path to .env file (this is the default)
  107.     }),
  108.     new webpack.DefinePlugin({
  109.       'process.env.BROWSER': true,
  110.       'process.env.URL_API': JSON.stringify(process.env.URL_API)
  111.     })
  112.     // new LoadablePlugin({
  113.     //   filename: './react-loadable.json'
  114.     // })
  115.     // new BrotliGzipPlugin({
  116.     //   asset: '[path].br[query]',
  117.     //   algorithm: 'brotli',
  118.     //   test: /\.(js|css|html|svg)$/,
  119.     //   threshold: 10240,
  120.     //   minRatio: 0.5,
  121.     //   quality: 11
  122.     // }),
  123.     // new BrotliGzipPlugin({
  124.     //   asset: '[path].gz[query]',
  125.     //   algorithm: 'gzip',
  126.     //   test: /\.(js|css|html|svg)$/,
  127.     //   threshold: 10240,
  128.     //   minRatio: 0.5
  129.     // })
  130.   ]
  131. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement