minesweeper icon indicating copy to clipboard operation
minesweeper copied to clipboard

Webpack 5 asset modules

Open nickovchinnikov opened this issue 2 years ago • 0 comments

Igal Kleiner:

Note about Webpack 5

As of Webpack 5, there's no need to install url-loader. Webpack 5 ships with Asset Modules, which replace url-loader, raw-loader and file-loader by adding 4 new module types - asset/resource, asset/inline, asset/source and asset. In my case, I wanted to copy all assets to the assets folder, so this was my configuration:

module.exports = {
      output: {
        // ...other output configurations
        assetModuleFilename: 'assets/[hash][ext][query]',
      },
      module: {
        rules: [
          // ...other rules,
          {
            test: /\.(png|jpg|gif|svg)$/i,
            type: 'asset/resource',
          },
        ],
      },
    }

And, of course, you can test it for .svg only:

test: /\.svg/,

Perhaps someone will find it helpful!

Cheers!

nickovchinnikov avatar Sep 01 '22 08:09 nickovchinnikov