Я пытаюсь адаптировать файл gulp для моих целей, и у меня возникают проблемы. Я забочусь только об одной задаче:gulp-load-plugins.sourcemaps.init() TypeError: Не удается прочитать свойство «init» неопределенного
gulp.task('js:browser', function() {
return mergeStream.apply(null,
Object.keys(jsBundles).map(function(key) {
return bundle(jsBundles[key], key);
})
);
});
С помощью браузера вы можете скомпоновать мой пакет в одноразовый файл. Он использует эти два метода и этот объект:
function createBundle(src) {
//if the source is not an array, make it one
if (!src.push) {
src = [src];
}
var customOpts = {
entries: src,
debug: true
};
var opts = assign({}, watchify.args, customOpts);
var b = watchify(browserify(opts));
b.transform(babelify.configure({
stage: 1
}));
b.transform(hbsfy);
b.on('log', plugins.util.log);
return b;
}
function bundle(b, outputPath) {
var splitPath = outputPath.split('/');
var outputFile = splitPath[splitPath.length - 1];
var outputDir = splitPath.slice(0, -1).join('/');
console.log(outputFile);
console.log(plugins);
return b.bundle()
// log errors if they happen
.on('error', plugins.util.log.bind(plugins.util, 'Browserify Error'))
.pipe(source(outputFile))
// optional, remove if you don't need to buffer file contents
.pipe(buffer())
// optional, remove if you dont want sourcemaps
.pipe(plugins.sourcemaps.init({loadMaps: true})) // loads map from browserify file
// Add transformation tasks to the pipeline here.
.pipe(plugins.sourcemaps.write('./')) // writes .map file
.pipe(gulp.dest('build/public/' + outputDir));
}
var jsBundles = {
'js/polyfills/promise.js': createBundle('./public/js/polyfills/promise.js'),
'js/polyfills/url.js': createBundle('./public/js/polyfills/url.js'),
'js/settings.js': createBundle('./public/js/settings/index.js'),
'js/main.js': createBundle('./public/js/main/index.js'),
'js/remote-executor.js': createBundle('./public/js/remote-executor/index.js'),
'js/idb-test.js': createBundle('./public/js/idb-test/index.js'),
'sw.js': createBundle(['./public/js/sw/index.js', './public/js/sw/preroll/index.js'])
};
Когда я запустить JS задачу глотка: Беседки Я получаю следующее сообщение об ошибке приходит из в .pipe(plugins.sourcemaps.init({loadMaps: true}))
выражения:
TypeError: Cannot read property 'init' of undefined
Я знаю, что линии необязательно, и я могу просто прокомментировать их, но я их хочу. Когда я запускаю код в файле примера, он работает правильно, когда я запускаю его в своем файле gulp, он дает мне ошибку. Какие-либо предложения о том, что я могу пропустить? Благодаря!