webpack-contrib / mini-css-extract-plugin

Lightweight CSS extraction plugin
MIT License
4.66k stars 388 forks source link

Insert option not working as expected #635

Closed zaidhuda closed 4 years ago

zaidhuda commented 4 years ago

Expected Behavior

linkTag should be prepended to body.

Actual Behavior

linkTag appended to head

Code

new MiniCssExtractPlugin({
  filename: 'styles.css',
  chunkFilename: 'styles.css',
  insert(linkTag) {
    window.document.body.prepend(linkTag);
  },
}),
{
  test: /\.s?[ac]ss$/,
  use: [
    MiniCssExtractPlugin.loader,
    'css-loader',
    'postcss-loader',
    'sass-loader',
  ],
},
<!DOCTYPE html>
<html>

<head>
  <base href="/" />
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width" />
</head>

<body>
  <div id="root"></div>
</body>

</html>
alexander-akait commented 4 years ago

insert option only for async chunks