Comments (9)
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.
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.
I can't imagine why the sourcemap would conflict. What gave you the idea that removing them would help?
from react-slingshot.
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.
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.
@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.
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
But is viewable here:
http://localhost:3000/30898abe6ff41c413083cf5b7ef3a556.png
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. 😄
from react-slingshot.
It looks like you're two steps away from success:
- Try using an absolute path for your image. I assume you're currently not providing a leading slash.
- 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.
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)
- Use redux-saga
- npm run remove-demo doesn't work
- Terminal font becomes invisible after npm start
- Error running 'npm install' HOT 1
- Switch Redux logic setup to use Redux Toolkit HOT 4
- Involving Database HOT 4
- why there are yarn.lock and package-lock.json both present? HOT 6
- Implementation of redux-persist with react-slingshot HOT 5
- [WARNING] Removing the demo app also removes files that do not belong to the demo app
- Get error when execute "npm start" command. HOT 1
- Required Information about peripheral files. HOT 2
- Update README about python version HOT 1
- Refused to execute inline script because it violates the following Content Security Policy directive:
- facing issue while npm run setup HOT 2
- Opentest issue
- npm run on production environment
- Add Flow please
- npm ERR! [email protected]
- jest: not found
- Build 16x fails not 18x or 20x
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-slingshot.