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

Importing image with CDN url #1488

Closed
rezamonangg opened this issue May 8, 2018 · 2 comments
Closed

Importing image with CDN url #1488

rezamonangg opened this issue May 8, 2018 · 2 comments

Comments

@rezamonangg
Copy link

rezamonangg commented May 8, 2018

So i have code structure folder like this:

app/
       javascript/
           components/
             HelloComponent.jsx <-- my component
           packs/
              images/ <-- image here
                icon.svg
              application.js

HelloComponent.jsx

  import Icon from 'images/icon.svg';
  import React from 'react';

  export default class HelloComponent extends React.Component {}

so i tried in my local machine and it load perfectly, the image is loaded from public folder.
then i tried in staging env with NODE_ENV=production, where the assets is from s3. but it doesn't load in staging because the image was loaded from public folder.

My expectation : the image url is from cdn (is it possible?)
Reality: the image url is from public folder

@rossta
Copy link
Member

rossta commented May 9, 2018

@rezadhah My understanding is that Webpacker is configured for images via file-loader, but that you'd need to hook up the publicPath option for that loader in your configuration like the examples in this comment. See #1186 for more info.

As an aside, you probably don't want your images in app/javascript/packs. The packs folder is only meant for JS entry points for Webpack output bundles.

First, try instead this layout and update your import for the image accordingly:

app/
   javascript/
      images/
         icon.svg
      components/
        HelloComponent.jsx
      packs/
        applications.js

@rezamonangg
Copy link
Author

Thanks! I solved it by literally copied the code from the links :D
I will close this issue, but i don't know that code will be needed for future update.

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

2 participants