swashata / wp-webpack-script

💥🔥📦👩‍💻 An easy to use, pre configured, hackable webpack setup & development server for WordPress themes and plugins.
https://wpack.io
MIT License
408 stars 57 forks source link

How to use dynamic imports with a CDN #1230

Open derweili opened 3 years ago

derweili commented 3 years ago

wpack.io uses the __wpackIoAppNameOutputPath variable to get the url of the dist folder as described here https://wpack.io/concepts/how-publicpath-works/

For using CDNs, this variable needs to be set to the CDNs URL instead of the WordPress URL. The docs already mention this case:

For example, we could very much put all the files inside dist to a CDN, and change publicPath to https://cdn.example.com/path/to/asset/dir.

Unfortunately the docs don't tell how to change the variable to the CDN URL.

I checked the https://github.com/swashata/wp-webpack-script/issues/new repository as well as the https://github.com/swashata/wpackio-enqueue/ repo but I did not find a way to overwrite the __wpackIoAppNameOutputPath variable.

Is there a way to manually set or overwrite this variable? Did I miss something?

swashata commented 3 years ago

There isn't a way to do this right now. But I am happy for a PR to add this feature. Maybe through some environment variables?

swashata commented 3 years ago

Or better yet, we can filter the value from wpackio/enqueue, so that it can be set programmatically.