简体   繁体   English

咕嘟咕嘟BabelJs编译的问题错误的顺序

[英]Gulp BabelJs compile issue wrong order

I am facing an issue related to compiling ES6 scripts by using gulp babel. 我面临与使用gulp babel编译ES6脚本有关的问题。 My project consists of maybe 40 - 50 different ES6 files (one class per file). 我的项目可能包含40-50个不同的ES6文件(每个文件一个class )。 At the moment, the compile process relies on a maintained ordered list of these .js files to guarantee a correct compilation and output order. 目前,编译过程依赖于这些.js文件的维护顺序列表,以确保正确的编译和输出顺序。

In the very past I tried to let the babel plugin compile these files in its own order. 在过去,我尝试让babel插件按照自己的顺序编译这些文件。 Unfortunately the result were runtime errors due to missing declared classes (affected by wrong compilation order). 不幸的是,由于缺少声明的类而导致运行时错误(受错误的编译顺序影响)。

My question is now: Is there any way to guarantee the correct compilation order automatically instead of manually maintaining this list? 我的问题现在是:有什么方法可以自动保证正确的编译顺序,而不是手动维护此列表?
If not, is there any ES6 compiler which does guarantee a correct compilation order automatically? 如果不是,是否有任何ES6编译器可以自动保证正确的编译顺序?

Thank you and best regards 感谢你并致以真诚的问候

I think the issue is, that babel doesn't resolve your dependencies. 我认为问题是,babel无法解决您的依赖关系。

For example: 例如:

// ComponentA.js
import AbstractComponent from './AbstractComponent';
class ComponentA extends AbstractComponent { ... }

// AbstractComponent.js
class AbstractComponent { ... }
export default AbstractComponent;

// gulpfile.js
gulp.task('js', function () {
return gulp.src(['./resources/javascript/ComponentA.js'])
    .pipe(concat('app.js'))
    .pipe(babel({ presets: ['@babel/env']}))
    .pipe(gulp.dest('./public/js'));
});

Issue here is, that babel can't find it's parent class, because it's not defined before ComponentA Class. 这里的问题是,babel找不到它的父类,因为它不是在ComponentA类之前定义的。 I've same issue and no solution for that. 我有同样的问题,没有解决方案。

Eg React you are able to import from classes and compile them to es5 and everything is fine... 例如,您可以从类中导入React并将其编译为es5,一切都很好...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM