0
我一直在我的React項目上成功使用webpack 1.x到目前爲止。現在我想遷移到的WebPack 2並運行了這個問題:webpack 2不能省略'-loader'錯誤
在我actions.js文件,我導入JavaScript函數從其他文件 - 見下:
當我運行的WebPack,我收到以下錯誤。貌似的WebPack是混淆了我import
陳述與進口裝載機 - 見下:
下面是我剛剛轉換成的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']
}
}
任何想法這是什麼原因以及如何解決?
謝謝。你是對的!看起來我也需要它用於'exports-loader'。 – Sam