webpack-contrib / file-loader

File Loader
MIT License
1.86k stars 257 forks source link

Update documentation to reflect Webpack v4 #314

Closed alanyinjs closed 5 years ago

alanyinjs commented 5 years ago

Documentation Is:

Please Explain in Detail...

The doc for file-loader has referred to the style recommended by Webpack 3 in multiple places where instead of using use, and specify loader and options inside the use object, loader and options have been used directly inside rules. screen shot 2018-12-26 at 11 58 59 pm

Your Proposal for Changes

Just an example of how the above could possibly be changed:

module.exports = {
  module: {
    rules: [
      {
        test: /\.(png|jpg|gif)$/,
        use: [
          {
            loader: 'file-loader',
            options: {
              name: '[path][name].[ext]',
            },
          },
        ],
      },
    ],
  },
};
alexander-akait commented 5 years ago

@alanyinjs both examples valid for webpack@3, webpack@4 and webpack@5, you need use property when you want using multiple loaders, like:

module.exports = {
  module: {
    rules: [
      {
        test: /\.(png|jpg|gif)$/,
        use: [
          {
            loader: 'other-loader',
            options: {
              // ...options
            },
          },
          {
            loader: 'file-loader',
            options: {
              name: '[path][name].[ext]',
            },
          },
        ],
      },
    ],
  },
};
alanyinjs commented 5 years ago

@evilebottnawi Thanks Evilbot for the quick reply! I understand the it will still be valid syntax without the use property. However the official docs seem to be recommending using use even for a single loader: https://webpack.js.org/loaders/babel-loader/

alexander-akait commented 5 years ago

@alanyinjs hm, let's update docs