-
Notifications
You must be signed in to change notification settings - Fork 14k
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
Enable CSS Hot Module Replacement and optimize css output for production #5813
Conversation
@xtinec said she knows Webpack very well and can help review & advise here |
superset/assets/webpack.config.js
Outdated
@@ -2,7 +2,9 @@ const path = require('path'); | |||
const webpack = require('webpack'); | |||
const CleanWebpackPlugin = require('clean-webpack-plugin'); | |||
const MiniCssExtractPlugin = require('mini-css-extract-plugin'); | |||
const OptimizeCSSAssetsPlugin = require("optimize-css-assets-webpack-plugin"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Nit] ''
here to get past the linter.
Looks good aside from the small thing to use |
Thanks @mistercrunch , @xtinec |
Codecov Report
@@ Coverage Diff @@
## master #5813 +/- ##
=======================================
Coverage 63.82% 63.82%
=======================================
Files 364 364
Lines 23099 23099
Branches 2587 2587
=======================================
Hits 14744 14744
Misses 8340 8340
Partials 15 15 Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! looks like I had the 'mini-css-extract-plugin
backwards 🤦♂️ 🙃 .
thanks for making the dev env 💯x better!
…ion (apache#5813) * Enable HMR for css. Use style-loader for development * optimize css output * remove mini-css-extract when dev * change double-quote to single-quote
…ion (apache#5813) * Enable HMR for css. Use style-loader for development * optimize css output * remove mini-css-extract when dev * change double-quote to single-quote
Enable HMR for CSS
Current webpack settings uses
mini-css-extract-plugin
for both development and production. This plugin extract css into many small files based on the modules that imports them.However, per the package's README, it is recommended for production only especially if we want Hot Module Replacement (HMR) for CSS. To use HMR, we need to use
style-loader
when in development mode. Otherwise, the page will not update after saving CSS files.https://github.com/webpack-contrib/mini-css-extract-plugin#advanced-configuration-example
To ensure that
style-loader
works correctly, I also need to modify the html templates to importtheme
js entry points. Becausestyle-loader
injects css code via js that writes<style>
tags instead of exporting css files.Optimize CSS output
Current CSS output from webpack are not minified. This PR adds
optimize-css-assets-webpack-plugin
to minify CSS outputs. The minification reduce CSS size by ~100kbTesting
I have tested building in production and running dev server. Both are working fine.
@graceguo-supercat @xtinec @hughhhh @conglei @williaster