Webpack-TypeError:this [NS]不是childCompiler.runAsChild的函数

时间:2018-07-07 07:51:02

标签: javascript webpack webpack.config.js

我目前正在以服务器端呈现方式使用Webpack。当尝试为我的包实现CSS支持时,我在bundle-time中收到此错误:

  

Webpack-TypeError:此[NS]不是位于的函数   childCompiler.runAsChild

这是我的webpack.config.js:

const webpack = require("webpack");
const autoprefixer = require("autoprefixer");
const path = require("path");
const nodeExternals = require('webpack-node-externals'); 
const MiniCssExtractPlugin = require("mini-css-extract-plugin");

// BrowserConfig  
const browserConfig =  {
  mode: 'development',
  devtool: "cheap-module-source-map",
  entry: "./src/client/index.js",
  output: {
    path: path.resolve(__dirname, "public"),
    filename: "bundle.js"
  },

  module: {
    rules: [
      {
        test: [/\.svg$/, /\.gif$/, /\.jpe?g$/, /\.png$/],
        loader: "file-loader",
        exclude: /(node_modules)/,
        options: {
          name: "public/media/[name].[ext]",
          publicPath: url => url.replace(/public/, "")
        }
      },{
      test:/\.css$/,
      exclude: /(node_modules)/,
      include: /(src)/,
      use:  [ "style-loader",MiniCssExtractPlugin.loader, 'css-loader', 'postcss-loader']
      },
      {
        test: [/\.js$/, /\.jsx$/], 
        exclude: /(node_modules)/,
        loader: "babel-loader"
      }
    ]
  },
  plugins:[
    new MiniCssExtractPlugin({
      filename: "public/css/[name].css"
    }),
    new webpack.DefinePlugin({
      __isBrowser__: "true"
    })
  ]
};


// ServerConfig 

const serverConfig = {
  mode: 'development',
  devtool: "cheap-module-source-map",
  entry: "./src/server/index.js",
  externals: [nodeExternals()],
  target: "node",
  output: {
    path: __dirname,
    filename: "server.js",
    libraryTarget: "commonjs2"
  }, 
  module: {
    rules: [
      {
        test: [/\.svg$/, /\.gif$/, /\.jpe?g$/, /\.png$/],
        loader: "file-loader",
        exclude: /(node_modules)/,
        options: {
          name: "public/media/[name].[ext]",
          publicPath: url => url.replace(/public/, "")
        }
      },{
      test:/\.css$/,
      exclude: /(node_modules)/,
      include: /(src)/,
      use:  [ "style-loader",MiniCssExtractPlugin.loader, 'css-loader/locals', 'postcss-loader']
      },
      {
        test: [/\.js$/, /\.jsx$/], 
        exclude: /(node_modules)/,
        loader: "babel-loader"
      }
    ]
  },
  plugins: [
    new MiniCssExtractPlugin({
      filename: "public/css/[name].css"
    }),
    new webpack.DefinePlugin({
      __isBrowser__: "false"
    })
  ]
};

module.exports = [browserConfig, serverConfig];

我不知道出什么问题了,因为在我看来我已经在程序中包含了所有必要的指令。

如果有人有任何提示,那就太好了。

谢谢

0 个答案:

没有答案