简体   繁体   English

webpack未定义-gulp-但已定义

[英]webpack is not defined - gulp - but IS defined

I'm using Gulp and webpack, I imported both webpack and webpack-stream in my gulpfile.js but for some reason the console says webpack is not defined 我正在使用Gulp和webpack,我在webpack同时导入了webpackwebpack-stream ,但是由于某些原因,控制台显示webpack is not defined

my gulp import are correct : 我的gulp导入是正确的:

var webpack = require('webpack');
var webpackStream = require('webpack-stream');

My task which should compile 我的任务应该编译

gulp.task('webpack', function() {
    return gulp.src(paths.srcClient)
        .pipe(webpackStream(require('./webpack.config.js'), webpack))
        .pipe(gulp.dest(paths.buildJs));

My webpack config if needed 我的webpack配置(如果需要)

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
            }
        })
    ]
};

The error from the output : 输出错误:

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)

Any suggestions? 有什么建议么? I'm gettin insane lately with webpack... 我最近用webpack疯了...

How did you install webpack? 您是如何安装webpack的? Make sure you have run "npm install webpack", or "npm install webpack -g" (for global system installation) 确保您已运行“ npm install webpack”或“ npm install webpack -g”(用于全局系统安装)

webpack is not defined in it config file. webpack未在其配置文件中定义。

In top of webpack.config.js, implement : 在webpack.config.js顶部,实现:

var UglifyJsPlugin = require('uglifyjs-webpack-plugin')

And in plugins line on webpack.config.js : 在webpack.config.js的插件行中:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM