2017-05-31 3 views
0

私はこの時点までにReactプロジェクトでwebpack 1.xを使用しています。私は今のWebPACK 2に移行しようとし、この問題に実行している:私のactions.jsファイルでwebpack 2は '-loader'エラーを省略できません

、私は他のファイルからJavaScriptの関数をインポート - 以下参照: enter image description here

を私はWebPACKのを実行すると、次のエラーが表示されます。 WebPACKのローダーをインポートすると私のimport文混乱されたように見えます - 下記参照:

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'] 
    } 
} 

任意のアイデア: enter image description here

をここに私はちょうどWebPACKの2形式に変換しましたwebpack.config.jsファイルですこれを引き起こしているものとそれを修正する方法は何ですか?

答えて

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

関連する問題