Giter VIP home page Giter VIP logo

Comments (6)

tannerlinsley avatar tannerlinsley commented on May 17, 2024 4

from react-static.

tannerlinsley avatar tannerlinsley commented on May 17, 2024

from react-static.

whmountains avatar whmountains commented on May 17, 2024

I can't import images either, but the symptoms are slightly different:

import photo from '../assets/starry-night.jpg'

photo now returns a base64 data url for the broken image icon. lolwat?

from react-static.

D1no avatar D1no commented on May 17, 2024

Have you looked at: #24 (comment) ?

from react-static.

DanWebb avatar DanWebb commented on May 17, 2024

I know an example config is requested but is there a reason this isn't built in? Gatsby enables it by default and actually suggests using this method to import assets for seemingly valid reasons.

Sorry if this is already being worked on it was just something I expected to be able to do, maybe I'm spoilt.

from react-static.

tannerlinsley avatar tannerlinsley commented on May 17, 2024

This should be fixed in the latest version. Please upgrade both global and local packages to version 2.0.0

Make sure you import and use the withFileLoader from react-static's plugins in your static.config.js file:

import axios from 'axios'
//
import withCss from 'react-static/lib/plugins/withCssLoader'
import withFiles from 'react-static/lib/plugins/withFileLoader'

export default {
  getSiteProps: () => ({
    title: 'React Static',
  }),
  getRoutes: async () => {
    const { data: posts } = await axios.get('https://jsonplaceholder.typicode.com/posts')
    return [
      {
        path: '/',
        component: 'src/containers/Home',
      },
      {
        path: '/about',
        component: 'src/containers/About',
      },
      {
        path: '/blog',
        component: 'src/containers/Blog',
        getProps: () => ({
          posts,
        }),
        children: posts.map(post => ({
          path: `/post/${post.id}`,
          component: 'src/containers/Post',
          getProps: () => ({
            post,
          }),
        })),
      },
      {
        is404: true,
        component: 'src/containers/404',
      },
    ]
  },
  webpack: [withCss, withFiles],
}

Then you can simply import images in your js

import logo from './logo.png'

from react-static.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.