[ad_1]
I just setup a gulp project to compile es6 code to es5.But the compiled code is not work in the browser.
gulpfile.js
var dir = __dirname;
const PATH =
sources:
js: path.join(dir, 'public/src/js/**/*.js')
,
build:
js: path.join(dir, 'public/dist/js')
,
sourcemaps: path.join(dir, 'public/maps')
;
gulp.task('default');
gulp.task('dev', ['dev:js']);
gulp.task('dev:js', function()
return gulp.src(PATH.sources.js)
.pipe(sourcemaps.init())
.pipe(babel())
.pipe(sourcemaps.write(PATH.sourcemaps))
.pipe(gulp.dest(PATH.build.js));
);
item.js
export class Test
play()
console.log('playing');
index.js
import Test from "./item";
const t = new Test();
t.play();
In html file, I require the compiled index.js file, but when I see the html file in browser, there is an error in console:
Uncaught ReferenceError: exports is not defined.
[ad_2]
لینک منبع