-
Notifications
You must be signed in to change notification settings - Fork 0
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
the-style-processing-of-webpack #11
Comments
Awesome! |
CSS background URL solutions
|
ExtractTextPluginOnly use ExtractTextPlugin in production mode. It haven't supported HMR yet. But ensure to use NODE_ENV instead of setting --mode in cli. NODE_ENV not set on process.env |
Interesting.. I haven't used this loader before. So I misunderstand its usage too at first glance. lemme add some note here. resolve-url-loaderWebpack css-loader will get assets out of url() statements. That is not what this loader does. This loader sits before css-loader and rewrites url() paths before they get to css-loader. Imagine you have a url() relative a scss file, which itself is imported into another scss file. Webpack will only see the root scss file and expect the asset to be relative to it. It will never know there was a nested scss file. It will go looking for the assets relative tot he root scss file and not find them. This loader looks in the source-map and finds the original file where the url() statement resides. It can then rewrite the path so that css-loader will be able to find the asset. Originally I wrote this loader because I had a root scss file for the project, and feature-based scss files and assets in a number of directories. Conversely if you have all your assets centralised then this is not your use-case. |
In the end I used all these for CSS:
This was effective for all the following:
I'm interested in what else there is to do for CSS ... this was a lot of processing for webpack to get through... apparently the community have discovered a lot of problems with CSS that needed fixing.... Your original post got me through to achieve the vast majority of my CSS goals. |
:D I'm so glad to help you! Feel free to discuss any tech stuff in my issue, I'd like to learn together! 👯 |
Haven't properly evaluated HMR in production, just using DevServer for development, CSS changes work fine. |
if you use react, check next :D |
style-loader
Adds CSS to the DOM by injecting a
<style>
tagcss-loader
The css-loader interprets
@import
andurl()
likeimport/require()
and will resolve them.Sets
importLoaders
option to prevent some bugs like:@import
ed files do not get processed by postcss'sautoprefixer
. postcss-loader#35 (Solution2: usespostcss-import
plugin beforeautoprefixer
)Sets
minimize
option to minimize the css files.postcss-loader
Loader for webpack to process CSS with PostCSS. Use it after
css-loader
andstyle-loader
, but before other preprocessor loaders like e.gsass|less|stylus-loader
, if you use any. Remember to set uppostcss.config.js
file too.The
Autoprefixer
PostCSS plugin is one of the most popular CSS processors. (cssnano
is great too. !)sass-loader
Loads a SASS/SCSS file and compiles it to CSS. The sass-loader requires
node-sass
andwebpack
as peerDependency.To enable CSS source maps, pass the
sourceMap
option to thesass-loader
and thecss-loader
.When you use preprocessor loaders with its option
sourceMap
being set, don't omit thesourceMap
option inpostcss-loader
(if you have this loader), or the previous source maps will be discarded bypostcss-loader
entirely.That's said, if you want to enable css's source maps function, ensure the relavant style's loaders have set the
sourceMap
option. you also need to includedevtool
option for webpack too. sass-loader#7ExtractTextWebpackPlugin
Extract text from a bundle, or bundles, into a separate file.
As the following example, it moves all the required
*.scss
modules in entry chunks into a separate CSS file. So your styles are no longer inlined into the JS bundle, but in a separate CSS filemain.css
. If your total stylesheet volume is big, it will be faster because the CSS bundle is loaded in parallel to the JS bundle.The text was updated successfully, but these errors were encountered: