Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to configure a loader for a specific path in webpack

Tags:

webpack

A question about webpack configure settings: in most examples, the test option in loader only checks the file name, not the full path. I have files in different directories that are the same type, but I want to use a different loader, e.g.

{     test:/aaa\/.*.html/,     loader:'loaderA' }, {     test:/bbb\/.*.html/,     loader:'loaderB' } 

Is there any way to make that work? Thanks for your attention and answers.

like image 244
Kent Wood Avatar asked May 27 '16 05:05

Kent Wood


People also ask

What is webpack public path?

publicPath specifies the virtual directory in web server from where bundled file, app. js is going to get served up from. Keep in mind, the word server when using publicPath can be either webpack-dev-server or express server or other server that you can use with webpack.

How does webpack file loader work?

Webpack goes through all the import ed and require d files in your project, and for all those files which have a . svg extension, it uses as an input to the webpack file loader. For each of these files, the file loader emits the file in the output directory and resolves the correct URL to be referenced.


1 Answers

You can use include and exclude properties (docs):

{     test:/\.html$/,     include: [         path.resolve(__dirname, "app/pathA")     ],     loader: 'loaderA' }, {     test:/\.html$/,     include: [         path.resolve(__dirname, "app/pathB")     ],     loader: 'loaderB' } 

For files in folder pathA will applied loader loaderA, and for pathB - loader loaderB.

like image 195
Bob Sponge Avatar answered Sep 17 '22 15:09

Bob Sponge