webpack.config.js中的无效配置对象

时间:2018-11-22 17:35:12

标签: reactjs webpack-2

我不断遇到这个错误

无效的配置对象。已使用与API架构不匹配的配置对象初始化了Webpack。

我的webpack.config.js就是这样

var path    = require('path');
var hwp     = require('html-webpack-plugin');

  module.exports = {
entry: path.join(__dirname, '/src/index.js'),
output: {
    filename: 'build.js',
    path: path.join(__dirname, '/dist')
},

module: {
    rules: [
        { test: /\.tsx?$/, loader: ['ts-loader'] },
        { test: /\.css$/, loader: "style-loader!css-loader" },
        {
            test: /\.scss$/, use: [{
                loader: "style-loader" // creates style nodes from JS 
strings
            }, {
                loader: "css-loader" // translates CSS into CommonJS
            }, {
                loader: "sass-loader" // compiles Sass to CSS
            }]
        },
        { test: /\.(otf|ttf|eot|svg|woff(2)?)(\?[a-z0-9=&.]+)?$/, 
 loader: 'file-loader?name=./Scripts/dist/[name].[ext]' }
    ]
},
plugins:[
    new hwp({template:path.join(__dirname, '/src/index.html')})
]
}

有人可以帮我吗,我尝试了很多webpack.config.js示例,但是它们不起作用。反应真的很难吗? 我是新来的。我知道如何编码,但是我无法建立自己的项目

1 个答案:

答案 0 :(得分:0)

尝试以下代码段:

var path = require("path");
var hwp = require("html-webpack-plugin");

module.exports = {
  entry: path.join(__dirname, "/src/index.js"),
  output: {
    filename: "build.js",
    path: path.join(__dirname, "/dist")
  },

  module: {
    rules: [
      { test: /\.tsx?$/, loader: ["ts-loader"] },
      { test: /\.css$/, loader: "style-loader!css-loader" },
      {
        test: /\.scss$/,
        use: [
          {
            loader: "style-loader" // creates style nodes from JS
          },
          {
            loader: "css-loader" // translates CSS into CommonJS
          },
          {
            loader: "sass-loader" // compiles Sass to CSS
          }
        ]
      },
      {
        test: /\.(otf|ttf|eot|svg|woff(2)?)(\?[a-z0-9=&.]+)?$/,
        loader: "file-loader?name=./Scripts/dist/[name].[ext]"
      }
    ]
  },
  plugins: [new hwp({ template: path.join(__dirname, "/src/index.html") })]
};