-
Notifications
You must be signed in to change notification settings - Fork 27.2k
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
isomorphic-style-loader example #1615
Comments
I started working on this, but it's more complicated than I thought. next is doing some pretty special things in webpack. For instance, CSS loaders seem to be completely ignored when writing output to the |
Ok, finally read this. Hmmm. |
Looking foward to that so much! Hope you can make it! |
I'm going to work on this more when I have time. I will need to spend more time understanding the next code. |
@timmywil I'm interested in seeing this as well. One major piece of plumbing is the context.insertCss which has to be passed as a prop to the App container at some point. I've been going through |
@timmywil as for the css loaders writing out to module.exports = {
webpack: (config, { dev }) => {
const isDebug = !!dev;
config.module.rules.push({
test: /\.scss$/,
use: [
'isomorphic-style-loader',
'raw-loader',
{
loader: 'emit-file-loader',
options: {
name: 'dist/[path][name].[ext]'
}
},
{
loader: 'css-loader',
options: {
// CSS Loader https://github.com/webpack/css-loader
importLoaders: 1,
sourceMap: isDebug,
// CSS Modules https://github.com/css-modules/css-modules
modules: true,
localIdentName: isDebug ? '[name]-[local]-[hash:base64:5]' : '[hash:base64:5]',
// CSS Nano http://cssnano.co/options/
minimize: !isDebug,
discardComments: { removeAll: true },
},
},
'postcss-loader',
]
})
return config
}
} and the output that I get in exports = module.exports = require("../../node_modules/css-loader/lib/css-base.js")(true);
// imports
// module
exports.push([module.id, ".Hero-heroHeader-Wc-hV {\n height: 200px; }\n\n@media (min-width: 576px) {\n .Hero-heroHeader-Wc-hV {\n height: 240px; } }\n\n@media (min-width: 768px) {\n .Hero-heroHeader-Wc-hV {\n height: 300px; } }\n\n@media (min-width: 1200px) {\n .Hero-heroHeader-Wc-hV {\n height: 350px; } }\n\n@media (min-width: 1440px) {\n .Hero-heroHeader-Wc-hV {\n height: 400px; } }\n\n\n\n", "", {"version":3,"sources":["/Users/wing/Projects/Personal/app-web/components/Hero/Hero.scss"],"names":[],"mappings":"AAAA;IACI,cAAc,EAAE;;AAEpB;IACI;QACI,cAAc,EAAE,GAAG;;AAC3B;IACI;QACI,cAAc,EAAE,GAAG;;AAC3B;IACI;QACI,cAAc,EAAE,GAAG;;AAC3B;IACI;QACI,cAAc,EAAE,GAAG","file":"Hero.scss","sourcesContent":[".heroHeader {\n height: 200px; }\n\n@media (min-width: 576px) {\n .heroHeader {\n height: 240px; } }\n@media (min-width: 768px) {\n .heroHeader {\n height: 300px; } }\n@media (min-width: 1200px) {\n .heroHeader {\n height: 350px; } }\n@media (min-width: 1440px) {\n .heroHeader {\n height: 400px; } }\n\n\n\n"],"sourceRoot":""}]);
// exports
exports.locals = {
"heroHeader": "Hero-heroHeader-Wc-hV"
}; |
@winglian Thanks! I think adding emit-file-loader is a step in the right direction. I'll look further asap. |
@sergiokopplin I should have some time today. I'll reply here again with any discoveries, or I'll just open a PR if I get it working. |
thanks man! let's get this to work! |
@sergiokopplin exactly |
I'm not going with next because of this. :/ |
I started this and opened a PR for collaboration. I can get either server rendering or client rendering to work correctly, but not both at the same time and I'm not sure why yet. |
Watching this with interest. I love next but I think we are going to pass until we can use the most common (e.g.: standard) css solutions... |
The CSS standard is what |
@rauchg I don't want to use css-in-js. We've built a number of solutions with that; it is overkill for what I need to build right now. I'd like to use SASS but without being able to add a css loader, that's a no-go. I can build it manually, perhaps even set up a side process to watch it. Not a big deal I guess. I'd love to see you guys support a solution like that out of the box. Next blows everything else out of the water. |
I'm hoping that the following two PRs in styled-jsx combined with some of the techniques used in examples/with-global-stylesheet will allow us to use SCSS (or whatever else) in an easy way.
For example:
I'm thinking you could use babel to transform SCSS files to a string, then dump that string to styled-jsx, provide a pre-process function, and let styled-jsx handle the scoping, autoprefixing, minifying, ensuring only one block of CSS is used for each component, etc Fingers crossed! This would be a pretty awesome CSS setup! |
Entire our team struggling with not supported |
@dvakatsiienko same here! |
Personally, I'd love to be able to create a custom build of a CSS framework like Bootstrap 4 or Foundation and then import global and local scoped SCSS files. |
Found this davibe/next.js-example-with-global-stylesheet#8 |
Some slight changes I propose to example that would make it much easier: #2382 |
@winglian same issue, i have tried resolve wrong paths with babel-plugin-module-resolver but with no positive results. I think and hope there is not so much effort to handle this issue. Yet still just with |
@dvakatsiienko Would https://github.com/moxystudio/next.js-style-loader be of any help? It's been recently deprecated as the original creators moved away from next.js, but it works for us (we use it with CSS modules, not SCSS, though). |
@agurtovoy did't tried that yet, and I'll do. Thank you very much for a suggestion! |
For what it's worth, I spent 2 days trying to get .scss files to work as imports/css-modules with no luck after going through all the various examples, gists and SO posts. Given the importance of this feature we had to drop Next for ReactQL which supports this "out of the box" and has worked out very well for us. I have no affiliation with ReactQL but I would recommend others with this issue have a look. |
@NotJustClarkKent are you talking about FWIW using the latest Next 4, along with Given the way Next works, |
@codinronan specifically I was sort of able to get global scss files working using the externally global scope example and this thread but found that sometimes it would generate the |
Would you welcome an isomorphic-style-loader example–the loader used in react-starter-kit–or is there a reason it hasn't been done yet? I think it would be matter of adding a css loader to
next.config.js
and either setting/concating thestyles
property for the head tag in_document.js
or creating a separatestyle
tag in_document.js
for non-styled-jsx styles.I don't want to attempt it if it's already been tried and discarded.
The text was updated successfully, but these errors were encountered: