Turner Hayes
Turner Hayes

Reputation: 1944

WebpackHTMLPlugin output built references with a prefix

I have a configuration option for my Express app that determines whether to pull static content (JS, CSS, etc.) from a separate URL (e.g. using webpack-dev-server) or serving it "inline" via express.static() in the Express app. So I need to output a different origin depending on that configuration:

<script src="{STATIC_CONTENT_PATH}/[resource reference]"></script>

where {STATIC_CONTENT_PATH} is the web server's origin if serving inline, or the content server's origin if running separately. So far, I've only been able to get it to output a path that is relative to the site root (/publicPath/[resource reference]). Is there an easy way to add a prefix to the path used in the tags that the plugin outputs?

Upvotes: 1

Views: 212

Answers (1)

Turner Hayes
Turner Hayes

Reputation: 1944

I don't think there's any existing option to do this, so I just used a template, which contains the following:

<%= _.map(htmlWebpackPlugin.files.js, (path) => `<script src="${htmlWebpackPlugin.options.staticContentURL}${path}"></script>` ).join("") %>

(I also passed through the URL as a config option to the plugin)

Upvotes: 1

Related Questions