Last active
May 10, 2020 01:08
-
-
Save kilgarenone/f7b2ce07183809ed4edbbb84845f8323 to your computer and use it in GitHub Desktop.
extract css in webpack
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// webpack.config.js | |
module.exports = { | |
entry: { | |
critical: path.resolve(__dirname, "../src/css/index.scss") // this's a chunk, source from a file with my critical CSS I wanna inline! | |
}, | |
plugins: [ | |
new MiniCssExtractPlugin({ | |
filename: "[name].css" // it's gonna be 'critical.css' | |
}), | |
new HtmlWebpackPlugin({ // this is the 'html-webpack-plugin'! Get it cuz we gonna need it majorly! | |
template: 'path/to/your/custom/index/html', // use our custom template! | |
inject: false // important! cuz we gonna place the <link> and <script> ourselves | |
}) | |
], | |
module: { | |
rules: [ | |
{ | |
test: /\.scss$/, | |
use: [ | |
MiniCssExtractPlugin.loader, // one of the key incredients! | |
{ | |
loader: "css-loader", | |
options: { | |
modules: true, | |
localIdentName: "[name]__[local]" | |
} | |
}, | |
"sass-loader" | |
] | |
} | |
] | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment