Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using dynamic Imports with a CDN #14

Closed
derweili opened this issue Aug 6, 2021 · 1 comment · Fixed by #17
Closed

Using dynamic Imports with a CDN #14

derweili opened this issue Aug 6, 2021 · 1 comment · Fixed by #17

Comments

@derweili
Copy link
Contributor

derweili commented Aug 6, 2021

I created the followin issue swashata/wp-webpack-script#1230 on the wp-webpack-script repo but I think it's better located here

Problem Description

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.

Possible Solution

I checked the source code and I think this could easily be solved by adding a filter to the Enqueue::getUrl() method before returning the value.

public function getUrl( $asset ) {
return $this->rootUrl . $asset;
}

Any thoughts about that?

@swashata
Copy link
Owner

swashata commented Aug 7, 2021

Yes you are correct. Also along with filtering the output of getUrl, I think we can also filter the output of printPublicPath for more extensibility.

public function printPublicPath() {
$publicPath = $this->getUrl( '' );
$jsCode = 'window.__wpackIo' . $this->sanitize_path( $this->appName . $this->outputPath ) . '=\'' . esc_js( $publicPath ) . '\';';
echo '<script type="text/javascript">/* wpack.io publicPath */' . $jsCode . '</script>';
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants