我正在尝试将vue添加到现有的webpack应用(基于this simple demo)。我只想在特定的入口点中加载vue和SFC文件,但是在构建过程中出现此错误:
ERROR in chunk testview [entry]
style.css
Conflict: Multiple chunks emit assets to the same filename style.css (chunks app and testview)
我要加载的文件是./js/components/main-content.vue
有问题的入口点./js/views/TestView.js文件的内容是:
import Vue from "vue";
import MainContent from "../components/main-content";
let MainComponent = Vue.extend(MainContent);
new MainComponent().$mount("#mainContent");
值得注意的是,如果我在app.js中包含以上内容,则可以正常工作。该错误不会出现,并且vue(和SFC)会在浏览器中正确加载。
我的webpack.config.js的缩写是:
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()
]
};
};