Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to ignore a file type with Webpack?

Tags:

webpack

In creating my art for my website, I have some intermediate files that I want to keep in my "media" folder.

But then webpack starts complaining that it does not know what to do with those files.

Is there an easy way to say, don't worry about any files with the .pdn extension?

I tried these options in my webpack.config.js, and it did not help:

  1. { test: /\.pdn?$/, loader: 'raw', exclude: /.*/}
  2. { test: /\.pdn?$/, exclude: /.*/}
like image 606
Vaccano Avatar asked Jun 06 '16 21:06

Vaccano


People also ask

What is exclude in webpack?

Actually, those 'include' and 'exclude' properties are telling the loaders whether to include/exclude the files described (such as the contents of node_modules ), not webpack itself.

What is Ignoreplugin?

Prevent generation of modules for import or require calls matching the following regular expressions: requestRegExp A RegExp to test the request against. contextRegExp (optional) A RegExp to test the context (directory) against.

Why do you need a loader when using webpack?

Webpack enables use of loaders to preprocess files. This allows you to bundle any static resource way beyond JavaScript. You can easily write your own loaders using Node.

What are webpack plugins?

A webpack plugin is a JavaScript object that has an apply method. This apply method is called by the webpack compiler, giving access to the entire compilation lifecycle.


Video Answer


1 Answers

You could add the ignore-loader plugin and match files to it.

Example (in webpack.config.js)

This will ignore all .css files.

module.exports = {
  // ... other configurations ...
  module: {
    loaders: [
      { test: /\.css$/, loader: 'ignore-loader' }
    ]
  }
};

I needed it since I was requiring some node_modules that imported multiple font formats, but I only wanted woff or woff2 formats.

My solution:

config = {
  // ... config ...
  module: [
    { test: /(\.woff|\.woff2)$/, loader: 'url?name=font/[name].[ext]&limit=10240&mimetype=application/font-woff' },
    { test: /\.ttf$/, loader: 'ignore-loader' },
    { test: /\.eot$/, loader: 'ignore-loader' }
  ]
}
like image 58
Aᴄʜᴇʀᴏɴғᴀɪʟ Avatar answered Sep 17 '22 19:09

Aᴄʜᴇʀᴏɴғᴀɪʟ