bugs——webpack2使用问题

学习webpack的时候,使用webpack2做项目打包。出现了很多问题。总结如下:

代码结构:

类似于以下的样子:

//webpack.config.js
const HtmlWebpackPlugin = require('html-webpack-plugin'),
      UglifyJSPlugin = require('uglifyjs-webpack-plugin'),
      ExtractTextPlugin = require("extract-text-webpack-plugin"),
      path = require("path");

module.exports = {
  "entry": ["./app/index.js"],
  "output": {
    "path": "output",
    "filename": "[name]-[chunkhash].js",
    "libraryTarget": "umd"
  },
  "module": {
    rules: [
      {
        "exclude": "/node_modules/",
        "include": "./app/",
        "loader": "babel",
        "options": {
          "presets": ["es2015", "react"]
        },
        "test": /\.jsx?$/
      },
      {
        "exclude": "/node_modules/",
        "use": ExtractTextPlugin.extract({
          "fallbackLoader": "style-loader",
          "loader": ["css-loader", "sass-loader"]
        }),
        "test": /\.scss$/
      }
    ]
  },
  plugins: [
    new HtmlWebpackPlugin(),
    new ExtractTextPlugin("[name]-[contenthash].css")
  ]
}
报错:

1、You may need an appropriate loader to handle this file type with

2、extensions[0] should not be empty.


解决:

1、所有的leader需要加上-loader

2、extensions:['*','.jsx','.js']


猜你喜欢

转载自blog.csdn.net/u013237862/article/details/72967093