Advertisement
Guest User

webpack react config

a guest
Feb 15th, 2022
118
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 ESLintPlugin = require("eslint-webpack-plugin");
  5.  
  6. let mode = process.env.NODE_ENV
  7. console.log("mode active: " + mode)
  8.  
  9.  
  10. module.exports = {
  11.   mode: mode,
  12.   entry: './src/index.js',
  13.   output: {
  14.     path: path.resolve(__dirname, 'dist'),
  15.     clean: true,
  16.     publicPath: "/",
  17.   },
  18.  
  19.   devtool: 'source-map',
  20.   devServer: {
  21.     static: './dist',
  22.     hot: true,
  23.     historyApiFallback: true,
  24.   },
  25.   target: mode === "development" ? "web" : "browserslist",
  26.  
  27.   plugins: [
  28.     new HtmlWebpackPlugin({
  29.       template: './src/index.html',
  30.       favicon: './src/favicon.png',
  31.      
  32.     }),
  33.     new ESLintPlugin({
  34.       extensions: ["js", "jsx", "ts", "tsx"],
  35.     }),
  36.     new MiniCssExtractPlugin({
  37.       filename: '[name].[id].css',
  38.     }),
  39.   ],
  40.   performance: { hints: false },
  41.   optimization: {
  42.     minimize: true,
  43.     splitChunks: {
  44.       chunks: 'all',
  45.     },
  46.   },
  47.  
  48.   resolve: {
  49.     extensions: [".jsx", ".js", ".sass", ".scss", ".css", ".json", "..."]
  50.   },
  51.  
  52.   module: {
  53.     rules: [
  54.       {
  55.         test: /\.(html)$/,
  56.         use: ['html-loader']
  57.       },
  58.  
  59.       {
  60.         test: /\.(jsx?)$/,
  61.         exclude: /node_modules/,
  62.         use: [
  63.           {
  64.             loader: 'babel-loader',
  65.             options: {
  66.               cacheDirectory: true,
  67.               presets: [
  68.                 '@babel/preset-env',
  69.                 '@babel/preset-react'
  70.               ],
  71.             }
  72.           },
  73.          
  74.         ]
  75.       },
  76.      
  77.       {
  78.         test: /\.(s[ac]ss|css)$/i,
  79.         use: [
  80.           MiniCssExtractPlugin.loader,
  81.           {
  82.             loader: 'css-loader',
  83.             options: {
  84.               importLoaders: 1,
  85.             }
  86.           },
  87.           'postcss-loader',
  88.           'sass-loader',
  89.       ]},
  90.  
  91.       {
  92.         test: /\.(jpe?g|gif|svg|webp)$/i,
  93.         type: mode === 'production' ? 'asset' : 'asset/resource'
  94.       },
  95.       {
  96.         test: /\.(png)$/,
  97.         type: 'asset/resource'
  98.       },
  99.       {
  100.         test: /\.(woff2?|eot|ttf|otf)$/i,
  101.         type: 'asset/resource',
  102.       },
  103.     ]
  104.    
  105.   },
  106.  
  107. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement