Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
822 views
in Technique[技术] by (71.8m points)

gulp browserify 打包reactjs 报错一直报错

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

这么写:

.transform('babelify', {
    presets: [ 'es2015', 'react' ]
})

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...