gulpfile配置文件如下:
gulp.task('browserify-index', function () {
return browserify({entries: 'src/client/js/main.js', debug: true})
// // .external(dependencies)
.transform(babelify, {presets: ['es2015', 'react']})
.bundle()
// .pipe(source('bundle.js'))
// .pipe(buffer())
// .pipe(sourcemaps.init({loadMaps: true}))
// // .pipe(gulpif(production, uglify({mangle: false})))
// .pipe(sourcemaps.write('.'))
// // .pipe(rename('bundle.js'))
.pipe(gulp.dest('public/js'));
});
然后 main。js 如下
import React from 'react';
import ReactDOM from 'react-dom';
import App from './components/App.jsx';
ReactDOM.render(
<App name='蛤蛤蛤' />,
document.getElementById('react')
);
然后报错如下
$ gulp
[11:59:13] Using gulpfile ~Downloadschatroom-master (1)chatroom-mastergulpfile.js
[11:59:13] Starting 'browserify-index'...
events.js:141
throw er; // Unhandled 'error' event
^
SyntaxError: Unexpected token
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…