Serving webpack embedded resources from a subdirectory

In all the examples I saw, the html entrypoint file (like index.html) lives next to all the built-in resources released by webpack.

build/ index.html bundle.js 1.bundle.js 2.bundle.js etc 

I want my html entry point to be separated from the embedded resources:

 index.html build/ bundle.js 1.bundle.js 2.bundle.js etc 

Is this possible with webpack?

+6
source share
1 answer

Yeah, I got it. In webpack.config you must set output.publicPath . This path is used to prefix all relative URLs in CSS.

In my case, I used:

 output: { path: path.resolve('./build'), publicPath: './build/', filename: '[name].bundle.js' }, 

http://webpack.imtqy.com/docs/configuration.html#output-publicpath

+8
source

Source: https://habr.com/ru/post/989986/


All Articles