Webpack停止转发React

时间:2017-11-16 21:52:04

标签: reactjs webpack

我一直在使用WebPack v2.6.1来转换和捆绑我的反应jsx代码。我什么都没改变。突然之间,WebPack停止了我的React代码的转换和捆绑生产。

以下是我收到的错误消息的一部分: enter image description here

当我使用webpack dev服务器时,一切都运行得很好。当我尝试去生产时就会发生这种情况。 WebPack似乎正在生成捆绑的输出文件,但是当我尝试拉起页面时,它们不会出现。我发出了我一直使用的webpack --env.process命令。在浏览器中,这是我遇到的错误,这会阻止我的React组件显示。

enter image description here

我的webpack.config.js文件位于下方。知道这里发生了什么吗?

var IS_DEV = false; // change to false if building production files

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

// Define plugins needed for production and dev cases
var _pluginsDev = [
    new webpack.ProvidePlugin({
        'fetch': 'imports-loader?this=>global!exports-loader?global.fetch!whatwg-fetch',
        moment: 'moment',
        ps: 'perfect-scrollbar'
    }),

];
var _pluginsProd = [
    new webpack.ProvidePlugin({
        'fetch': 'imports-loader?this=>global!exports-loader?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 = {
    home: './UI/components/home/home.jsx',
    accounts: './UI/components/accounts/accounts.jsx',
    contacts: './UI/components/contacts/contacts.jsx',
    projectsList: './UI/components/projects/projects_list/projectsList.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)/,
                use: {
                    loader: "babel-loader",
                    options: {
                        presets: ['es2015', 'stage-2', 'stage-0', 'react']
                    }
                }
            }
        ]
    },
    resolve: {
        extensions: ['.js', '.jsx']
    }
}

0 个答案:

没有答案