Is there a way to ignore file type using webpack?

When creating my art for my site, I have intermediate files that I want to save in my "media" folder.

But then webpack starts complaining that he does not know what to do with these files.

Is there an easy way to say don’t worry about any .pdn files?

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

  • { test: /\.pdn?$/, loader: 'raw', exclude: /.*/}
  • { test: /\.pdn?$/, exclude: /.*/}
+8
webpack
source share
2 answers

You can add the ignore-loader plugin and map files to it.

Example (in webpack.config.js )

This ignores all .css files.

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

I needed this because I needed a few node_modules that imported several font formats, but I only needed woff or woff2 .

My decision:

 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' } ] } 
+13
source share

The question is not what the web package wants to do with these files, but what do you want to do with these files when you require them? Do you want their contents in Javascript, do you want you to provide you with the path to the files in your assembly or something else?

If you don't need .pdn files, but Webpack is still trying to download them, you can use dynamic requirements. Dynamic requirements can do very strange things and tend to try to combine too much, so you should really avoid using them.

If you want to access files in one way, use the file loader.

In the above example, the first bootloader option will not work simply because you exclude everything in the exclude clause. You ask webpack to apply raw-loader to files matching "test", but ignore files matching "exclude", which is all in your case. Use { test: /\.pdn$/, loader: 'raw' } instead.

0
source share

All Articles