V
V
ValeraNakhuy2019-02-10 00:19:17
webpack
ValeraNakhuy, 2019-02-10 00:19:17

How to exclude images and fonts from webpack 4?

Pictures give 2 extra megabytes
Config:
Common

const webpack = require('webpack');
const path = require('path');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;


 module.exports = {
  entry: {
    app: './src/index.js'
  },
  plugins: [
       new CleanWebpackPlugin(['dist']),
       new HtmlWebpackPlugin({
         template: "./index.html"
        }),
    new webpack.HotModuleReplacementPlugin(),
    // new BundleAnalyzerPlugin()
   ],
   output: {
       filename: 'bundle.js',
       path: path.resolve(__dirname, 'dist')
     },

   resolve: {
     extensions: ['*', '.js', '.jsx']
   },
   module: {
     rules: [
       {
         test: /\.(png|jpg|jpeg|gif|svg)$/,
         loader: "url-loader",
       },
       {
         test: /\.(js|jsx)$/,
         exclude: /node_modules/,
         use: ['babel-loader']
       },
       {
         test: /\.scss$/,
         include: __dirname + '/src/sass',
         use: [
           "style-loader",
           "css-loader",
           "sass-loader"
         ]
       },
       {
         test: /\.css$/,
         use: [
           "style-loader",
           "css-loader",
           "url-loader"
         ]
       },
       {
         test: /\.(eot|svg|ttf|woff|woff2)$/,
         use: [
           {
             loader: 'file-loader'
           }
         ]
       }
     ]
   },
 };

product
const merge = require('webpack-merge');
 const common = require('./webpack.common.js');

   module.exports = merge(common, {
     mode: 'production',
     optimization: {
       minimize: true
     }
   });

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question