Mini-css-extract-plugin: Vue + minicss = ReferenceError: window is not defined

Created on 10 Jun 2018  路  7Comments  路  Source: webpack-contrib/mini-css-extract-plugin

Can't get MiniCssExtractPlugin working with Vue single component files.
Archlinux node v10.3.0

module: {
    rules: [
      {
        exclude: /node_modules/,
        test: /\.vue$/,
        loader: 'vue-loader', 

      },
      {
        test: /\.sass$/,
        use: [
          MiniCssExtractPlugin.loader,
          "style-loader",
          "css-loader",
          "sass-loader?indentedSyntax"
        ]
      },
    ]
  }

Module build failed (from ./node_modules/mini-css-extract-plugin/dist/loader.js):
ReferenceError: window is not defined
at eval (webpack:///./node_modules/style-loader/lib/addStyles.js?:23:2)
at eval (webpack:///./node_modules/style-loader/lib/addStyles.js?:12:46)

steps to reproduce:

  • git clone https://github.com/Deathangel908/vue-webpack-minimal && cd vue-webpack-minimal
  • npm install
  • npm run build

Most helpful comment

Oh I shouldn't use style-loader...
{ test: /\.sass$/, use: [ MiniCssExtractPlugin.loader, "css-loader", "sass-loader?indentedSyntax" ] },

All 7 comments

Oh I shouldn't use style-loader...
{ test: /\.sass$/, use: [ MiniCssExtractPlugin.loader, "css-loader", "sass-loader?indentedSyntax" ] },

@Deathangel908 Why we shouldn't use style-loader? Thanks for an explanation.

@f3l1x - From the README of style-loader:

Adds CSS to the DOM by injecting a