var $ = require('gulp-load-plugins')()
var gulp = require('gulp')
var path = require('path')
var webpackStream = require('webpack-stream')
var webpack = webpackStream.webpack
var config = {
entry: {
'admin/product': './frontend/js/admin/product',
},
output: {
filename: '[name].js',
},
externals: {
jquery: 'jQuery',
},
module: {
loaders: [
{
test: /\.js$/,
include: path.join(__dirname, 'frontend/js'),
loader: 'babel?presets[]=es2015',
},
],
},
plugins: [
new webpack.NoEmitOnErrorsPlugin(),
new webpack.optimize.CommonsChunkPlugin({
name: 'admin/product',
chunks: ['admin/product'],
}),
],
}
module.exports = function (options) {
return function () {
return gulp
.src(options.src)
.pipe(
$.plumber({
errorHandler: $.notify.onError(function (err) {
return {
title: 'Webpack',
message: err.message,
}
}),
})
)
.pipe(webpackStream(config))
.pipe($.if(true, $.uglify()))
.pipe(gulp.dest(options.dest))
}
}
gulp webpack
var gulp = require('gulp');
function lazyRequireTask(taskName, path, options) {
options = options || {};
options.taskName = taskName;
gulp.task(taskName, function(callback) {
var task = require(path).call(this, options);
return task(callback);
});
}
lazyRequireTask('webpack', './frontend/gulp-task/webpack', {
src: ['./frontend/js/admin/*.js'],
dest: './web/js/'
});
require('./components/product');
webpackJsonp([1],{10:function(t,e){function v(){this.$grid=$(".products__grid"),this.init()}v.prototype.eventTabActive=function(){var t=app.getUrlParam("tab");if(!t)return!1;$("#tab-link-"+t).click()} ... и еще куча минифицированного кода.
.pipe(webpackStream(config))
, скрипт собирается в /web/js/ - не куда надо - и имеет тот же вид, что и исходники.