Pascal
Pascal

Reputation: 8939

Serving webpack built assets from a subdirectory

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?

Upvotes: 10

Views: 15144

Answers (1)

Pascal
Pascal

Reputation: 8939

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

Upvotes: 14

Related Questions