2017-05-31 69 views
0

我一直在我的React项目上成功使用webpack 1.x到目前为止。现在我想迁移到的WebPack 2并运行了这个问题:webpack 2不能省略'-loader'错误

在我actions.js文件,我导入JavaScript函数从其他文件 - 见下: enter image description here

当我运行的WebPack,我收到以下错误。貌似的WebPack是混淆了我import陈述与进口装载机 - 见下: enter image description here

下面是我刚刚转换成的WebPack 2格式的文件webpack.config.js:

var IS_DEV = false; 
var webpack = require('webpack'); 
var path = require("path"); 

var _pluginsDev = [ 
    new webpack.ProvidePlugin({ 
     'fetch': 'imports?this=>global!exports?global.fetch!whatwg-fetch', 
     moment: 'moment', 
     ps: 'perfect-scrollbar' 
    }), 

]; 
var _pluginsProd = [ 
    new webpack.ProvidePlugin({ 
     'fetch': 'imports?this=>global!exports?global.fetch!whatwg-fetch', 
     moment: 'moment', 
     ps: 'perfect-scrollbar' 
    }), 
    new webpack.DefinePlugin({ // Minimizer, removing multiple occurances of imports et.c 
     'process.env': { 
      'NODE_ENV': JSON.stringify('production') 
     } 
    }), 
    new webpack.optimize.UglifyJsPlugin({ 
     minimize: true, 
     compress: true, 
     output: { comments: false } 
    }) 
]; 

var _devtool = IS_DEV ? 'eval' : 'cheap-module-source-map'; 
var _plugins = IS_DEV ? _pluginsDev : _pluginsProd; 
var _fileName = IS_DEV ? "./build/[name]-bundle.js" : "./dist/[name]-bundle.js"; 

var _bundles = { 
    accounts: './UI/components/accounts/accounts.jsx' 
}; 

module.exports = { 
    entry: _bundles, 
    output: { 
     path: path.resolve(__dirname, "wwwroot"), 
     publicPath: "/", 
     filename: _fileName 
    }, 
    devtool: _devtool, 
    plugins: _plugins, 
    module: { 
     rules: [ 
      { 
       test: /\.jsx?$/, 
       exclude: /(node_modules|bower_components)/, 
       loader: "babel-loader", 
       options: { 
        presets: ['es2015', 'stage-0', 'stage-2', 'react'] 
       } 
      } 
     ] 
    }, 
    resolve: { 
     extensions: ['.js', '.jsx'] 
    } 
} 

任何想法这是什么原因以及如何解决?

回答

0

在新的webpack版本中,不能省略loader前缀。

new webpack.ProvidePlugin({ 
     'fetch': 'imports-loader?this=>global!exports?global.fetch!whatwg-fetch', 
     moment: 'moment', 
     ps: 'perfect-scrollbar' 
    }) 
+1

谢谢。你是对的!看起来我也需要它用于'exports-loader'。 – Sam

相关问题