Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/webpack/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Webpack 为什么我的网页配置中总是出现模块加载错误?_Webpack_Html Webpack Plugin - Fatal编程技术网

Webpack 为什么我的网页配置中总是出现模块加载错误?

Webpack 为什么我的网页配置中总是出现模块加载错误?,webpack,html-webpack-plugin,Webpack,Html Webpack Plugin,我的webpack配置如下: var path = require('path'); var webpack = require('webpack'); var ROOT_PATH = path.resolve(__dirname); var APP_PATH = path.resolve(ROOT_PATH, 'WebApp'); var BUILD_PATH = path.resolve(ROOT_PATH, 'build'); var nodeModulePath=path.r

我的
webpack
配置如下:

 var path = require('path');
 var webpack = require('webpack');
 var ROOT_PATH = path.resolve(__dirname);
 var APP_PATH = path.resolve(ROOT_PATH, 'WebApp');
 var BUILD_PATH = path.resolve(ROOT_PATH, 'build');
 var nodeModulePath=path.resolve(ROOT_PATH,'node_modules');
 var HtmlwebpackPlugin = require('html-webpack-plugin');
 module.exports = {
   devtool:false,
    entry: {
       main: './WebApp/index.js',
       vendor:["jquery",'immutable','react','antd']

 },
output: {
    path: 'build',
    publicPath:'/build',
    filename: '[name].[hash].js',
    chunkFilename: "[id].chunk.js"

},
resolve:{
    //当requrie的模块找不到时,添加这些后缀
    extentions:["",".js",".jsx",".es6",'.css','.png','.jpg'],
    //让webpack不需要搜索可以直接处理的文件
    alias:{
        'react-dom':path.join(nodeModulePath,'/react-dom/dist/react-dom.min'),
        'react':path.join(nodeModulePath,'/react/dist/react.min'),
        'redux':path.join(nodeModulePath,'/redux/dist/redux.min'),
        'react-redux':path.join(nodeModulePath,'/react-redux/dist/react-redux.min'),
        'jquery':path.join(nodeModulePath,'/jquery/dist/jquery.min'),
        'immutable':path.join(nodeModulePath,'/immutable/dist/immutable.min')
    }
},
module: {
    //没有依赖的文件可以直接处理
    noParse:[path.join(nodeModulePath,'/react/dist/react.min'),path.join(nodeModulePath,'/immutable/dist/immutable.min'),path.join(nodeModulePath,'/redux/dist/redux.min')],
    loaders: [
        {
            test: /\.jsx?$/,
            loader: 'babel',
            //include: ROOT_PATH,
            exclude: /node_modules/,
            query: {
                //添加两个presents 使用这两种presets处理js或者jsx文件
                presets: ['es2015', 'react']
            }
        },
        {
            test: /\.css$/,
            loaders: ['style', 'css', 'sass'],
            include: ROOT_PATH
        },
        {
            test: /\.(png|jpg)$/,
            loader: 'url?limit=40000'
        }
    ]
},
plugins: [
    new webpack.DefinePlugin({ "process.env": { NODE_ENV: JSON.stringify("production") } }),
   // 插件有问题
   // new webpack.optimize.UglifyJsPlugin({minimize: true,compress:{warnings:false}}),
    new webpack.optimize.CommonsChunkPlugin('vendor','vendor.js'),
    new HtmlwebpackPlugin({
    template: path.resolve(APP_PATH, 'index.html'),
    filename: 'app.html',
    // //chunks这个参数告诉插件要引用entry里面的哪几个入口
    chunks: ['main','vendor'],
    // //要把script插入到标签里
    inject: 'body'
    // title: 'Hello World app'
})

]
};
这是我的node server.js:

var express = require('express')
var app = express()
var fs = require('fs')
var path = require('path')
console.log(__dirname);
app.use(express.static(__dirname));
app.get('/',  function (req, res, next) {

    var fileName =__dirname+ '/build/app.html';
    res.sendFile(fileName, function (err) {
        if (err) {
            console.log(err);
            res.status(err.status).end();
        }
        else {
            console.log('Sent:', fileName);
        }
    })
});

app.listen(3080, function () {
    console.log('Server listening on http://localhost:3080, Ctrl+C to stop')
})
但是当我运行这个程序时,我总是得到错误
无法得到/build/build0.chunk.js


我在开发环境中使用webpack一切正常,但在生产环境中我总是会遇到这个错误,我只会得到
0.chunk.js
1.chunk.js
等等,但为什么这个错误会显示:
无法获取/build/build0.chunk.js
,我的
htmlwebpackplugin
有什么问题吗?

您是否检查了
0.chunk.js
1.chunk.js
是否正在加载?您可以使用
console
选项卡旁边的
networks
选项卡进行验证。您是否检查了
0.chunk.js
1.chunk.js
是否正在加载?您可以使用
控制台
选项卡旁边的
网络
选项卡进行验证。