Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Serving webpack built assets from a subdirectory

Tags:

webpack

build

In all the examples I've seen, the entrypoint html file (e.g. index.html) lives alongside all the built assets emitted by webpack.

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

I'd like to have my entrypoint html separate from the built assets:

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

Is this possible with webpack?

like image 447
Pascal Avatar asked Jun 30 '15 04:06

Pascal


1 Answers

Aha, figured it out. In the webpack.config, you have to set output.publicPath. That 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.github.io/docs/configuration.html#output-publicpath

like image 129
Pascal Avatar answered Oct 05 '22 12:10

Pascal