繁体   English   中英

如何使Gulp在项目的根目录中读取Babel7的babel.config.js?

[英]How to make Gulp read babel.config.js of Babel7 in the root of the project?

这是我的项目结构:

Project
|-module1
|  |-package.json
|  |-gulpfile.babel.js
|-module2
|  |-package.json
|  |-gulpfile.babel.js  
|-package.json
|-scripts.js
|-babel.config.js 

如您在项目根目录中scripts.js ,我有scripts.js可以导出一些东西。 阅读Babel7配置中的所有信息后, 这里在我创建的项目的根babel.config.js具有以下内容:

module.exports = {
  presets: [
    ['@babel/env', {
      targets: {
        node: 'current',
        firefox: '60',
        chrome: '67',
        safari: '11.1',
      },
    }],
  ],
};

据我所知,我不需要创建.babelrcmodule1module2 ,因为我有一个babel.config.js根。 然而,当我上运行一饮而尽module1我看到一饮而尽没有找到通天塔的配置,因为我得到:

Project/module1/gulpfile.babel.js:26
import gulp from 'gulp';
       ^^^^
SyntaxError: Unexpected identifier

我的错误在哪里?

我发现的唯一解决方案如下-我们应该手动使用gulpfile.js而不是gulpfile.babel.js和config babel。 我的意思是:

Project/module1/gulpfile.js

require('@babel/register')({
    configFile: './../babel.config.js',
    ignore: [/node_modules/]
})
require('./tasks')

然后在Project/module1/tasks.js放入所有Project/module1/tasks.js任务。

暂无
暂无

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

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