0

I am trying to add vue to my existing webpack app (based on this simple demo). I only want to load vue and SFC files in a specific entrypoint, but I am getting this error during build:

ERROR in chunk testview [entry]
style.css
Conflict: Multiple chunks emit assets to the same filename style.css (chunks app and testview)

The file I'm trying to load is ./js/components/main-content.vue

The contents of the entrypoint in question, ./js/views/TestView.js file is:

import Vue from "vue";
import MainContent from "../components/main-content";
let MainComponent = Vue.extend(MainContent);
new MainComponent().$mount("#mainContent");

It's worth noting that if I include the above in my app.js, it works fine. The error doesn't appear, and vue (and SFC) loads properly in the browser.

An abbreviated version of my webpack.config.js is:

const VueLoaderPlugin = require("vue-loader/lib/plugin");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");

module.exports = (env, argv) => {

  return {
    entry: {
      app: ["./src/polyfills.js", "./src/scss/styles.scss", "./src/app.js"],
      ...
      testview: "./src/js/views/TestView.js"
    },
    output: {
      path: assets,
      filename: "[name].[hash].js",
      publicPath: "/static/"
    },
    resolve: {
      modules: ["node_modules", "src"],
      alias: {
        vue$: "vue/dist/vue.esm.js"
      },
      extensions: ["*", ".js", ".vue"]
    },
    module: {
      rules: [
        {
          test: /\.js?$/,
          exclude: /node_modules/,
          use: [
            {
              loader: "babel-loader",
              ...
            }
          ]
        },
        {
          test: /\.s?[ac]ss$/,
          use: [
            {
              loader: "vue-style-loader"
            },
            {
              loader: MiniCssExtractPlugin.loader
            },
            {
              loader: "css-loader"
            }
            ...
          ]
        },
        {
          test: /\.vue$/,
          loader: "vue-loader"
        }
      ]
    },
    optimization: {
      splitChunks: {
        cacheGroups: {
          commons: {
            name: "commons",
            chunks: "initial",
            minChunks: 2,
            minSize: 0
          }
        }
      },
      occurrenceOrder: true 
    },
    plugins: [
      new HtmlWebpackPlugin({
        hash: true,
        inject: false,
        template: "./src/jinja-templates/base.html.j2",
        filename: `${templates}/base.html.j2`,
        environment: environment,
        development: ifNotProduction()
      }),
      new MiniCssExtractPlugin({
        filename: devMode ? "style.css" : "style.[hash].css"
      }),
      ...
      new VueLoaderPlugin()
    ]
  };
};
tarponjargon
  • 1,002
  • 10
  • 28
  • Did you manage to solve this? I'm having similiar issues right now! – Constantin Groß Jan 09 '19 at 17:02
  • Didn't figure out this issue specifically, but I made some config changes and got something working. See this issue: https://stackoverflow.com/questions/53736904/vue-sfc-styles-not-being-extracted-in-webpack-production-build – tarponjargon Jan 10 '19 at 18:23

0 Answers0