-
-
Notifications
You must be signed in to change notification settings - Fork 384
Extract CSS from SCSS and deferred lazy load into app #105
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
Comments
Related issue: #94 |
@johnelliott how this issue related to your problem? use |
@fillippeyton sorry i can't help your here, please create new issue with minimum reproducible test repo and what you have and what you expected and description. Why do I ask to do this? Because we have hundreds of requests (issues and PRы) and it takes a lot of time, the more accurately you can formulate the problem and demonstrate it using a small configuration, the sooner your problem will be solved or you can start investigating problem yourself and send us PR |
@johnelliott The solution I've come up with is using I would love to dynamically import these via a named import or some way that feels less hacky. |
@fillippeyton can we close issue? |
@fillippeyton my solution was to use the extract-loader and file-loader after the css-loader. From there I would conditionally emit the file on the client or server webpack config and have the output file name be the content hash. This would allow me to import the file name on disk in both server and client. Then in the client when the webpack mode is development I would use the style-loader instead of the extract-loader and file-loader chain. I realize it’s a bit difficult to describe some of these configurations without some code to look at. :/ |
Appreciate the effort looking into this @johnelliott ! I'll take a swing at that solution when I have some time. |
@johnelliott thank you for the idea! Would you be able to share your setup? I'm looking into doing something similar, and would greatly appreciate it. |
@danburzo I’m working until 6pm EST but I’ll follow up. Gotta find the branch too :p |
Thank you @johnelliott for the idea! I was able to adapt it to suit our needs, like below. (It actually ended up not using webpack.config.js module: {
rules: {
// Font stylesheets
{
test: /\.css$/,
use: [
{
loader: 'file-loader',
options: {
name: config.local ? 'css/[name].[ext]' : 'css/[hash].[ext]'
}
},
'extract-loader',
'css-loader',
'postcss-loader'
],
include: [/fonts/]
},
// Font files
{
test: /\.(woff|woff2|ttf|otf)$/,
loader: 'file-loader',
include: [/fonts/],
// awkward path config to make everything work
// See: https://github.com/webpack-contrib/file-loader/issues/261
options: {
name: config.local ? '[name].[ext]' : '[hash].[ext]',
outputPath: 'css/',
publicPath: '../css/'
}
},
}
} With this setup:
I am able to have individual, content-hashed CSS files whose URLs I can obtain in the JS code with |
Good to hear Dan :) |
I have a few SCSS theme files I want to extract to CSS files and later load them into the page. I want to be able to use
contenthash
for long term caching.Since I'm using Webpack 4, I am using mini-css-extract-plugin. I started down the path of creating a splitChunks in my webpack config.
I've then tried dynamically importing the css in my app:
I need to be able to load that css file dynamically in
login()
and I'm just not sure how to reference it when it has a generated[contenthash]
. Is there a good way to reference the split css chunks in my app when usingmini-css-extract-plugin
?The text was updated successfully, but these errors were encountered: