webpack 未定义 - gulp - 但已定义
webpack is not defined - gulp - but IS defined
我正在使用 Gulp 和 webpack,我在我的 gulpfile.js 中导入了 webpack
和 webpack-stream
但由于某种原因控制台显示 webpack is not defined
我的 gulp 导入是正确的:
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));
如果需要我的 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
}
})
]
};
输出错误:
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)
有什么建议吗?我最近对 webpack 很着迷...
你是怎么安装webpack的?请确保您有 运行 "npm install webpack" 或 "npm install webpack -g"(用于全局系统安装)
webpack 没有在它的配置文件中定义。
在 webpack.config.js 之上,实施:
var UglifyJsPlugin = require('uglifyjs-webpack-plugin')
并且在 webpack.config.js 上的插件行中:
plugins: [
new UglifyJsPlugin({
compress: {
warnings: false
}
})
]
我正在使用 Gulp 和 webpack,我在我的 gulpfile.js 中导入了 webpack
和 webpack-stream
但由于某种原因控制台显示 webpack is not defined
我的 gulp 导入是正确的:
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));
如果需要我的 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
}
})
]
};
输出错误:
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)
有什么建议吗?我最近对 webpack 很着迷...
你是怎么安装webpack的?请确保您有 运行 "npm install webpack" 或 "npm install webpack -g"(用于全局系统安装)
webpack 没有在它的配置文件中定义。
在 webpack.config.js 之上,实施:
var UglifyJsPlugin = require('uglifyjs-webpack-plugin')
并且在 webpack.config.js 上的插件行中:
plugins: [
new UglifyJsPlugin({
compress: {
warnings: false
}
})
]