我尝试使用gulp
将我的 javascript 代码转换ecm6
为ecm5
,这没关系。gulp-babel
添加require
到转换后的代码中,现在我需要在浏览器中使用此代码,并且它是必要browserify
的代码。
当我在终端中运行此命令时,它向我显示以下错误:
我能做些什么来解决这个问题?我究竟做错了什么?
PD:谢谢你的帮助。
贾斯特
命令
gulp build
输出
Error: Cannot find module 'log' from '/home/ismael/projects/js-evolve/gulp-babel/dist'
at /home/ismael/projects/js-evolve/gulp-babel/node_modules/resolve/lib/async.js:46:17
at process (/home/ismael/projects/js-evolve/gulp-babel/node_modules/resolve/lib/async.js:173:43)
at ondir (/home/ismael/projects/js-evolve/gulp-babel/node_modules/resolve/lib/async.js:188:17)
at load (/home/ismael/projects/js-evolve/gulp-babel/node_modules/resolve/lib/async.js:69:43)
at onex (/home/ismael/projects/js-evolve/gulp-babel/node_modules/resolve/lib/async.js:92:31)
at /home/ismael/projects/js-evolve/gulp-babel/node_modules/resolve/lib/async.js:22:47
at FSReqWrap.oncomplete (fs.js:82:15)
gulpfile.js
var gulp = require('gulp'),
babel = require('gulp-babel'),
sourcemaps = require('gulp-sourcemaps'),
concat = require('gulp-concat'),
browserify = require('browserify'),
babelify = require('babelify'),
source = require('vinyl-source-stream'),
gulpBrowser = require('gulp-browserify');
gulp.task('default', function(){
return gulp.src('src/**/*.js')
.pipe(sourcemaps.init())
.pipe(babel({
presets: ['es2015']
}))
.pipe(concat('all.js'))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest('dist'));
});
gulp.task('build', function(){
return gulp.src('./dist/all.js')
.pipe(gulpBrowser({
debug:true,
transform: ['babelify']
}))
.pipe(gulp.dest('bundle/compile.js'))
});
all.js
'use strict';
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _log = require('log');
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var jet = function () {
/**
* Jet constructor
* @param {String} container - Html container identifier
* @constructor
**/
function jet(container) {
_classCallCheck(this, jet);
/**
* Jet container
* @type {HTMLElement}
* @private
**/
this._container = document.getElementById(container);
/**
* Logger de la clase
* @type {Logger}
* @private
**/
this._logger = new _log.Logger('Bullet');
}
_createClass(jet, [{
key: 'showInfo',
/**
* Shows info in the console
* @param {String} text - Info message
**/
value: function showInfo(text) {
this._logger.log(text);
}
}]);
return jet;
}();
;
'use strict';
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var logger = function () {
/**
* Logger constructor
* @param {String} channel - Logger channel
* @constructor
**/
function logger(channel) {
_classCallCheck(this, logger);
/**
* Logger channel
* @type {String}
* @private
**/
this._channel = channel;
/**
* Private channel
* @type {String}
* @private
**/
this._privateChannel = '[' + channel + ']';
}
/**
* Shows a message in the console
* @type {String}
* @private
**/
_createClass(logger, [{
key: 'log',
value: function log(text) {
console.log(this._privateChannel + ' ' + text);
}
}]);
return logger;
}();
//# sourceMappingURL=all.js.map