我试图让所有这些事情一起工作,它之前有用,所以有点困惑。
我已经安装了所有新的babel v6更改所需的依赖项。
开发/ index.js
import React from "react"
整个gulp任务
gulp.task("js", function () {
var bundler = through2.obj(function (file, enc, next) {
browserify(file.path, {
extensions: [".js", ".jsx"],
bundleExternal: false
})
.transform('babelify', {
presets: ["es2015", "react"]
})
.bundle(function (err, res) {
if (err) {
return next(err);
}
file.contents = res;
next(null, file);
});
});
return gulp
.src(path.join(config.dir.src, config.dir.client, config.dir.js, "index.js"))
.pipe(plugins.plumber({
errorHandler: onError
}))
.pipe(bundler)
.pipe(gulp.dest(path.join(config.dir.dist, config.dir.js)))
.pipe(browserSync.reload({ stream: true }));
});
输出index.js
(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
"use strict";
var _react = require("react");
var _react2 = _interopRequireDefault(_react);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
},{"react":undefined}]},{},[1]);
的package.json
"babel-core": "^6.7.5",
"babel-preset-es2015": "^6.3.13",
"babel-preset-react": "^6.3.13",