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
Javascript 网页包未定义-吞咽-但已定义_Javascript_Webpack_Gulp_Referenceerror_Gulp Webpack - Fatal编程技术网

Javascript 网页包未定义-吞咽-但已定义

Javascript 网页包未定义-吞咽-但已定义,javascript,webpack,gulp,referenceerror,gulp-webpack,Javascript,Webpack,Gulp,Referenceerror,Gulp Webpack,我正在使用Gulp和webpack,我在我的gulpfile.js中导入了webpack和webpack流,但由于某些原因,控制台说webpack没有定义 我的吞咽导入是正确的: var webpack = require('webpack'); var webpackStream = require('webpack-stream'); 我的任务应该是编译 gulp.task('webpack', function() { return gulp.src(paths.srcClien

我正在使用Gulp和webpack,我在我的gulpfile.js中导入了
webpack
webpack流
,但由于某些原因,控制台说
webpack没有定义

我的吞咽导入是正确的:

var webpack = require('webpack');
var webpackStream = require('webpack-stream');
我的任务应该是编译

gulp.task('webpack', function() {
    return gulp.src(paths.srcClient)
        .pipe(webpackStream(require('./webpack.config.js'), webpack))
        .pipe(gulp.dest(paths.buildJs));
我的网页包配置(如果需要)

module.exports = {
    entry: './src/client.js',

    output: {
        path: __dirname + '/build/assets/js',
        filename: '[name].js'
    },

    module: {
        loaders: [
            {
                test: /\.js$/,
                loader: 'babel-loader',
                exclude: '/node_modules/',
                query: {
                    cacheDirectory: true,
                    presets: ['es2015']
                }
            }
        ]
    },

    plugins: [
        new webpack.optimize.UglifyJsPlugin({
            compress: {
                warnings: false
            }
        })
    ]
};
输出中的错误:

Starting 'webpack'...
[16:29:38] 'webpack' errored after 2.24 ms
[16:29:38] ReferenceError: webpack is not defined
    at Object.<anonymous> (/home/k3nzie/projects/jsGame/webpack.config.js:25:13)
    at Module._compile (module.js:571:32)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:488:32)
    at tryModuleLoad (module.js:447:12)
    at Function.Module._load (module.js:439:3)
    at Module.require (module.js:498:17)
    at require (internal/module.js:20:19)
    at Gulp.<anonymous> (/home/k3nzie/projects/jsGame/gulpfile.js:28:29)
    at module.exports (/home/k3nzie/projects/jsGame/node_modules/orchestrator/lib/runTask.js:34:7)
正在启动“网页包”。。。
[16:29:38]“网页包”在2.24毫秒后出错
[16:29:38]引用错误:未定义网页包
反对。(/home/k3nzie/projects/jsGame/webpack.config.js:25:13)
在模块处编译(模块js:571:32)
在Object.Module.\u extensions..js(Module.js:580:10)
在Module.load(Module.js:488:32)
在tryModuleLoad时(module.js:447:12)
在Function.Module.\u加载(Module.js:439:3)
at Module.require(Module.js:498:17)
根据需要(内部/module.js:20:19)
狼吞虎咽。(/home/k3nzie/projects/jsGame/gulpfile.js:28:29)
在module.exports(/home/k3nzie/projects/jsGame/node_modules/orchestrator/lib/runTask.js:34:7)

有什么建议吗?最近我对webpack有点疯狂…

你是如何安装webpack的?确保已运行“npm安装网页包”或“npm安装网页包-g”(用于全局系统安装)

it配置文件中未定义网页包

在webpack.config.js顶部,实现:

var UglifyJsPlugin = require('uglifyjs-webpack-plugin')
在webpack.config.js上的插件行中:

plugins: [
    new UglifyJsPlugin({
        compress: {
            warnings: false
        }
    })
]

您只需要添加
var webpack=require('webpack')
webpack.config.js
的顶部。我认为这解决了它,因为现在发现模块未找到时出错(我导入的类,我要将其标记为正确,这似乎是另一个问题(这很奇怪,因为我导入的目录正确,但找不到它)How class?Uglify plugin?如果是,请确保您已在cmd:npm install-D Uglify webpack plugin中运行。事实上,问题本身已经解决,因为其他原因,尽管我注意到我的依赖项中没有Uglify webpack plugin,所以我运行了
npm install-D Uglify webpack plugin
,但它显示
未找到:Uglify webpack-plugin@latest
edit:my bad,它实际上是
uglifyjs网页插件
不是
uglify网页插件
my bad对不起^^