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

Unable to find assets with external cssBaseUrl and jsBaseUrl #35

Closed
amayer-hc opened this issue Nov 2, 2021 · 1 comment · Fixed by #36
Closed

Unable to find assets with external cssBaseUrl and jsBaseUrl #35

amayer-hc opened this issue Nov 2, 2021 · 1 comment · Fixed by #36
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@amayer-hc
Copy link
Contributor

Description

My assets are hosted on a CDN in production. According to the Cake Book the App.cssBaseUrl and App.jsBaseUrl should be the URL and path to the CDN. When I set App.jsBaseUrl to https://example.com/js/ I get the following error when trying to execute $this->AssetMix->script('app');:

Unable to locate AssetMix file: /https://example.com/js/app.js.

Steps To Reproduce

  1. Add the following lines to app_local.php. Combine the App array if one already exists.
    'App' => [
        'cssBaseUrl' => 'https://example.com/css/',`
        'jsBaseUrl' => 'https://example.com/js/',
    ]
  2. Compile javascript and CSS assets.
    mix.js('resources/js/app.js', 'webroot/js')
        .sass('resources/sass/main.scss', 'webroot/css');
  3. Add $this->AssetMix->js('app'); to a template file.

Expected behavior

The CSS file should load from https://example.com/css/main.css and the javascript should load from https://example.com/js/app.js.

Tests

I wrote these tests in case they would be useful.

/**
 * Test `css()` function returns proper url
 *
 * @return void
 */
public function testStyleTagWithExternalBaseUrl()
{
    Configure::write('App.cssBaseUrl', 'https://example.com/css/');

    $this->_copyWithoutVersion();

    $result = $this->AssetMix->css('main');

    $this->assertStringContainsString('https://example.com/css/main.css', $result);
}

/**
 * Test `script()` function returns proper url
 *
 * @return void
 */
public function testScriptTagWithExternalBaseUrl()
{
    Configure::write('App.jsBaseUrl', 'https://example.com/js/');

    $this->_copyWithoutVersion();

    $result = $this->AssetMix->script('app');

    $this->assertStringContainsString('https://example.com/js/app.js', $result);
}
@ishanvyas22 ishanvyas22 added enhancement New feature or request good first issue Good for newcomers labels Nov 4, 2021
@ishanvyas22
Copy link
Owner

Hey @amayer-hc, thanks opening a bug report with detailed description. Would you mind submitting a PR?

amayer-hc added a commit to amayer-hc/asset-mix that referenced this issue Nov 11, 2021
This allows assets to be hosted on a CDN
Closes ishanvyas22#35
@ishanvyas22 ishanvyas22 linked a pull request Nov 13, 2021 that will close this issue
amayer-hc added a commit to amayer-hc/asset-mix that referenced this issue Nov 15, 2021
This allows assets to be hosted on a CDN
Closes ishanvyas22#35
ishanvyas22 pushed a commit that referenced this issue Nov 15, 2021
This allows assets to be hosted on a CDN
Closes #35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants