suwu150
suwu150
采纳率44.3%
2017-02-14 15:43 阅读 2.8k
已采纳

配置webpack.config.js时出现错误,提示如下所示

1

图片说明

是怎么回事?我的代码如下所示:
var path=require('path');
var webpack=require('webpack');
var HtmlWebpackPlugin=require('html-webpack-plugin');
//一些常用路径
var ROOT_PATH=path.resolve(__dirname);
var APP_PATH=path.resolve(ROOT_PATH,'app');
var BUILD_PATH=path.resolve(ROOT_PATH,'build');
console.log("ROOT_PATH====="+ROOT_PATH);
console.log("APP_PATH====="+APP_PATH);
console.log("BUILD_PATH====="+BUILD_PATH);
module.exports={
entry:{
app:path.resolve(APP_PATH,'index.jsx')
},
output:{
path:BUILD_PATH,
filename:'bundle.js'
},
//开启 dev source map
devtool:'eval-source-map',
//开启 webpack dev server
devServer:{
historyApiFallback:true,
hot:true,
inline:true,
progress:true
},
module: {
//配置preLoaders,将eslint添加进入
// preLoaders: [
// {
// test:/.jsx?$/,
// loaders:['eslint'],
// include:APP_PATH
// }
// ],
//配置loaders,将babel添加进去
loaders:[
{
test:/.jsx?$/,
loaders:['babel'],
include:APP_PATH
}
]
},
//配置plugin
plugins:[
new HtmlWebpackPlugin({
title:'My first react app'
})
],
resolve:{
extensions:['','.js','.jsx']
}
}

如果去掉
,
resolve:{
extensions:['','.js','.jsx']
}
这段代码之后,结果变为下面:
图片说明

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

5条回答 默认 最新

  • 已采纳
    suwu150 suwu150 2017-02-15 07:39

    webpack@2.2.0-rc.3 has breaking changes. preLoaders is removed from the webpack^2.1.0-beta.23. so move it to rules and use enforce: "pre" instead.

    module.exports = {
    // entry, output, other top-level options ...
    module: {
    rules: [
    {
    test: /.js$/,
    exclude: /node_modules/,
    enforce: 'pre',
    use: [{loader: 'eslint-loader', options: {rules: {semi: 0}}}],
    },
    // other rules
    ],
    },
    // no need for plugins
    };

    点赞 评论 复制链接分享
  • devmiao devmiao 2017-02-14 15:56
  • suwu150 suwu150 2017-02-14 16:07

    执行webpack是就报错了---
    图片说明

    点赞 评论 复制链接分享
  • fight_in_dl 战在春秋 2017-02-14 21:46

    去掉

      resolve:{
    extensions:['','.js','.jsx']
    }
    

    试试

    点赞 评论 复制链接分享
  • suwu150 suwu150 2017-02-15 07:45

    解决了,我是用的是以前版本的webpack,在webpack.config.js中的配置与现在是有区别的,现在使用最新版本的已经去掉了preLoaders属性,使用rules进行代替操作

    点赞 评论 复制链接分享

相关推荐