8000 Encore manifest.json, assets package base_path · Issue #36844 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

Encore manifest.json, assets package base_path #36844

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

Closed
plashenkov opened this issue May 17, 2020 · 6 comments
Closed

Encore manifest.json, assets package base_path #36844

plashenkov opened this issue May 17, 2020 · 6 comments

Comments

@plashenkov
Copy link
plashenkov commented May 17, 2020

Symfony version:
5.0.7

Description
assets.packages.base_path is not used with json_manifest_path.

For example, this is my manifest.json:

{
  "build/admin/admin.js": "/build/admin/admin.b991d27f.js",
  "build/admin/runtime.js": "/build/admin/runtime.2dd405e4.js"
}

This is my assets.yaml:

framework:
    assets:
        packages:
            admin:
                base_path: /build/admin
                json_manifest_path: '%kernel.project_dir%/public/build/admin/manifest.json'

When I call asset() function from Twig, omitting the base_path prefix, manifest.json is ignored:

<!-- Twig: -->
<script src="{{ asset('admin.js', 'admin') }}"></script>

<!-- I expect (please note the b991d27f postfix): -->
<script src="/build/admin/admin.b991d27f.js"></script>

<!-- I really get: -->
<script src="/build/admin/admin.js"></script>

If to provide full path to asset() function, it renders the correct file name (with postfix).
I.e. if I want to use manifest.json I have to specify a full path regardless of base_path provided.

@GromNaN
Copy link
Member
GromNaN commented May 18, 2020

Is it a side effect of #35762 ?

Edit: No. That was merged in 5.1.

@mzzovko
Copy link
mzzovko commented Aug 17, 2020

Confirming this happens in 5.1.3

config/packages/assets.yaml

framework:
    assets:
        base_path: '/build'
        json_manifest_path: '%kernel.project_dir%/public/build/manifest.json'

config/packages/prod/assets.yaml

framework:
  assets:
    base_path: '/dist'
    json_manifest_path: '%kernel.project_dir%/public/dist/manifest.json'

public/dist/manifest.json - trimmed for readability

{
  ...,
  "dist/icons/apple-icon-180x180.png": "/dist/icons/apple-icon-180x180.7927522e.png",
  "dist/icons/apple-icon-57x57.png": "/dist/icons/apple-icon-57x57.4699adf7.png",
  "dist/icons/apple-icon-60x60.png": "/dist/icons/apple-icon-60x60.c013af87.png",
  ...
}

We use different asset folders for prod & dev, and after I've added different base_path for dev & prod (code above), in prod env version is not added to path (it seems that it only applies base_path but not version), in dev mode everything works, because there is no version, so there isnt problem.

example
<link rel="apple-touch-icon" sizes="57x57" href="{{ asset('icons/apple-icon-57x57.png') }}">
in prod env returns
<link rel="apple-touch-icon" sizes="57x57" href="/dist/icons/apple-icon-57x57.png">

and I expect
<link rel="apple-touch-icon" sizes="57x57" href="/dist/icons/apple-icon-57x57.4699adf7.png">

@carsonbot
Copy link

Hey, thanks for your report!
There has not been a lot of activity here for a while. Is this bug still relevant? Have you managed to find a workaround?

@carsonbot
Copy link

Just a quick reminder to make a comment on this. If I don't hear anything I'll close this.

@carsonbot
Copy link

Hey,

I didn't hear anything so I'm going to close it. Feel free to comment if this is still relevant, I can always reopen!

@tannyl
Copy link
tannyl commented Apr 29, 2021

I faced the same problem when using two packages with different base_path

After looking into how the base_path is applied, I the simple solution and wanted to share it.

If you have set the base_path for the admin package to /build/admin/
then instead of having the manifest.json look like this:

{
  "build/admin/admin.js": "/build/admin/admin.b991d27f.js",
  "build/admin/runtime.js": "/build/admin/runtime.2dd405e4.js"
}

You must do it like this:

{
  "admin.js": "/build/admin/admin.b991d27f.js",
  "runtime.js": "/build/admin/runtime.2dd405e4.js"
}

Now using

<script src="{{ asset('admin.js', 'admin') }}"></script>

will work as expected and result in

<script src="/build/admin/admin.b991d27f.js"></script>

If you are using Webpack Encore then it is simple to fix the prefixing in the manifest.json by using the setManifestKeyPrefix option.

// Admin config
Encore
  .setOutputPath('public/build/admin/')
  .setPublicPath('/build/admin')
  .setManifestKeyPrefix('') // <- Setting the Prefix to '' (empty string) will overwrite the /build/admin/ being added to the keys in the manifest.json file
// Rest of config...

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

No branches or pull requests

6 participants
0