Copy static assets while keeping directory structure

I have a structure like this:

/app1/img1.png
/app1/main.js
/app2/img2.png
/app2/main.js

With the output.file option I can output the js bundle to the correct directory (e.g. app1). But how can I output the img1.png as app1/img1.png?

One option it to use require('file!name=app/img1.png!./img1.png'), but then I have to specify the loader manually each time. I’d like to specify this in config, i.e.

{ test: /([a-z0-9]+)\/([a-z0-9]+\.png)$/, loader: "url-loader?name=$1/$2 },

Now the image filename gets hashed and outputted at root.

Author: Fantashit

2 thoughts on “Copy static assets while keeping directory structure

  1. i. e. file?name=[path][name].[ext]&context=/the/root/path

    This copies the file /the/root/path/dir/file.png to /output-directory/dir/file.png.

    But I recommend to use file?name=[path][name].[ext]?[hash]&context=/the/root/path which also adds a hash to the url (not visible on filesystem) for better cacheablitity…

Comments are closed.