1

当运行 webpack-dev-server 产生错误 Module build failed: TypeError: text.forEach is not a function enter image description here

'use strict';

var webpack = require('webpack');
var ExtractTextPlugin = require('extract-text-webpack-plugin');

var path = require('path');

module.exports = {
entry: {
    app: ['./client/main.js'],

    index: ['./server/index.pug']
},

output: {
    path: path.resolve(__dirname, "..", "public",'js'),
    publicPath: "/js/",
    filename: '[name].js'
},

module: {
    rules: [
       {
           test: /\.pug$/,
           loader: ExtractTextPlugin.extract( 'pug-loader')
       },
       {
           test: /\.js$/,
           loader: "babel-loader",
           exclude: /node_modules/,
           query: {
                presets: ['es2015']
            }
       },
       {
            test: /\.scss$/,
            loader: ExtractTextPlugin.extract({
                fallback: "style-loader",
                use: [{
                    loader: "css-loader"
                }, {
                    loader: "postcss-loader"
                }, {
                    loader: "sass-loader"
                }]
            })
        }, 
        {
            test: /\.vue$/,
            loader: "vue-loader"
        }
    ]
},

resolve: {
    extensions: [".vue", ".js", ".json",".pug",".html"],
    alias: {
        'vue$': 'vue/dist/vue.common.js'
    }
},

plugins: [
    new ExtractTextPlugin("[name].html"),
    new ExtractTextPlugin("[name].css"),
    new webpack.NoEmitOnErrorsPlugin(),
    new webpack.optimize.CommonsChunkPlugin({
        name: "main",
        minChunks: 2
    })
],
}

在此之前,我尝试通过 HtmlWebpackPlugin 来实现,但它返回纯文本!

4

0 回答 0