Skip to content

Manifest includes assets_url in v4.0.0.rc.2 #1845

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
JanStevens opened this issue Dec 20, 2018 · 9 comments
Closed

Manifest includes assets_url in v4.0.0.rc.2 #1845

JanStevens opened this issue Dec 20, 2018 · 9 comments
Labels

Comments

@JanStevens
Copy link

JanStevens commented Dec 20, 2018

Hello

In version v4.0.0.rc.2 now generates a manifest.json file that includes the configured asset host

{
  "admin.css": "https://xxxxx.cloudfront.net/packs/admin-e902804e.css",
}

In my production.rb I got

config.action_controller.asset_host = "https://xxxxx.cloudfront.net"

And my environment.js has

const splitChunks = {
  optimization: {
    runtimeChunk: false,
    splitChunks: {
      chunks: 'all'
    }
  }
}

environment.config.merge(splitChunks)

environment.plugins.insert(
  'Manifest',
  new WebpackAssetsManifest({
    integrity: false,
    entrypoints: true,
    writeToDisk: true,
    publicPath: true
  })
)

In version v4.0.0.pre.3 the same settings would generate the manifest as followed:

{
  "admin.css": "/packs/admin-e902804e.css",
}

I do want to turn this off, since I do not know during compilation of my assets the cloudfront url and my devops team might want to change the cloudfront url. This would now mean we have to recompile assets again.

We compile assets and upload them to S3 using

 env RAILS_ENV=production env NODE_ENV=production bundle exec rake webpacker:compile   

Regards

@gauravtiwari
Copy link
Member

Thanks for reporting, let me take a look 👍

@iggant
Copy link

iggant commented Jan 28, 2019

@gauravtiwari If this is not a bug, can you please explain why this happens, and can this will be fixed by any config parameter?

@marcohamersma
Copy link

marcohamersma commented Feb 1, 2019

@gauravtiwari I think this is breaking stuff for our users. Just adding wontfix without any explanation is not very communicative.

update:
To elaborate a bit on how it breaks; we use Heroku's pipeline feature for our deployment. Which for us means that assets will get built for the staging environment, and then the app gets "promoted" to production, and assets will not change anymore.

From the Heroku docs:

When a slug is promoted, Heroku copies it without making any changes. It is not rebuilt for the environment of the target app. If your builds bake in environment from the build-app context, then your slugs are not portable between pipeline stages.

Considering that our staging setup has a separate CDN url, this means that staging's CDN url is now baked in to the asset manifest file. I noticed there might ways of dealing with this by adding extra steps to the Procfile, but this is a bit of a hassle and I'd rather have that this type of default workflow would just work out of the box like the 3.x version of Webpacker.

@joelmoss
Copy link

Just adding wontfix without any explanation is not very communicative.

Extremely unhelpful, and not in the spirit of open source at all :(

@guilleiguaran
Copy link
Member

Please take a look to #1973

@gauravtiwari
Copy link
Member

gauravtiwari commented Mar 3, 2019

Sorry about not adding more info earlier. I was away :)

Basically, this is not a bug, in other words, it sort of like chicken-egg situation. Rails add CDN host through helper tags for all the assets included in the views, however, assets like images or font icons which are included inside JS code or CSS files don't have CDN if we don't supply full public path since it's processed by file loader, which uses webpack public path.

For example:

import Rails from 'rails'
import Rails2 from 'rails_assets'
import Google from 'some_namespace/google'

const Hello = props => (
  <div>Hello {props.name}!<img src={Google} /> <img src={Rails} /> <img src={Rails2} /></div>
)

Note: The images included above won't have CDN included since they are processed by webpack using file loader, unless we specify public path with CDN.

Now, current implementation works for both cases, since Rails is intelligent enough to figure out that a URI includes CDN host if we supply a CDN host to webpack and the generated URI includes CDN host, Rails doesn't add CDN host to it and the embedded assets also include CDN hosts.

I see, this might not be ideal for some cases like described above but this is the best we can get at the moment that's why I added won't fix label earlier.

If anyone has ideas, feel free to post.

@gauravtiwari
Copy link
Member

Found a solution :)

@gauravtiwari
Copy link
Member

Please see the PR

@marcohamersma
Copy link

Great! thanks for taking a look 🙂

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

No branches or pull requests

6 participants