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

Production build uses versioning and the template doesn't point to that version #79

Open
jonginn opened this issue Jun 24, 2020 · 4 comments

Comments

@jonginn
Copy link

jonginn commented Jun 24, 2020

When running in prod mode, the assets are made with Symfony Encore with versioning.

See webpack.config.js, line 17/18:

// enables hashed filenames (e.g. app.abc123.css)
.enableVersioning(Encore.isProduction())

However in _layouts/default.html, this still uses the non-versioned file:

<link rel="stylesheet" href="{{ site.url }}/build/app.css">

Running these commands:

yarn encore prod
./vendor/bin/sculpin generate --env=prod

I would expect to get a production ready site but app.css does not exist. I would expect default.html to point to app.HASH.css. The same is true for the JS.

Is there some way Sculpin can use encore_entry_link_tags and encore_entry_script_tags as Symfony does, or similar? I would much rather use the versioned assets, as then it helps with caching. I can't see anywhere in the Sculpin docs that does this.

I can see in this post from 2017 that "There is no easy way for Sculpin to handle the manifest.json file. Yet." is this something that's been resolved, or is the addition of enableVersioning in webpack.config.js an error?

I can see this comment that seems to cover the same issue: sculpin/sculpin#354 (comment)

If there's no way to use Encore versioning, is there some way I can use app.css?v={{ buildFragment }} where buildFragment is a random number that's created every time the site is built?

Thanks!

@jonginn
Copy link
Author

jonginn commented Jun 25, 2020

As an update to this, I'm now using the Netlify plugin to generate hashes - https://github.com/munter/netlify-plugin-hashfiles which seems to work quite well.

@beryllium
Copy link
Member

That looks like an interesting approach.

On one of my blogs, I used a Twig Extension to transform the build/manifest.json file into an array I can access in Twig, which lets me pluck out the values for including CSS and JS files with hashes. Today I'm working on a PR to bake this into the Sculpin Twig Bundle.

@jonginn
Copy link
Author

jonginn commented Jun 28, 2020

@beryllium that looks great!

If it's of any help, I use a similar approach for Wordpress to allow Symfony Encore to build assets, and then allow Wordpress to enqueue all files related to an entry.

It works great with Encore's splitEntryChunks option, so multiple files can be made and auto-imported.

https://gist.github.com/jonginn/21a025421fc9ebf3bf7025d043fa0349

@devromans
Copy link

Check https://github.com/sculpin/sculpin/blob/master/src/Sculpin/Bundle/TwigBundle/WebpackEncoreHelper.php (I'm using "sculpin/sculpin":"^3.1").

Config app/config/sculpin_kernel.yml looks like:

sculpin_twig:
    webpack_manifest: build/manifest.json

Layout default.html:

<link rel="stylesheet" href="{{ site.url }}{{ webpack_manifest['build/app.css']|default('/build/app.css') }}">

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

No branches or pull requests

3 participants