GithubHelp home page GithubHelp logo

Images about react-slingshot HOT 9 CLOSED

coryhouse avatar coryhouse commented on May 5, 2024
Images

from react-slingshot.

Comments (9)

waltercolindres avatar waltercolindres commented on May 5, 2024

Should probably explain a bit more:

I am putting some background images in my scss files and running this in my config.

const getLoaders = function (env) {
  const loaders = [{ test: /\.js$/, include: path.join(__dirname, 'src'), loaders: ['babel', 'eslint'] },
  {
     test: /\.(jpe?g|png|gif|svg)$/i,
     loaders: ['file']
   }

   ];

  if (env === productionEnvironment ) {
    // generate separate physical stylesheet for production build using ExtractTextPlugin. This provides separate caching and avoids a flash of unstyled content on load.
    loaders.push({test: /(\.css|\.scss)$/, loader: ExtractTextPlugin.extract("css?sourceMap!sass?sourceMap")});
  } else {
    loaders.push({test: /(\.css|\.scss)$/, loaders: ['style', 'css?sourceMap', 'sass?sourceMap']});
  }

  return loaders;
};

What I am getting is a an image with a dynamically generated name:

.top-left {
    background-image: url(30898abe6ff41c413083cf5b7ef3a556.png);
}

Right click to open in new tab and this is the url:

chrome-devtools://devtools/bundled/30898abe6ff41c413083cf5b7ef3a556.png

Which does not work. But if I go to:

http://localhost:3000/30898abe6ff41c413083cf5b7ef3a556.png

It works... so I am not sure what I am missing here.

If I do a npm run build the image is still linked via a hash, but I can finally see it in my view. So it looks like I am missing something from the dev config.

from react-slingshot.

waltercolindres avatar waltercolindres commented on May 5, 2024

Follow up, I was able to get around this by removing source maps from dev, which is a bummer. Any recommendations on how I can use sourcemaps with images in scss?

from react-slingshot.

coryhouse avatar coryhouse commented on May 5, 2024

I can't imagine why the sourcemap would conflict. What gave you the idea that removing them would help?

from react-slingshot.

waltercolindres avatar waltercolindres commented on May 5, 2024

I did a lot of googling and found some issues with image urls and libsass not playing nicely with sourcemaps. Another thing I found was if the images are not relative to the sourcemap it can't find them, but I am not 100% sure on that being the cause. I'll see if I can find the issues I found again (got excited and closed all my windows). All I changed was this line:

old >> loaders.push({test: /(\.css|\.scss)$/, loaders: ['style', 'css?sourceMap', 'sass?sourceMap']});

new >>  loaders.push({test: /(\.css|\.scss)$/, loaders: ['style', 'css', 'sass']});

Love the project, my fav react starter so far!

from react-slingshot.

waltercolindres avatar waltercolindres commented on May 5, 2024

I am wondering if I need to add anything to the build tools to copy over the images. They seem to be broken now. I reverted to using sourcemaps.

from react-slingshot.

coryhouse avatar coryhouse commented on May 5, 2024

@waltercolindres Can you get latest and try again? The webpack config now handles images, so I suspect this will resolve your issue.

from react-slingshot.

waltercolindres avatar waltercolindres commented on May 5, 2024

Ok, so interestingly, that fixed it if I do a npm run build. However, npm start still has it as a missing background image. So in prod it works, in dev the image is missing.

It still produces an image link for dev:

.top-left {
    background-image: url(30898abe6ff41c413083cf5b7ef3a556.png);
}

When I right click the image goes here which is un-viewable:
chrome-devtools://devtools/bundled/30898abe6ff41c413083cf5b7ef3a556.png

screenshot 2016-03-16 10 20 22

But is viewable here:
http://localhost:3000/30898abe6ff41c413083cf5b7ef3a556.png

screenshot 2016-03-16 10 20 17

Another issue I've run into is that the images directory is not copying over during npm run build. Where can I place that command? They work fine during npm start/dev but once I do a build, they fall out. I can see that the images folder is not being copied over. So my inline images work in dev, but they don't get copied over for production. Which is ironic considering the first issue. 😄

Screen of my directory setup:
screenshot 2016-03-16 10 12 49

Screen of my dist:
screenshot 2016-03-16 10 12 44

from react-slingshot.

coryhouse avatar coryhouse commented on May 5, 2024

It looks like you're two steps away from success:

  1. Try using an absolute path for your image. I assume you're currently not providing a leading slash.
  2. Add a build step to copy the images folder. Check /tools/buildHtml.js for an example of how I'm migrating the HTML file. Same idea.

from react-slingshot.

waltercolindres avatar waltercolindres commented on May 5, 2024

Thanks for you help Cory, definitely getting close.. This looks to be an issue with the style loader: https://github.com/vuejs/vue-loader-example/issues/43

I will close this!

from react-slingshot.

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.